Permalink
Browse files

Add new "status" command. Server now handles one request at a time.

Because I don't want to complicate things with thread safety for now,
server handles only one connection at a time.
  • Loading branch information...
1 parent 96cb3a2 commit a5fa9883f9e1711a23bda412f6fda16c4558e389 @nsf committed Jul 10, 2010
Showing with 34 additions and 7 deletions.
  1. +6 −0 gocode.go
  2. +21 −4 gocodelib.go
  3. +7 −3 gocodeserver.go
View
@@ -32,6 +32,10 @@ func serverFunc() {
daemon.acr.Loop()
}
+func Cmd_Status(c *rpc.Client) {
+ fmt.Printf("%s\n", Client_Status(c, 0))
+}
+
func Cmd_AutoComplete(c *rpc.Client) {
file, err := ioutil.ReadAll(os.Stdin)
if err != nil {
@@ -83,6 +87,8 @@ func clientFunc() int {
Cmd_AutoComplete(client)
case "close":
Cmd_Close(client)
+ case "status":
+ Cmd_Status(client)
}
}
return 0
View
@@ -310,7 +310,7 @@ func (self *AutoCompleteContext) processPackage(filename string, uniquename stri
if pkgname == "" {
pkgname = s[len("package "):i-1]
}
- self.AddAlias(pkgname, uniquename)
+ self.addAlias(pkgname, uniquename)
if self.debuglog != nil {
fmt.Fprintf(self.debuglog, "parsing package '%s'...\n", pkgname)
}
@@ -359,7 +359,7 @@ func (self *AutoCompleteContext) processPackage(filename string, uniquename stri
f := new(ast.File) // fake file
f.Decls = decls
ast.FileExports(f)
- self.Add(key, f.Decls)
+ self.add(key, f.Decls)
}
}
}
@@ -614,7 +614,7 @@ func NewAutoCompleteContext() *AutoCompleteContext {
return self
}
-func (self *AutoCompleteContext) Add(globalname string, decls []ast.Decl) {
+func (self *AutoCompleteContext) add(globalname string, decls []ast.Decl) {
if self.m[globalname] == nil {
self.m[globalname] = make(map[string]ast.Decl)
}
@@ -630,7 +630,7 @@ func (self *AutoCompleteContext) Add(globalname string, decls []ast.Decl) {
}
}
-func (self *AutoCompleteContext) AddAlias(alias string, globalname string) {
+func (self *AutoCompleteContext) addAlias(alias string, globalname string) {
self.cfns[alias] = globalname
}
@@ -688,3 +688,20 @@ func (self *AutoCompleteContext) Apropos(file []byte, apropos string) ([]string,
sort.Sort(pair)
return pair.first, pair.second
}
+
+func (self *AutoCompleteContext) Status() string {
+ buf := bytes.NewBuffer(make([]byte, 0, 4096))
+ fmt.Fprintf(buf, "Number of top level packages: %d\n", len(self.m))
+ if len(self.m) > 0 {
+ fmt.Fprintf(buf, "Listing packages: ")
+ i := 0
+ for key, _ := range self.m {
+ fmt.Fprintf(buf, "'%s'", key)
+ if i != len(self.m)-1 {
+ fmt.Fprintf(buf, ", ")
+ }
+ i++
+ }
+ }
+ return buf.String()
+}
View
@@ -33,6 +33,10 @@ func Server_Close(notused int) int {
return 0
}
+func Server_Status(notused int) string {
+ return daemon.ctx.Status()
+}
+
//-------------------------------------------------------------------------
// Autocompletion Refactoring Server
//-------------------------------------------------------------------------
@@ -78,9 +82,9 @@ func (self *ACRServer) Loop() {
// handle connections or server CMDs (currently one CMD)
select {
case c := <-conn_in:
- go func(c net.Conn) {
- rpc.ServeConn(c)
- }(c)
+ //go func(c net.Conn) {
+ rpc.ServeConn(c)
+ //}(c)
case cmd := <-self.cmd_in:
switch cmd {
case ACR_CLOSE:

0 comments on commit a5fa988

Please sign in to comment.