diff --git a/gopls/internal/lsp/regtest/expectation.go b/gopls/internal/lsp/regtest/expectation.go index d09398779c..e5beb04271 100644 --- a/gopls/internal/lsp/regtest/expectation.go +++ b/gopls/internal/lsp/regtest/expectation.go @@ -287,10 +287,16 @@ func (e *Env) DoneDiagnosingChanges() Expectation { // AfterChange expects that the given expectations will be met after all // state-changing notifications have been processed by the server. -func (e *Env) AfterChange(expectations ...Expectation) Expectation { - return OnceMet( - e.DoneDiagnosingChanges(), - expectations..., +// +// It awaits the completion of all anticipated work before checking the given +// expectations. +func (e *Env) AfterChange(expectations ...Expectation) { + e.T.Helper() + e.Await( + OnceMet( + e.DoneDiagnosingChanges(), + expectations..., + ), ) } diff --git a/gopls/internal/regtest/modfile/modfile_test.go b/gopls/internal/regtest/modfile/modfile_test.go index 64892be596..4369aefd3f 100644 --- a/gopls/internal/regtest/modfile/modfile_test.go +++ b/gopls/internal/regtest/modfile/modfile_test.go @@ -632,12 +632,10 @@ func main() { env.SaveBuffer("a/go.mod") // Save to trigger diagnostics. d := protocol.PublishDiagnosticsParams{} - env.Await( - env.AfterChange( - // Make sure the diagnostic mentions the new version -- the old diagnostic is in the same place. - env.DiagnosticAtRegexpWithMessage("a/go.mod", "example.com v1.2.3", "example.com@v1.2.3"), - ReadDiagnostics("a/go.mod", &d), - ), + env.AfterChange( + // Make sure the diagnostic mentions the new version -- the old diagnostic is in the same place. + env.DiagnosticAtRegexpWithMessage("a/go.mod", "example.com v1.2.3", "example.com@v1.2.3"), + ReadDiagnostics("a/go.mod", &d), ) qfs := env.GetQuickFixes("a/go.mod", d.Diagnostics) if len(qfs) == 0 { @@ -645,11 +643,9 @@ func main() { } env.ApplyCodeAction(qfs[0]) // Arbitrarily pick a single fix to apply. Applying all of them seems to cause trouble in this particular test. env.SaveBuffer("a/go.mod") // Save to trigger diagnostics. - env.Await( - env.AfterChange( - EmptyDiagnostics("a/go.mod"), - env.DiagnosticAtRegexp("a/main.go", "x = "), - ), + env.AfterChange( + EmptyDiagnostics("a/go.mod"), + env.DiagnosticAtRegexp("a/main.go", "x = "), ) }) }) @@ -678,24 +674,18 @@ func main() { t.Run("good", func(t *testing.T) { runner.Run(t, known, func(t *testing.T, env *Env) { env.OpenFile("a/go.mod") - env.Await( - env.AfterChange( - env.DiagnosticAtRegexp("a/main.go", "x = "), - ), + env.AfterChange( + env.DiagnosticAtRegexp("a/main.go", "x = "), ) env.RegexpReplace("a/go.mod", "v1.2.3", "v1.2.2") env.Editor.SaveBuffer(env.Ctx, "a/go.mod") // go.mod changes must be on disk - env.Await( - env.AfterChange( - env.DiagnosticAtRegexp("a/go.mod", "example.com v1.2.2"), - ), + env.AfterChange( + env.DiagnosticAtRegexp("a/go.mod", "example.com v1.2.2"), ) env.RegexpReplace("a/go.mod", "v1.2.2", "v1.2.3") env.Editor.SaveBuffer(env.Ctx, "a/go.mod") // go.mod changes must be on disk - env.Await( - env.AfterChange( - env.DiagnosticAtRegexp("a/main.go", "x = "), - ), + env.AfterChange( + env.DiagnosticAtRegexp("a/main.go", "x = "), ) }) }) diff --git a/gopls/internal/regtest/workspace/broken_test.go b/gopls/internal/regtest/workspace/broken_test.go index 8cafa3ec1a..fb101d366e 100644 --- a/gopls/internal/regtest/workspace/broken_test.go +++ b/gopls/internal/regtest/workspace/broken_test.go @@ -206,12 +206,10 @@ package b env.OpenFile("a/a.go") env.OpenFile("a/empty.go") env.OpenFile("b/go.mod") - env.Await( - env.AfterChange( - env.DiagnosticAtRegexp("a/a.go", "package a"), - env.DiagnosticAtRegexp("b/go.mod", "module b.com"), - OutstandingWork(lsp.WorkspaceLoadFailure, msg), - ), + env.AfterChange( + env.DiagnosticAtRegexp("a/a.go", "package a"), + env.DiagnosticAtRegexp("b/go.mod", "module b.com"), + OutstandingWork(lsp.WorkspaceLoadFailure, msg), ) // Changing the workspace folders to the valid modules should resolve