Skip to content

Commit cf891b7

Browse files
muirdmstamblerre
authored andcommitted
internal/lsp: disable completion time budget in tests
Now a budget of 0 disables mean unlimited and tests no longer set the budget. Hopefully the deep completion tests will stop flaking. Updates golang/go#34617 Change-Id: Icdff5e78dcf1cc3d3fcbf0326716b39b00f0a8c1 Reviewed-on: https://go-review.googlesource.com/c/tools/+/203338 Reviewed-by: Rebecca Stambler <[email protected]> Run-TryBot: Rebecca Stambler <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 2077df3 commit cf891b7

File tree

4 files changed

+3
-12
lines changed

4 files changed

+3
-12
lines changed

internal/lsp/completion_test.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package lsp
33
import (
44
"strings"
55
"testing"
6-
"time"
76

87
"golang.org/x/tools/internal/lsp/protocol"
98
"golang.org/x/tools/internal/lsp/source"
@@ -30,7 +29,6 @@ func (r *runner) CompletionSnippet(t *testing.T, src span.Span, expected tests.C
3029
list := r.callCompletion(t, src, source.CompletionOptions{
3130
Placeholders: placeholders,
3231
Deep: true,
33-
Budget: 5 * time.Second,
3432
FuzzyMatching: true,
3533
})
3634
got := tests.FindItem(list, *items[expected.CompletionItem])
@@ -59,7 +57,6 @@ func (r *runner) UnimportedCompletion(t *testing.T, src span.Span, test tests.Co
5957
func (r *runner) DeepCompletion(t *testing.T, src span.Span, test tests.Completion, items tests.CompletionItems) {
6058
got := r.callCompletion(t, src, source.CompletionOptions{
6159
Deep: true,
62-
Budget: 5 * time.Second,
6360
Documentation: true,
6461
})
6562
if !strings.Contains(string(src.URI()), "builtins") {
@@ -75,7 +72,6 @@ func (r *runner) FuzzyCompletion(t *testing.T, src span.Span, test tests.Complet
7572
got := r.callCompletion(t, src, source.CompletionOptions{
7673
FuzzyMatching: true,
7774
Deep: true,
78-
Budget: 5 * time.Second,
7975
})
8076
if !strings.Contains(string(src.URI()), "builtins") {
8177
got = tests.FilterBuiltins(got)
@@ -103,7 +99,6 @@ func (r *runner) RankCompletion(t *testing.T, src span.Span, test tests.Completi
10399
got := r.callCompletion(t, src, source.CompletionOptions{
104100
FuzzyMatching: true,
105101
Deep: true,
106-
Budget: 5 * time.Second,
107102
})
108103
want := expected(t, test, items)
109104
if msg := tests.CheckCompletionOrder(want, got); msg != "" {
@@ -121,6 +116,7 @@ func expected(t *testing.T, test tests.Completion, items tests.CompletionItems)
121116
}
122117
return want
123118
}
119+
124120
func (r *runner) callCompletion(t *testing.T, src span.Span, options source.CompletionOptions) []protocol.CompletionItem {
125121
t.Helper()
126122

internal/lsp/source/deep_completion.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (c *completer) shouldPrune() bool {
107107
}
108108

109109
// Check our remaining budget every 100 candidates.
110-
if c.deepState.candidateCount%100 == 0 {
110+
if c.opts.Budget > 0 && c.deepState.candidateCount%100 == 0 {
111111
spent := float64(time.Since(c.startTime)) / float64(c.opts.Budget)
112112

113113
switch {

internal/lsp/source/options.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ type CompletionOptions struct {
119119
// requests finish in a couple milliseconds, but in some cases deep
120120
// completions can take much longer. As we use up our budget we
121121
// dynamically reduce the search scope to ensure we return timely
122-
// results.
122+
// results. Zero means unlimited.
123123
Budget time.Duration
124124
}
125125

internal/lsp/source/source_test.go

-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"sort"
1515
"strings"
1616
"testing"
17-
"time"
1817

1918
"golang.org/x/tools/go/packages/packagestest"
2019
"golang.org/x/tools/internal/lsp/cache"
@@ -113,7 +112,6 @@ func (r *runner) CompletionSnippet(t *testing.T, src span.Span, expected tests.C
113112
_, list := r.callCompletion(t, src, source.CompletionOptions{
114113
Placeholders: placeholders,
115114
Deep: true,
116-
Budget: 5 * time.Second,
117115
})
118116
got := tests.FindItem(list, *items[expected.CompletionItem])
119117
want := expected.PlainSnippet
@@ -148,7 +146,6 @@ func (r *runner) DeepCompletion(t *testing.T, src span.Span, test tests.Completi
148146
}
149147
prefix, list := r.callCompletion(t, src, source.CompletionOptions{
150148
Deep: true,
151-
Budget: 5 * time.Second,
152149
Documentation: true,
153150
})
154151
if !strings.Contains(string(src.URI()), "builtins") {
@@ -175,7 +172,6 @@ func (r *runner) FuzzyCompletion(t *testing.T, src span.Span, test tests.Complet
175172
prefix, list := r.callCompletion(t, src, source.CompletionOptions{
176173
FuzzyMatching: true,
177174
Deep: true,
178-
Budget: 5 * time.Second,
179175
})
180176
if !strings.Contains(string(src.URI()), "builtins") {
181177
list = tests.FilterBuiltins(list)
@@ -220,7 +216,6 @@ func (r *runner) RankCompletion(t *testing.T, src span.Span, test tests.Completi
220216
prefix, list := r.callCompletion(t, src, source.CompletionOptions{
221217
FuzzyMatching: true,
222218
Deep: true,
223-
Budget: 5 * time.Second,
224219
})
225220
fuzzyMatcher := fuzzy.NewMatcher(prefix)
226221
var got []protocol.CompletionItem

0 commit comments

Comments
 (0)