diff --git a/gopls/internal/regtest/misc/failures_test.go b/gopls/internal/regtest/misc/failures_test.go index 86c9b223c94..185a68cfc8b 100644 --- a/gopls/internal/regtest/misc/failures_test.go +++ b/gopls/internal/regtest/misc/failures_test.go @@ -39,9 +39,12 @@ func main() { }) } -// badPackageDup contains a duplicate definition of the 'a' const. -// this is from diagnostics_test.go, -const badPackageDup = ` +// This test demonstrates a case where gopls is confused by line directives, +// and fails to surface type checking errors. +func TestFailingDiagnosticClearingOnEdit(t *testing.T) { + // badPackageDup contains a duplicate definition of the 'a' const. + // this is from diagnostics_test.go, + const badPackageDup = ` -- go.mod -- module mod.com @@ -56,11 +59,17 @@ package consts const a = 2 ` -func TestFailingDiagnosticClearingOnEdit(t *testing.T) { Run(t, badPackageDup, func(t *testing.T, env *Env) { env.OpenFile("b.go") + // no diagnostics for any files, but there should be - env.Await(NoDiagnostics("a.go"), NoDiagnostics("b.go")) + env.Await( + OnceMet( + env.DoneWithOpen(), + EmptyOrNoDiagnostics("a.go"), + EmptyOrNoDiagnostics("b.go"), + ), + ) // Fix the error by editing the const name in b.go to `b`. env.RegexpReplace("b.go", "(a) = 2", "b") diff --git a/internal/lsp/regtest/env.go b/internal/lsp/regtest/env.go index f8a68b34190..77744ae614a 100644 --- a/internal/lsp/regtest/env.go +++ b/internal/lsp/regtest/env.go @@ -282,6 +282,7 @@ func (a *Awaiter) DiagnosticsFor(name string) *protocol.PublishDiagnosticsParams } func (e *Env) Await(expectations ...Expectation) { + e.T.Helper() if err := e.Awaiter.Await(e.Ctx, expectations...); err != nil { e.T.Fatal(err) }