mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00:00
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 <rstambler@golang.org> Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
2077df3685
commit
cf891b754e
@ -3,7 +3,6 @@ package lsp
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"golang.org/x/tools/internal/lsp/protocol"
|
"golang.org/x/tools/internal/lsp/protocol"
|
||||||
"golang.org/x/tools/internal/lsp/source"
|
"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{
|
list := r.callCompletion(t, src, source.CompletionOptions{
|
||||||
Placeholders: placeholders,
|
Placeholders: placeholders,
|
||||||
Deep: true,
|
Deep: true,
|
||||||
Budget: 5 * time.Second,
|
|
||||||
FuzzyMatching: true,
|
FuzzyMatching: true,
|
||||||
})
|
})
|
||||||
got := tests.FindItem(list, *items[expected.CompletionItem])
|
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) {
|
func (r *runner) DeepCompletion(t *testing.T, src span.Span, test tests.Completion, items tests.CompletionItems) {
|
||||||
got := r.callCompletion(t, src, source.CompletionOptions{
|
got := r.callCompletion(t, src, source.CompletionOptions{
|
||||||
Deep: true,
|
Deep: true,
|
||||||
Budget: 5 * time.Second,
|
|
||||||
Documentation: true,
|
Documentation: true,
|
||||||
})
|
})
|
||||||
if !strings.Contains(string(src.URI()), "builtins") {
|
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{
|
got := r.callCompletion(t, src, source.CompletionOptions{
|
||||||
FuzzyMatching: true,
|
FuzzyMatching: true,
|
||||||
Deep: true,
|
Deep: true,
|
||||||
Budget: 5 * time.Second,
|
|
||||||
})
|
})
|
||||||
if !strings.Contains(string(src.URI()), "builtins") {
|
if !strings.Contains(string(src.URI()), "builtins") {
|
||||||
got = tests.FilterBuiltins(got)
|
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{
|
got := r.callCompletion(t, src, source.CompletionOptions{
|
||||||
FuzzyMatching: true,
|
FuzzyMatching: true,
|
||||||
Deep: true,
|
Deep: true,
|
||||||
Budget: 5 * time.Second,
|
|
||||||
})
|
})
|
||||||
want := expected(t, test, items)
|
want := expected(t, test, items)
|
||||||
if msg := tests.CheckCompletionOrder(want, got); msg != "" {
|
if msg := tests.CheckCompletionOrder(want, got); msg != "" {
|
||||||
@ -121,6 +116,7 @@ func expected(t *testing.T, test tests.Completion, items tests.CompletionItems)
|
|||||||
}
|
}
|
||||||
return want
|
return want
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *runner) callCompletion(t *testing.T, src span.Span, options source.CompletionOptions) []protocol.CompletionItem {
|
func (r *runner) callCompletion(t *testing.T, src span.Span, options source.CompletionOptions) []protocol.CompletionItem {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ func (c *completer) shouldPrune() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check our remaining budget every 100 candidates.
|
// 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)
|
spent := float64(time.Since(c.startTime)) / float64(c.opts.Budget)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
|
@ -119,7 +119,7 @@ type CompletionOptions struct {
|
|||||||
// requests finish in a couple milliseconds, but in some cases deep
|
// requests finish in a couple milliseconds, but in some cases deep
|
||||||
// completions can take much longer. As we use up our budget we
|
// completions can take much longer. As we use up our budget we
|
||||||
// dynamically reduce the search scope to ensure we return timely
|
// dynamically reduce the search scope to ensure we return timely
|
||||||
// results.
|
// results. Zero means unlimited.
|
||||||
Budget time.Duration
|
Budget time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"golang.org/x/tools/go/packages/packagestest"
|
"golang.org/x/tools/go/packages/packagestest"
|
||||||
"golang.org/x/tools/internal/lsp/cache"
|
"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{
|
_, list := r.callCompletion(t, src, source.CompletionOptions{
|
||||||
Placeholders: placeholders,
|
Placeholders: placeholders,
|
||||||
Deep: true,
|
Deep: true,
|
||||||
Budget: 5 * time.Second,
|
|
||||||
})
|
})
|
||||||
got := tests.FindItem(list, *items[expected.CompletionItem])
|
got := tests.FindItem(list, *items[expected.CompletionItem])
|
||||||
want := expected.PlainSnippet
|
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{
|
prefix, list := r.callCompletion(t, src, source.CompletionOptions{
|
||||||
Deep: true,
|
Deep: true,
|
||||||
Budget: 5 * time.Second,
|
|
||||||
Documentation: true,
|
Documentation: true,
|
||||||
})
|
})
|
||||||
if !strings.Contains(string(src.URI()), "builtins") {
|
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{
|
prefix, list := r.callCompletion(t, src, source.CompletionOptions{
|
||||||
FuzzyMatching: true,
|
FuzzyMatching: true,
|
||||||
Deep: true,
|
Deep: true,
|
||||||
Budget: 5 * time.Second,
|
|
||||||
})
|
})
|
||||||
if !strings.Contains(string(src.URI()), "builtins") {
|
if !strings.Contains(string(src.URI()), "builtins") {
|
||||||
list = tests.FilterBuiltins(list)
|
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{
|
prefix, list := r.callCompletion(t, src, source.CompletionOptions{
|
||||||
FuzzyMatching: true,
|
FuzzyMatching: true,
|
||||||
Deep: true,
|
Deep: true,
|
||||||
Budget: 5 * time.Second,
|
|
||||||
})
|
})
|
||||||
fuzzyMatcher := fuzzy.NewMatcher(prefix)
|
fuzzyMatcher := fuzzy.NewMatcher(prefix)
|
||||||
var got []protocol.CompletionItem
|
var got []protocol.CompletionItem
|
||||||
|
Loading…
x
Reference in New Issue
Block a user