summaryrefslogtreecommitdiff
path: root/gocomplete/parse.go
diff options
context:
space:
mode:
Diffstat (limited to 'gocomplete/parse.go')
-rw-r--r--gocomplete/parse.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/gocomplete/parse.go b/gocomplete/parse.go
new file mode 100644
index 0000000..8111b74
--- /dev/null
+++ b/gocomplete/parse.go
@@ -0,0 +1,28 @@
+package main
+
+import (
+ "go/ast"
+ "go/parser"
+ "go/token"
+ "regexp"
+
+ "github.com/posener/complete"
+)
+
+func functionsInFile(path string, regexp *regexp.Regexp) (tests []string) {
+ fset := token.NewFileSet()
+ f, err := parser.ParseFile(fset, path, nil, 0)
+ if err != nil {
+ complete.Log("Failed parsing %s: %s", path, err)
+ return nil
+ }
+ for _, d := range f.Decls {
+ if f, ok := d.(*ast.FuncDecl); ok {
+ name := f.Name.String()
+ if regexp == nil || regexp.MatchString(name) {
+ tests = append(tests, name)
+ }
+ }
+ }
+ return
+}