From 99f0115c138f5aa699cc74dbdf7620f0c7ee7870 Mon Sep 17 00:00:00 2001 From: Fredrik Ehnbom Date: Thu, 21 Mar 2013 15:00:38 +0100 Subject: [PATCH] Some minimal documentation. Fixed test broken in a previous commit. --- content/intent.go | 11 ++++++++++- content/json.go | 1 + content/standard_intents.go | 11 +++++++++++ java/completion_intent.go | 2 +- server_test.go | 3 ++- 5 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 content/standard_intents.go diff --git a/content/intent.go b/content/intent.go index 401b452..0050d26 100644 --- a/content/intent.go +++ b/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() diff --git a/content/json.go b/content/json.go index 9cb369e..7252f58 100644 --- a/content/json.go +++ b/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) diff --git a/content/standard_intents.go b/content/standard_intents.go new file mode 100644 index 0000000..8f21e2d --- /dev/null +++ b/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" +) diff --git a/java/completion_intent.go b/java/completion_intent.go index 5076ef8..374e31f 100644 --- a/java/completion_intent.go +++ b/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) diff --git a/server_test.go b/server_test.go index 74b6c77..c580795 100644 --- a/server_test.go +++ b/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 {