From f35d7dcca5e35a48b8699d32b67caebbc56daa22 Mon Sep 17 00:00:00 2001 From: Rob Findley Date: Fri, 30 Jul 2021 15:23:27 -0400 Subject: [PATCH] internal/lsp/source: offer the fast fuzzy matcher as an option Hook up the new fast SymbolMatcher as an option. Benchmark ("test" in x/tools): 48ms->21ms (with the new matcher) Benchmark ("test" in kubernetes): 857ms->199ms (with the new matcher) Change-Id: Ic638eda1ed10572638f32879dd9b56467ae305ef Reviewed-on: https://go-review.googlesource.com/c/tools/+/338695 Trust: Robert Findley Run-TryBot: Robert Findley gopls-CI: kokoro TryBot-Result: Go Bot Reviewed-by: Rebecca Stambler --- gopls/doc/settings.md | 1 + internal/lsp/source/api_json.go | 4 ++++ internal/lsp/source/options.go | 2 ++ internal/lsp/source/workspace_symbol.go | 2 ++ 4 files changed, 9 insertions(+) diff --git a/gopls/doc/settings.md b/gopls/doc/settings.md index 5be569f862..8b0ec839e2 100644 --- a/gopls/doc/settings.md +++ b/gopls/doc/settings.md @@ -397,6 +397,7 @@ Must be one of: * `"CaseInsensitive"` * `"CaseSensitive"` +* `"FastFuzzy"` * `"Fuzzy"` Default: `"Fuzzy"`. diff --git a/internal/lsp/source/api_json.go b/internal/lsp/source/api_json.go index 9accafa8d5..c7522201a9 100755 --- a/internal/lsp/source/api_json.go +++ b/internal/lsp/source/api_json.go @@ -325,6 +325,10 @@ var GeneratedAPIJSON = &APIJSON{ Value: "\"CaseSensitive\"", Doc: "", }, + { + Value: "\"FastFuzzy\"", + Doc: "", + }, { Value: "\"Fuzzy\"", Doc: "", diff --git a/internal/lsp/source/options.go b/internal/lsp/source/options.go index c78bab0c43..5175507dc3 100644 --- a/internal/lsp/source/options.go +++ b/internal/lsp/source/options.go @@ -543,6 +543,7 @@ type SymbolMatcher string const ( SymbolFuzzy SymbolMatcher = "Fuzzy" + SymbolFastFuzzy SymbolMatcher = "FastFuzzy" SymbolCaseInsensitive SymbolMatcher = "CaseInsensitive" SymbolCaseSensitive SymbolMatcher = "CaseSensitive" ) @@ -834,6 +835,7 @@ func (o *Options) set(name string, value interface{}, seen map[string]struct{}) case "symbolMatcher": if s, ok := result.asOneOf( string(SymbolFuzzy), + string(SymbolFastFuzzy), string(SymbolCaseInsensitive), string(SymbolCaseSensitive), ); ok { diff --git a/internal/lsp/source/workspace_symbol.go b/internal/lsp/source/workspace_symbol.go index 3591b08005..b717ed58ba 100644 --- a/internal/lsp/source/workspace_symbol.go +++ b/internal/lsp/source/workspace_symbol.go @@ -157,6 +157,8 @@ func newSymbolCollector(matcher SymbolMatcher, style SymbolStyle, query string) switch matcher { case SymbolFuzzy: m = parseQuery(query) + case SymbolFastFuzzy: + m = fuzzy.NewSymbolMatcher(query).Match case SymbolCaseSensitive: m = matchExact(query) case SymbolCaseInsensitive: