Skip to content

Commit 46b6958

Browse files
committed
gopls/internal/lsp/source: delete source_test
The source test is one of three (partial) implementations of the tests.Tests interface, which defines the behavior of the marker tests. It makes direct calls to logic in the source package; the other two implementations make LSP RPCs (lsp_test) or fork+exec the gopls command (cmd_test). I have audited all the functions in source_test and satisfied myself that they provide no additional coverage beyond what is provided by lsp_test, and in some cases strictly less. A lot of logic was redundant. Ultimately, lsp_test is what matters, since the LSP is our main interface. Where there was any subtlety or discrepancy, I have remarked below. A few functions in source have been made unexported. This also removes 9s real, 18s CPU, from our CI builds. Details: - CompletionSnippet source_test had opts.Matcher = source.Fuzzy - DeepCompletion source_test had a FuzzyMatcher, but it never affected the outcome. - RankCompletion source_test failed to set these options used in the LSP test: opts.CompleteUnimported = false opts.LiteralCompletions = true - Import lsp_test invokes the broader textDocument/codeAction RPC where source_test called AllImportsFixes. - Definition source_test was calling FormatHover twice! - Rename the LSP implementation does strictly more (reports the file rename). Updates golang/go#54845 Change-Id: I1b0956d56540856dc0494f50ede0be7b7acc3e8e Reviewed-on: https://go-review.googlesource.com/c/tools/+/462816 Run-TryBot: Alan Donovan <[email protected]> Reviewed-by: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent bcc7794 commit 46b6958

File tree

5 files changed

+32
-832
lines changed

5 files changed

+32
-832
lines changed

gopls/internal/lsp/lsp_test.go

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,7 @@ func (r *runner) Diagnostics(t *testing.T, uri span.URI, want []*source.Diagnost
224224
// Get the diagnostics for this view if we have not done it before.
225225
v := r.server.session.View(r.data.Config.Dir)
226226
r.collectDiagnostics(v)
227-
got := append([]*source.Diagnostic(nil), r.diagnostics[uri]...) // copy
228-
tests.CompareDiagnostics(t, uri, want, got)
227+
tests.CompareDiagnostics(t, uri, want, r.diagnostics[uri])
229228
}
230229

231230
func (r *runner) FoldingRanges(t *testing.T, spn span.Span) {
@@ -238,41 +237,30 @@ func (r *runner) FoldingRanges(t *testing.T, spn span.Span) {
238237
modified := original
239238
defer r.server.session.SetViewOptions(r.ctx, view, original)
240239

241-
// Test all folding ranges.
242-
modified.LineFoldingOnly = false
243-
view, err = r.server.session.SetViewOptions(r.ctx, view, modified)
244-
if err != nil {
245-
t.Error(err)
246-
return
247-
}
248-
ranges, err := r.server.FoldingRange(r.ctx, &protocol.FoldingRangeParams{
249-
TextDocument: protocol.TextDocumentIdentifier{
250-
URI: protocol.URIFromSpanURI(uri),
251-
},
252-
})
253-
if err != nil {
254-
t.Error(err)
255-
return
256-
}
257-
r.foldingRanges(t, "foldingRange", uri, ranges)
258-
259-
// Test folding ranges with lineFoldingOnly = true.
260-
modified.LineFoldingOnly = true
261-
view, err = r.server.session.SetViewOptions(r.ctx, view, modified)
262-
if err != nil {
263-
t.Error(err)
264-
return
265-
}
266-
ranges, err = r.server.FoldingRange(r.ctx, &protocol.FoldingRangeParams{
267-
TextDocument: protocol.TextDocumentIdentifier{
268-
URI: protocol.URIFromSpanURI(uri),
269-
},
270-
})
271-
if err != nil {
272-
t.Error(err)
273-
return
240+
for _, test := range []struct {
241+
lineFoldingOnly bool
242+
prefix string
243+
}{
244+
{false, "foldingRange"},
245+
{true, "foldingRange-lineFolding"},
246+
} {
247+
modified.LineFoldingOnly = test.lineFoldingOnly
248+
view, err = r.server.session.SetViewOptions(r.ctx, view, modified)
249+
if err != nil {
250+
t.Error(err)
251+
continue
252+
}
253+
ranges, err := r.server.FoldingRange(r.ctx, &protocol.FoldingRangeParams{
254+
TextDocument: protocol.TextDocumentIdentifier{
255+
URI: protocol.URIFromSpanURI(uri),
256+
},
257+
})
258+
if err != nil {
259+
t.Error(err)
260+
continue
261+
}
262+
r.foldingRanges(t, test.prefix, uri, ranges)
274263
}
275-
r.foldingRanges(t, "foldingRange-lineFolding", uri, ranges)
276264
}
277265

278266
func (r *runner) foldingRanges(t *testing.T, prefix string, uri span.URI, ranges []protocol.FoldingRange) {
@@ -446,6 +434,8 @@ func (r *runner) SemanticTokens(t *testing.T, spn span.Span) {
446434
}
447435

448436
func (r *runner) Import(t *testing.T, spn span.Span) {
437+
// Invokes textDocument/codeAction and applies all the "goimports" edits.
438+
449439
uri := spn.URI()
450440
filename := uri.Filename()
451441
actions, err := r.server.CodeAction(r.ctx, &protocol.CodeActionParams{

gopls/internal/lsp/source/hover.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ func Hover(ctx context.Context, snapshot Snapshot, fh FileHandle, position proto
7979
}
8080
return nil, nil
8181
}
82-
h, err := HoverIdentifier(ctx, ident)
82+
h, err := hoverIdentifier(ctx, ident)
8383
if err != nil {
8484
return nil, err
8585
}
86-
hover, err := FormatHover(h, snapshot.View().Options())
86+
hover, err := formatHover(h, snapshot.View().Options())
8787
if err != nil {
8888
return nil, err
8989
}
@@ -239,7 +239,7 @@ func findRune(ctx context.Context, snapshot Snapshot, fh FileHandle, position pr
239239
return r, rng, nil
240240
}
241241

242-
func HoverIdentifier(ctx context.Context, i *IdentifierInfo) (*HoverJSON, error) {
242+
func hoverIdentifier(ctx context.Context, i *IdentifierInfo) (*HoverJSON, error) {
243243
ctx, done := event.Start(ctx, "source.Hover")
244244
defer done()
245245

@@ -782,7 +782,7 @@ func findFieldComment(pos token.Pos, fieldList *ast.FieldList) *ast.CommentGroup
782782
return nil
783783
}
784784

785-
func FormatHover(h *HoverJSON, options *Options) (string, error) {
785+
func formatHover(h *HoverJSON, options *Options) (string, error) {
786786
signature := formatSignature(h, options)
787787

788788
switch options.HoverKind {

0 commit comments

Comments
 (0)