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>
diff --git a/internal/lsp/regtest/env.go b/internal/lsp/regtest/env.go
index 73641b1..f6b6a55 100644
--- a/internal/lsp/regtest/env.go
+++ b/internal/lsp/regtest/env.go
@@ -573,6 +573,15 @@
}
}
+// 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{} {