Skip to content

Commit

Permalink
gopls/internal/regtest: fill out features of the new marker tests
Browse files Browse the repository at this point in the history
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 <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
  • Loading branch information
findleyr committed Feb 7, 2023
1 parent 2b149ce commit 24a13c6
Show file tree
Hide file tree
Showing 26 changed files with 973 additions and 1,314 deletions.
3 changes: 3 additions & 0 deletions gopls/internal/lsp/fake/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,9 @@ func (e *Editor) setBufferContentLocked(ctx context.Context, path string, dirty

// GoToDefinition jumps to the definition of the symbol at the given position
// in an open buffer. It returns the location of the resulting jump.
//
// TODO(rfindley): rename to "Definition", to be consistent with LSP
// terminology.
func (e *Editor) GoToDefinition(ctx context.Context, loc protocol.Location) (protocol.Location, error) {
if err := e.checkBufferLocation(loc); err != nil {
return protocol.Location{}, err
Expand Down
20 changes: 20 additions & 0 deletions gopls/internal/lsp/regtest/expectation.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,26 @@ func ReadDiagnostics(fileName string, into *protocol.PublishDiagnosticsParams) E
}
}

// ReadAllDiagnostics is an expectation that stores all published diagnostics
// into the provided map, whenever it is evaluated.
//
// It can be used in combination with OnceMet or AfterChange to capture the
// state of diagnostics when other expectations are satisfied.
func ReadAllDiagnostics(into *map[string]*protocol.PublishDiagnosticsParams) Expectation {
check := func(s State) Verdict {
allDiags := make(map[string]*protocol.PublishDiagnosticsParams)
for name, diags := range s.diagnostics {
allDiags[name] = diags
}
*into = allDiags
return Met
}
return Expectation{
Check: check,
Description: "read all diagnostics",
}
}

// NoOutstandingWork asserts that there is no work initiated using the LSP
// $/progress API that has not completed.
func NoOutstandingWork() Expectation {
Expand Down
Loading

0 comments on commit 24a13c6

Please sign in to comment.