complete/gocomplete/parse.go

28 lines
510 B
Go
Raw Normal View History

package main
import (
"go/ast"
"go/parser"
"go/token"
2019-11-13 22:51:44 -06:00
"log"
"regexp"
)
func functionsInFile(path string, regexp *regexp.Regexp) (tests []string) {
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, path, nil, 0)
if err != nil {
2019-11-13 22:51:44 -06:00
log.Printf("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
}