Skip to content
Browse files

Misc comment updates and renames.

  • Loading branch information...
1 parent 8054256 commit e30aeaa9a9b2b5e27873fb00fb84733bbe81c19f @nsf committed Sep 12, 2010
Showing with 66 additions and 24 deletions.
  1. +2 −0 autocompletecontext.go
  2. +4 −0 autocompletefile.go
  3. +7 −0 decl.go
  4. +26 −7 declcache.go
  5. +1 −1 gocode.go
  6. +26 −16 server.go
View
2 autocompletecontext.go
@@ -16,6 +16,7 @@ import (
//-------------------------------------------------------------------------
// OutBuffers
+//
// Temporary structure for writing autocomplete response.
//-------------------------------------------------------------------------
@@ -121,6 +122,7 @@ func matchClass(declclass int, class int) bool {
//-------------------------------------------------------------------------
// AutoCompleteContext
+//
// Context that holds cache structures for autocompletion needs. It
// includes cache for packages and for main package files.
//-------------------------------------------------------------------------
View
4 autocompletefile.go
@@ -6,6 +6,10 @@ import (
"go/token"
)
+//-------------------------------------------------------------------------
+// AutoCompleteFile
+//-------------------------------------------------------------------------
+
type AutoCompleteFile struct {
name string
packageName string
View
7 decl.go
@@ -42,6 +42,13 @@ var declClassToString = [...]string{
DECL_METHODS_STUB: "IF YOU SEE THIS, REPORT A BUG", // :D
}
+//-------------------------------------------------------------------------
+// Decl
+//
+// The most important data structure of the whole gocode project. It
+// describes a single declaration and its children.
+//-------------------------------------------------------------------------
+
type Decl struct {
Name string
Type ast.Expr
View
33 declcache.go
@@ -14,6 +14,7 @@ import (
//-------------------------------------------------------------------------
// PackageImport
+//
// Contains import information from a single file
//-------------------------------------------------------------------------
@@ -30,23 +31,26 @@ func NewPackageImports(filename string, decls []ast.Decl) PackageImports {
return mi
}
-func (mi *PackageImports) appendImports(filename string, decls []ast.Decl) {
+// Parses import declarations until the first non-import declaration and fills
+// 'pi' array with import information.
+func (pi *PackageImports) appendImports(filename string, decls []ast.Decl) {
for _, decl := range decls {
if gd, ok := decl.(*ast.GenDecl); ok && gd.Tok == token.IMPORT {
for _, spec := range gd.Specs {
imp := spec.(*ast.ImportSpec)
path, alias := pathAndAlias(imp)
path = absPathForPackage(filename, path)
- mi.appendImport(alias, path)
+ pi.appendImport(alias, path)
}
} else {
return
}
}
}
-func (mi *PackageImports) appendImport(alias, path string) {
- v := *mi
+// Simple vector-like append.
+func (pi *PackageImports) appendImport(alias, path string) {
+ v := *pi
if alias == "_" || alias == "." {
// TODO: support for packages imported in the current namespace
return
@@ -61,13 +65,15 @@ func (mi *PackageImports) appendImport(alias, path string) {
v = v[0 : n+1]
v[n] = PackageImport{alias, path}
- *mi = v
+ *pi = v
}
//-------------------------------------------------------------------------
// DeclFileCache
-// Contains cache for top-level declarations of a file. Used in both
-// autocompletion and refactoring utilities.
+//
+// Contains cache for top-level declarations of a file as well as its
+// contents, AST and import information. Used in both autocompletion
+// and refactoring utilities.
//-------------------------------------------------------------------------
type DeclFileCache struct {
@@ -112,6 +118,10 @@ func (f *DeclFileCache) readFile(filename string) {
return
}
+ f.processData()
+}
+
+func (f *DeclFileCache) processData() {
f.File, f.Error = parser.ParseFile("", f.Data, 0)
f.FileScope = NewScope(nil)
anonymifyAst(f.File.Decls, 0, f.FileScope)
@@ -122,6 +132,13 @@ func (f *DeclFileCache) readFile(filename string) {
}
}
+func (f *DeclFileCache) reprocess() {
+ // drop mtime, because we're invalidating cache
+ f.mtime = 0
+
+ f.processData()
+}
+
func appendToTopDecls(decls map[string]*Decl, decl ast.Decl, scope *Scope) {
foreachDecl(decl, func(data *foreachDeclStruct) {
class := astDeclClass(data.decl)
@@ -204,6 +221,8 @@ func packageName(file *ast.File) string {
//-------------------------------------------------------------------------
// DeclCache
+//
+// Thread-safe collection of DeclFileCache entities.
//-------------------------------------------------------------------------
type DeclCache struct {
View
2 gocode.go
@@ -188,7 +188,7 @@ func serverFunc() int {
fmt.Printf("unix socket: '%s' already exists\n", socketfname)
return 1
}
- daemon = NewAutoCompletionDaemon(socketfname)
+ daemon = NewDaemon(socketfname)
defer os.Remove(socketfname)
rpcremote := new(RPCRemote)
View
42 server.go
@@ -10,35 +10,39 @@ import (
)
//-------------------------------------------------------------------------
+// Daemon
+//-------------------------------------------------------------------------
-type AutoCompletionDaemon struct {
- acr *ACRServer
+type Daemon struct {
+ acr *Server
acc *AutoCompleteContext
semantic *SemanticContext
pcache PackageCache
declcache *DeclCache
}
-func NewAutoCompletionDaemon(path string) *AutoCompletionDaemon {
- d := new(AutoCompletionDaemon)
- d.acr = NewACRServer(path)
+func NewDaemon(path string) *Daemon {
+ d := new(Daemon)
+ d.acr = NewServer(path)
d.pcache = NewPackageCache()
d.declcache = NewDeclCache()
d.acc = NewAutoCompleteContext(d.pcache, d.declcache)
d.semantic = NewSemanticContext(d.pcache, d.declcache)
return d
}
-func (d *AutoCompletionDaemon) DropCache() {
+func (d *Daemon) DropCache() {
d.pcache = NewPackageCache()
d.declcache = NewDeclCache()
d.acc = NewAutoCompleteContext(d.pcache, d.declcache)
d.semantic = NewSemanticContext(d.pcache, d.declcache)
}
-var daemon *AutoCompletionDaemon
+var daemon *Daemon
//-------------------------------------------------------------------------
+// printBacktrace
+//-------------------------------------------------------------------------
var btSync sync.Mutex
@@ -59,6 +63,12 @@ func printBacktrace(err interface{}) {
fmt.Println("")
}
+//-------------------------------------------------------------------------
+// Server_* functions
+//
+// Corresponding Client_* functions are autogenerated by goremote.
+//-------------------------------------------------------------------------
+
func Server_AutoComplete(file []byte, filename string, cursor int) (a, b, c []string, d int) {
defer func() {
if err := recover(); err != nil {
@@ -124,20 +134,20 @@ func Server_Set(key, value string) string {
}
//-------------------------------------------------------------------------
-// Autocompletion Refactoring Server
+// Server
//-------------------------------------------------------------------------
const (
- ACR_CLOSE = iota
+ SERVER_CLOSE = iota
)
-type ACRServer struct {
+type Server struct {
listener *net.UnixListener
cmd_in chan int
}
-func NewACRServer(path string) *ACRServer {
- s := new(ACRServer)
+func NewServer(path string) *Server {
+ s := new(Server)
addr, err := net.ResolveUnixAddr("unix", path)
if err != nil {
panic(err.String())
@@ -161,7 +171,7 @@ func acceptConnections(in chan net.Conn, listener *net.UnixListener) {
}
}
-func (s *ACRServer) Loop() {
+func (s *Server) Loop() {
conn_in := make(chan net.Conn)
go acceptConnections(conn_in, s.listener)
for {
@@ -172,7 +182,7 @@ func (s *ACRServer) Loop() {
runtime.GC()
case cmd := <-s.cmd_in:
switch cmd {
- case ACR_CLOSE:
+ case SERVER_CLOSE:
return
}
case sig := <-signal.Incoming:
@@ -187,6 +197,6 @@ func (s *ACRServer) Loop() {
}
}
-func (s *ACRServer) Close() {
- s.cmd_in <- ACR_CLOSE
+func (s *Server) Close() {
+ s.cmd_in <- SERVER_CLOSE
}

0 comments on commit e30aeaa

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