From 308beac2836fb4709e6cb9035f5efb4eda440b78 Mon Sep 17 00:00:00 2001 From: pjw Date: Sat, 6 Jun 2020 07:47:14 -0400 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Robert Findley --- internal/lsp/regtest/env.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/lsp/regtest/env.go b/internal/lsp/regtest/env.go index 73641b1979..f6b6a55b57 100644 --- a/internal/lsp/regtest/env.go +++ b/internal/lsp/regtest/env.go @@ -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{} {