internal/lsp: add a way for regtests to look at the diagnostics

regtests can use Await to wait for diagnostic expectations. But sometimes
it is useful (or more robust) to then look at the specific diagnostics.
This change introduces env.DiagnosticsFor, which returns the current
diagnostics for a file.

Change-Id: Iea35d28f6679289795bc853f156aae351279b205
Reviewed-on: https://go-review.googlesource.com/c/tools/+/236837
Run-TryBot: Peter Weinberger <pjw@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
pjw 2020-06-06 07:47:14 -04:00 committed by Peter Weinberger
parent 6eec81c746
commit 308beac283
1 changed files with 9 additions and 0 deletions

View File

@ -573,6 +573,15 @@ func DiagnosticAt(name string, line, col int) DiagnosticExpectation {
}
}
// DiagnosticsFor returns the current diagnostics for the file. It is useful
// after waiting on AnyDiagnosticAtCurrentVersion, when the desired diagnostic
// is not simply described by DiagnosticAt.
func (e *Env) DiagnosticsFor(name string) *protocol.PublishDiagnosticsParams {
e.mu.Lock()
defer e.mu.Unlock()
return e.state.diagnostics[name]
}
// Await waits for all expectations to simultaneously be met. It should only be
// called from the main test goroutine.
func (e *Env) Await(expectations ...Expectation) []interface{} {