Skip to content
Browse files

Some minimal documentation. Fixed test broken in a previous commit.

  • Loading branch information...
1 parent 781cb48 commit 99f0115c138f5aa699cc74dbdf7620f0c7ee7870 @quarnster committed Mar 21, 2013
Showing with 25 additions and 3 deletions.
  1. +10 −1 content/intent.go
  2. +1 −0 content/json.go
  3. +11 −0 content/standard_intents.go
  4. +1 −1 java/completion_intent.go
  5. +2 −1 server_test.go
View
11 content/intent.go
@@ -13,7 +13,7 @@ type (
CanHandle(it *Intent) bool
Handle(it *Intent) *Response
}
- // TODO(@dskinner): Replace with IntentHandler?
+ // TODO(@dskinner): Replace Handler with IntentHandler or something else?
Handler func(io.Writer, Intent)
Intent struct {
@@ -43,13 +43,22 @@ func NewResponse() (ret Response) {
return
}
+// Returns the Session object associated with this Intent or nil.
func (it *Intent) Session() *Session {
+ // TODO(someone): Intent.Session not implemented yet
if sessionid, ok := it.Data.Get("sessionid").(int); ok {
_ = sessionid // TODO actually look up session and return it
}
return nil
}
+// If a Session is associated with this Intent, then the Session's
+// Settings is cloned and the intent's Settings are merged into the
+// cloned Settings object. This to allow Intents to be "slim", i.e.
+// only contain the keys of the specific settings it wants to override.
+//
+// If there's no Session nor Intent Settings, the empty Settings object
+// is returned.
func (it *Intent) Settings() *Settings {
if session := it.Session(); session != nil {
set := session.Settings.Clone()
View
1 content/json.go
@@ -27,6 +27,7 @@ func init() {
}
}
+// Register a type to make it possible to correctly deserialize it.
func RegisterType(key string, t reflect.Type) error {
if registered_types == nil {
registered_types = make(map[string]reflect.Type)
View
11 content/standard_intents.go
@@ -0,0 +1,11 @@
+package content
+
+var (
+ // The CompleteFullyQualifiedName operation expects a "fqn" key in the intent's data field
+ // pointing to the FullyQualifiedName of the type we want to complete
+ CompleteFullyQualifiedName = "completion.complete.fqn"
+
+ // The CompleteSourceLocation operation expects a "loc" key in the intent's data field
+ // pointing to the SourceLocation we want to complete
+ CompleteSourceLocation = "complete.loc"
+)
View
2 java/completion_intent.go
@@ -57,7 +57,7 @@ func (c *CompletionHandler) Handle(it *content.Intent) *content.Response {
func (c *CompletionHandler) CanHandle(it *content.Intent) bool {
// TODO
- if it.Operation != "completion.complete.fqn" {
+ if it.Operation != content.CompleteFullyQualifiedName {
return false
}
fqn, ok := it.Data.Get("fqn").(content.FullyQualifiedName)
View
3 server_test.go
@@ -33,7 +33,8 @@ func send(s string) (string, error) {
func handler(w io.Writer, intent content.Intent) {
log.Println(intent)
- if b, err := json.Marshal(&content.Response{1, nil}); err != nil {
+ r := content.NewResponse()
+ if b, err := json.Marshal(r); err != nil {
log.Println(err)
fmt.Fprintf(w, "Failed to create response: %v", err)
} else {

0 comments on commit 99f0115

Please sign in to comment.
Something went wrong with that request. Please try again.