Skip to content
This repository has been archived by the owner on Feb 3, 2024. It is now read-only.

Commit

Permalink
Some minimal documentation. Fixed test broken in a previous commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
quarnster committed Mar 21, 2013
1 parent 781cb48 commit 99f0115
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
11 changes: 10 additions & 1 deletion content/intent.go
Expand Up @@ -13,7 +13,7 @@ type (
CanHandle(it *Intent) bool CanHandle(it *Intent) bool
Handle(it *Intent) *Response Handle(it *Intent) *Response
} }
// TODO(@dskinner): Replace with IntentHandler? // TODO(@dskinner): Replace Handler with IntentHandler or something else?
Handler func(io.Writer, Intent) Handler func(io.Writer, Intent)


Intent struct { Intent struct {
Expand Down Expand Up @@ -43,13 +43,22 @@ func NewResponse() (ret Response) {
return return
} }


// Returns the Session object associated with this Intent or nil.
func (it *Intent) Session() *Session { func (it *Intent) Session() *Session {
// TODO(someone): Intent.Session not implemented yet
if sessionid, ok := it.Data.Get("sessionid").(int); ok { if sessionid, ok := it.Data.Get("sessionid").(int); ok {
_ = sessionid // TODO actually look up session and return it _ = sessionid // TODO actually look up session and return it
} }
return nil 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 { func (it *Intent) Settings() *Settings {
if session := it.Session(); session != nil { if session := it.Session(); session != nil {
set := session.Settings.Clone() set := session.Settings.Clone()
Expand Down
1 change: 1 addition & 0 deletions content/json.go
Expand Up @@ -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 { func RegisterType(key string, t reflect.Type) error {
if registered_types == nil { if registered_types == nil {
registered_types = make(map[string]reflect.Type) registered_types = make(map[string]reflect.Type)
Expand Down
11 changes: 11 additions & 0 deletions 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"
)
2 changes: 1 addition & 1 deletion java/completion_intent.go
Expand Up @@ -57,7 +57,7 @@ func (c *CompletionHandler) Handle(it *content.Intent) *content.Response {


func (c *CompletionHandler) CanHandle(it *content.Intent) bool { func (c *CompletionHandler) CanHandle(it *content.Intent) bool {
// TODO // TODO
if it.Operation != "completion.complete.fqn" { if it.Operation != content.CompleteFullyQualifiedName {
return false return false
} }
fqn, ok := it.Data.Get("fqn").(content.FullyQualifiedName) fqn, ok := it.Data.Get("fqn").(content.FullyQualifiedName)
Expand Down
3 changes: 2 additions & 1 deletion server_test.go
Expand Up @@ -33,7 +33,8 @@ func send(s string) (string, error) {


func handler(w io.Writer, intent content.Intent) { func handler(w io.Writer, intent content.Intent) {
log.Println(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) log.Println(err)
fmt.Fprintf(w, "Failed to create response: %v", err) fmt.Fprintf(w, "Failed to create response: %v", err)
} else { } else {
Expand Down

0 comments on commit 99f0115

Please sign in to comment.