Skip to content

Commit 24a13c6

Browse files
committed
gopls/internal/regtest: fill out features of the new marker tests
Add missing features to the new marker test implementation, implement a few new markers, and port some tests to demonstrate the new structure. Additionally, improve UX following some experience working with these tests. Specifically: - Add support for settings.json. This was necessary for standard library hover, since full documentation was too verbose and varied across Go versions. - Ensure that the ordering of ordinary archive files is preserved. I kept having go.mod sorted below go files, which harms readability. - Add a helper to provide a nice location summary for test output, formatting both local and global (=archive-wide) positions. - Add support for both regexp and string locations conversion. - Add the loc marker, which is pre-processed to make named locations available to other markers. - Add the diag marker, which defines a 1:1 pairing between observed and expected diagnostics. - Add the def marker, which runs textDocument/definition. - Port around half of the godef tests, which include both def and hover markers. While doing so, try to extract related assertions into separate tests, to improve organization and documentation and reduce test size. Remaining tests will have to wait, as this CL was getting too big. For golang/go#54845 Change-Id: Id9fe22c00ebd1b3a96eeacc5c0e82fca9c95c680 Reviewed-on: https://go-review.googlesource.com/c/tools/+/465895 Run-TryBot: Robert Findley <[email protected]> Reviewed-by: Alan Donovan <[email protected]> TryBot-Result: Gopher Robot <[email protected]> gopls-CI: kokoro <[email protected]>
1 parent 2b149ce commit 24a13c6

26 files changed

+973
-1314
lines changed

gopls/internal/lsp/fake/editor.go

+3
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,9 @@ func (e *Editor) setBufferContentLocked(ctx context.Context, path string, dirty
774774

775775
// GoToDefinition jumps to the definition of the symbol at the given position
776776
// in an open buffer. It returns the location of the resulting jump.
777+
//
778+
// TODO(rfindley): rename to "Definition", to be consistent with LSP
779+
// terminology.
777780
func (e *Editor) GoToDefinition(ctx context.Context, loc protocol.Location) (protocol.Location, error) {
778781
if err := e.checkBufferLocation(loc); err != nil {
779782
return protocol.Location{}, err

gopls/internal/lsp/regtest/expectation.go

+20
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,26 @@ func ReadDiagnostics(fileName string, into *protocol.PublishDiagnosticsParams) E
171171
}
172172
}
173173

174+
// ReadAllDiagnostics is an expectation that stores all published diagnostics
175+
// into the provided map, whenever it is evaluated.
176+
//
177+
// It can be used in combination with OnceMet or AfterChange to capture the
178+
// state of diagnostics when other expectations are satisfied.
179+
func ReadAllDiagnostics(into *map[string]*protocol.PublishDiagnosticsParams) Expectation {
180+
check := func(s State) Verdict {
181+
allDiags := make(map[string]*protocol.PublishDiagnosticsParams)
182+
for name, diags := range s.diagnostics {
183+
allDiags[name] = diags
184+
}
185+
*into = allDiags
186+
return Met
187+
}
188+
return Expectation{
189+
Check: check,
190+
Description: "read all diagnostics",
191+
}
192+
}
193+
174194
// NoOutstandingWork asserts that there is no work initiated using the LSP
175195
// $/progress API that has not completed.
176196
func NoOutstandingWork() Expectation {

0 commit comments

Comments
 (0)