From 967bae76f3132c210e6275653f9b603593973858 Mon Sep 17 00:00:00 2001 From: Eyal Posener Date: Thu, 11 May 2017 20:28:31 +0300 Subject: Add Predictor interface --- gocomplete/complete.go | 8 +++++--- gocomplete/tests.go | 15 ++++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'gocomplete') diff --git a/gocomplete/complete.go b/gocomplete/complete.go index 75d3672..1575e1b 100644 --- a/gocomplete/complete.go +++ b/gocomplete/complete.go @@ -6,9 +6,11 @@ import "github.com/posener/complete" var ( predictEllipsis = complete.PredictSet("./...") - goFilesOrPackages = complete.PredictFiles("*.go"). - Or(complete.PredictDirs("*")). - Or(predictEllipsis) + goFilesOrPackages = complete.PredictOr( + complete.PredictFiles("*.go"), + complete.PredictDirs("*"), + predictEllipsis, + ) ) func main() { diff --git a/gocomplete/tests.go b/gocomplete/tests.go index 40210d4..4be3f0d 100644 --- a/gocomplete/tests.go +++ b/gocomplete/tests.go @@ -17,15 +17,16 @@ import ( // and then all the relevant function names. // for test names use prefix of 'Test' or 'Example', and for benchmark // test names use 'Benchmark' -func predictTest(funcPrefix ...string) complete.Predicate { - return func(last string) []match.Matcher { +func predictTest(funcPrefix ...string) complete.Predictor { + return complete.PredictFunc(func(a complete.Args) (prediction []string) { tests := testNames(funcPrefix) - options := make([]match.Matcher, len(tests)) - for i := range tests { - options[i] = match.Prefix(tests[i]) + for _, t := range tests { + if m := match.Prefix(t); m.Match(a.Last) { + prediction = append(prediction, m.String()) + } } - return options - } + return + }) } // get all test names in current directory -- cgit v1.2.3