diff --git a/internal/lsp/completion_test.go b/internal/lsp/completion_test.go index 022468adc0..7c20ce103a 100644 --- a/internal/lsp/completion_test.go +++ b/internal/lsp/completion_test.go @@ -3,7 +3,6 @@ package lsp import ( "strings" "testing" - "time" "golang.org/x/tools/internal/lsp/protocol" "golang.org/x/tools/internal/lsp/source" @@ -30,7 +29,6 @@ func (r *runner) CompletionSnippet(t *testing.T, src span.Span, expected tests.C list := r.callCompletion(t, src, source.CompletionOptions{ Placeholders: placeholders, Deep: true, - Budget: 5 * time.Second, FuzzyMatching: true, }) got := tests.FindItem(list, *items[expected.CompletionItem]) @@ -59,7 +57,6 @@ func (r *runner) UnimportedCompletion(t *testing.T, src span.Span, test tests.Co func (r *runner) DeepCompletion(t *testing.T, src span.Span, test tests.Completion, items tests.CompletionItems) { got := r.callCompletion(t, src, source.CompletionOptions{ Deep: true, - Budget: 5 * time.Second, Documentation: true, }) if !strings.Contains(string(src.URI()), "builtins") { @@ -75,7 +72,6 @@ func (r *runner) FuzzyCompletion(t *testing.T, src span.Span, test tests.Complet got := r.callCompletion(t, src, source.CompletionOptions{ FuzzyMatching: true, Deep: true, - Budget: 5 * time.Second, }) if !strings.Contains(string(src.URI()), "builtins") { got = tests.FilterBuiltins(got) @@ -103,7 +99,6 @@ func (r *runner) RankCompletion(t *testing.T, src span.Span, test tests.Completi got := r.callCompletion(t, src, source.CompletionOptions{ FuzzyMatching: true, Deep: true, - Budget: 5 * time.Second, }) want := expected(t, test, items) if msg := tests.CheckCompletionOrder(want, got); msg != "" { @@ -121,6 +116,7 @@ func expected(t *testing.T, test tests.Completion, items tests.CompletionItems) } return want } + func (r *runner) callCompletion(t *testing.T, src span.Span, options source.CompletionOptions) []protocol.CompletionItem { t.Helper() diff --git a/internal/lsp/source/deep_completion.go b/internal/lsp/source/deep_completion.go index 6dd85e7026..b175933879 100644 --- a/internal/lsp/source/deep_completion.go +++ b/internal/lsp/source/deep_completion.go @@ -107,7 +107,7 @@ func (c *completer) shouldPrune() bool { } // Check our remaining budget every 100 candidates. - if c.deepState.candidateCount%100 == 0 { + if c.opts.Budget > 0 && c.deepState.candidateCount%100 == 0 { spent := float64(time.Since(c.startTime)) / float64(c.opts.Budget) switch { diff --git a/internal/lsp/source/options.go b/internal/lsp/source/options.go index e1bc782b90..6f02651f52 100644 --- a/internal/lsp/source/options.go +++ b/internal/lsp/source/options.go @@ -119,7 +119,7 @@ type CompletionOptions struct { // requests finish in a couple milliseconds, but in some cases deep // completions can take much longer. As we use up our budget we // dynamically reduce the search scope to ensure we return timely - // results. + // results. Zero means unlimited. Budget time.Duration } diff --git a/internal/lsp/source/source_test.go b/internal/lsp/source/source_test.go index 8c0d19e7dc..c85cdd8e9d 100644 --- a/internal/lsp/source/source_test.go +++ b/internal/lsp/source/source_test.go @@ -14,7 +14,6 @@ import ( "sort" "strings" "testing" - "time" "golang.org/x/tools/go/packages/packagestest" "golang.org/x/tools/internal/lsp/cache" @@ -113,7 +112,6 @@ func (r *runner) CompletionSnippet(t *testing.T, src span.Span, expected tests.C _, list := r.callCompletion(t, src, source.CompletionOptions{ Placeholders: placeholders, Deep: true, - Budget: 5 * time.Second, }) got := tests.FindItem(list, *items[expected.CompletionItem]) want := expected.PlainSnippet @@ -148,7 +146,6 @@ func (r *runner) DeepCompletion(t *testing.T, src span.Span, test tests.Completi } prefix, list := r.callCompletion(t, src, source.CompletionOptions{ Deep: true, - Budget: 5 * time.Second, Documentation: true, }) if !strings.Contains(string(src.URI()), "builtins") { @@ -175,7 +172,6 @@ func (r *runner) FuzzyCompletion(t *testing.T, src span.Span, test tests.Complet prefix, list := r.callCompletion(t, src, source.CompletionOptions{ FuzzyMatching: true, Deep: true, - Budget: 5 * time.Second, }) if !strings.Contains(string(src.URI()), "builtins") { list = tests.FilterBuiltins(list) @@ -220,7 +216,6 @@ func (r *runner) RankCompletion(t *testing.T, src span.Span, test tests.Completi prefix, list := r.callCompletion(t, src, source.CompletionOptions{ FuzzyMatching: true, Deep: true, - Budget: 5 * time.Second, }) fuzzyMatcher := fuzzy.NewMatcher(prefix) var got []protocol.CompletionItem