Skip to content

Commit 33d416e

Browse files
adonovangopherbot
authored andcommitted
gopls/internal/lsp: add missing comments on 3x tests.Test impls
Also, use top-down order for some decls. Updates golang/go#54845 Change-Id: I5d732593fb709c02300b46a444360c4909b92773 Reviewed-on: https://go-review.googlesource.com/c/tools/+/462659 Reviewed-by: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]> gopls-CI: kokoro <[email protected]> Run-TryBot: Alan Donovan <[email protected]> Auto-Submit: Alan Donovan <[email protected]>
1 parent afea272 commit 33d416e

File tree

4 files changed

+42
-25
lines changed

4 files changed

+42
-25
lines changed

gopls/internal/lsp/cmd/test/cmdtest.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,38 @@ import (
2828
"golang.org/x/tools/internal/tool"
2929
)
3030

31-
type runner struct {
32-
data *tests.Data
33-
ctx context.Context
34-
options func(*source.Options)
35-
normalizers []tests.Normalizer
36-
remote string
37-
}
38-
31+
// TestCommandLine runs the marker tests in files beneath testdata/ using
32+
// implementations of each of the marker operations (e.g. @hover) that
33+
// fork+exec the gopls command.
3934
func TestCommandLine(t *testing.T, testdata string, options func(*source.Options)) {
4035
// On Android, the testdata directory is not copied to the runner.
4136
if runtime.GOOS == "android" {
4237
t.Skip("testdata directory not present on android")
4338
}
4439
tests.RunTests(t, testdata, false, func(t *testing.T, datum *tests.Data) {
4540
ctx := tests.Context(t)
46-
ts := NewTestServer(ctx, options)
41+
ts := newTestServer(ctx, options)
4742
tests.Run(t, NewRunner(datum, ctx, ts.Addr, options), datum)
4843
cmd.CloseTestConnections(ctx)
4944
})
5045
}
5146

52-
func NewTestServer(ctx context.Context, options func(*source.Options)) *servertest.TCPServer {
47+
func newTestServer(ctx context.Context, options func(*source.Options)) *servertest.TCPServer {
5348
ctx = debug.WithInstance(ctx, "", "")
5449
cache := cache.New(nil, nil)
5550
ss := lsprpc.NewStreamServer(cache, false, options)
5651
return servertest.NewTCPServer(ctx, ss, nil)
5752
}
5853

54+
// runner implements tests.Tests by fork+execing the gopls command.
55+
type runner struct {
56+
data *tests.Data
57+
ctx context.Context
58+
options func(*source.Options)
59+
normalizers []tests.Normalizer
60+
remote string
61+
}
62+
5963
func NewRunner(data *tests.Data, ctx context.Context, remote string, options func(*source.Options)) *runner {
6064
return &runner{
6165
data: data,

gopls/internal/lsp/lsp_test.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,13 @@ func TestMain(m *testing.M) {
4343
os.Exit(m.Run())
4444
}
4545

46+
// TestLSP runs the marker tests in files beneath testdata/ using
47+
// implementations of each of the marker operations (e.g. @hover) that
48+
// make LSP RPCs (e.g. textDocument/hover) to a gopls server.
4649
func TestLSP(t *testing.T) {
4750
tests.RunTests(t, "testdata", true, testLSP)
4851
}
4952

50-
type runner struct {
51-
server *Server
52-
data *tests.Data
53-
diagnostics map[span.URI][]*source.Diagnostic
54-
ctx context.Context
55-
normalizers []tests.Normalizer
56-
editRecv chan map[span.URI]string
57-
}
58-
5953
func testLSP(t *testing.T, datum *tests.Data) {
6054
ctx := tests.Context(t)
6155

@@ -110,6 +104,16 @@ func testLSP(t *testing.T, datum *tests.Data) {
110104
tests.Run(t, r, datum)
111105
}
112106

107+
// runner implements tests.Tests by making LSP RPCs to a gopls server.
108+
type runner struct {
109+
server *Server
110+
data *tests.Data
111+
diagnostics map[span.URI][]*source.Diagnostic
112+
ctx context.Context
113+
normalizers []tests.Normalizer
114+
editRecv chan map[span.URI]string
115+
}
116+
113117
// testClient stubs any client functions that may be called by LSP functions.
114118
type testClient struct {
115119
protocol.Client

gopls/internal/lsp/source/source_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ func TestMain(m *testing.M) {
3333
os.Exit(m.Run())
3434
}
3535

36+
// TestSource runs the marker tests in files beneath testdata/ using
37+
// implementations of each of the marker operations (e.g. @hover) that
38+
// make direct calls to the server logic (such as source.Hover).
3639
func TestSource(t *testing.T) {
3740
tests.RunTests(t, "../testdata", true, testSource)
3841
}
3942

43+
// runner implements tests.Tests by making direct calls to the source package.
4044
type runner struct {
4145
session *cache.Session
4246
view *cache.View

gopls/internal/lsp/tests/tests.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,17 @@ type Data struct {
143143
mappers map[span.URI]*protocol.Mapper
144144
}
145145

146-
// TODO(adonovan): there are multiple implementations of this (undocumented)
147-
// interface, each of which must implement similar semantics. For example:
148-
// - *runner in ../cmd/test/check.go
149-
// - *runner in ../source/source_test.go
150-
// - *runner in ../lsp_test.go
151-
// Can we avoid this duplication?
146+
// The Tests interface abstracts a set of implementations of marker
147+
// test operators (such as @hover) appearing
148+
//
149+
// There are three implementations:
150+
// - *runner in ../cmd/test/check.go, which runs the command-line tool (e.g. "gopls hover")
151+
// - *runner in ../source/source_test.go, which makes direct calls (e.g. to source.Hover)
152+
// - *runner in ../lsp_test.go, which makes LSP requests (textDocument/hover) to a gopls server.
153+
//
154+
// Not all implementations implement all methods.
155+
//
156+
// TODO(adonovan): reduce duplication; see https://github.com/golang/go/issues/54845.
152157
type Tests interface {
153158
CallHierarchy(*testing.T, span.Span, *CallHierarchyResult)
154159
CodeLens(*testing.T, span.URI, []protocol.CodeLens)

0 commit comments

Comments
 (0)