mirror of https://github.com/golang/go.git
gopls/internal/lsp/tests: simplify collectCompletionItems, remove Data.t
The marker function collectCompletionItems required at least three arguments. Express this in its signature, leaving a final variadic argument for documentation. I considered just making this final argument mandatory, but opted for minimizing the diff given that there are 400+ existing @item annotations. With this change the only use of tests.Data.t is in mustRange. Since conversion to range should always succeed, I switched this usage to a panic and removed the t field. For golang/go#54845 Change-Id: I407f07cb85fa1356ceb6dba366007f69d1b6a068 Reviewed-on: https://go-review.googlesource.com/c/tools/+/432337 Reviewed-by: Alan Donovan <adonovan@google.com> Run-TryBot: Robert Findley <rfindley@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
88b5529c9e
commit
b243e57ea8
|
|
@ -130,7 +130,6 @@ type Data struct {
|
|||
AddImport AddImport
|
||||
Hovers Hovers
|
||||
|
||||
t testing.TB
|
||||
fragments map[string]string
|
||||
dir string
|
||||
golden map[string]*Golden
|
||||
|
|
@ -337,7 +336,6 @@ func load(t testing.TB, mode string, dir string) *Data {
|
|||
AddImport: make(AddImport),
|
||||
Hovers: make(Hovers),
|
||||
|
||||
t: t,
|
||||
dir: dir,
|
||||
fragments: map[string]string{},
|
||||
golden: map[string]*Golden{},
|
||||
|
|
@ -1187,15 +1185,9 @@ func (data *Data) collectCompletions(typ CompletionTestType) func(span.Span, []t
|
|||
}
|
||||
}
|
||||
|
||||
func (data *Data) collectCompletionItems(pos token.Pos, args []string) {
|
||||
if len(args) < 3 {
|
||||
loc := data.Exported.ExpectFileSet.Position(pos)
|
||||
data.t.Fatalf("%s:%d: @item expects at least 3 args, got %d",
|
||||
loc.Filename, loc.Line, len(args))
|
||||
}
|
||||
label, detail, kind := args[0], args[1], args[2]
|
||||
func (data *Data) collectCompletionItems(pos token.Pos, label, detail, kind string, args []string) {
|
||||
var documentation string
|
||||
if len(args) == 4 {
|
||||
if len(args) > 3 {
|
||||
documentation = args[3]
|
||||
}
|
||||
data.CompletionItems[pos] = &completion.CompletionItem{
|
||||
|
|
@ -1354,14 +1346,12 @@ func (data *Data) collectSymbols(name string, selectionRng span.Span, kind, deta
|
|||
})
|
||||
}
|
||||
|
||||
// mustRange converts spn into a protocol.Range, calling t.Fatal on any error.
|
||||
// mustRange converts spn into a protocol.Range, panicking on any error.
|
||||
func (data *Data) mustRange(spn span.Span) protocol.Range {
|
||||
m, err := data.Mapper(spn.URI())
|
||||
rng, err := m.Range(spn)
|
||||
if err != nil {
|
||||
// TODO(rfindley): this can probably just be a panic, at which point we
|
||||
// don't need to close over t.
|
||||
data.t.Fatal(err)
|
||||
panic(fmt.Sprintf("converting span %s to range: %v", spn, err))
|
||||
}
|
||||
return rng
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue