diff --git a/gocomplete/complete.go b/gocomplete/complete.go index bb3e92e..00392eb 100644 --- a/gocomplete/complete.go +++ b/gocomplete/complete.go @@ -44,7 +44,7 @@ func main() { Flags: complete.Flags{ "-exec": complete.PredictAnything, }, - Args: complete.PredictFunc(predictRunnableFiles), + Args: goFiles, } test := complete.Command{ diff --git a/gocomplete/pkgs.go b/gocomplete/pkgs.go index 356a0fa..e3a85d9 100644 --- a/gocomplete/pkgs.go +++ b/gocomplete/pkgs.go @@ -4,8 +4,6 @@ import ( "bytes" "encoding/json" "os/exec" - "path/filepath" - "regexp" "strings" "github.com/posener/complete" @@ -13,9 +11,6 @@ import ( const goListFormat = `{"Name": "{{.Name}}", "Path": "{{.Dir}}", "FilesString": "{{.GoFiles}}"}` -// regexp matches a main function -var reMainFunc = regexp.MustCompile("^main$") - func predictPackages(a complete.Args) (prediction []string) { dir := a.Directory() pkgs := listPackages(dir) @@ -27,27 +22,6 @@ func predictPackages(a complete.Args) (prediction []string) { return complete.PredictFilesSet(files).Predict(a) } -func predictRunnableFiles(a complete.Args) (prediction []string) { - dir := a.Directory() - pkgs := listPackages(dir) - - files := []string{} - for _, p := range pkgs { - // filter non main pacakges - if p.Name != "main" { - continue - } - for _, f := range p.Files { - path := filepath.Join(p.Path, f) - if len(functionsInFile(path, reMainFunc)) > 0 { - files = append(files, path) - } - } - } - complete.Log("FILES: %s", files) - return complete.PredictFilesSet(files).Predict(a) -} - type pack struct { Name string Path string diff --git a/gocomplete/tests_test.go b/gocomplete/tests_test.go index a72f38f..5683d24 100644 --- a/gocomplete/tests_test.go +++ b/gocomplete/tests_test.go @@ -47,16 +47,6 @@ func TestPredictions(t *testing.T) { predictor: complete.PredictFunc(predictPackages), last: "X", }, - { - name: "predict runnable ok", - predictor: complete.PredictFunc(predictRunnableFiles), - completion: []string{"complete.go"}, - }, - { - name: "predict runnable not found", - predictor: complete.PredictFunc(predictRunnableFiles), - last: "X", - }, } for _, tt := range tests {