gopls/internal/regtest: avoid flake in TestGoModInvalidesOnSave

Investigating flakes in TestGoModInvalidatesOnSave highlighted a couple
bugs:
 + A didOpen on a go.mod file invalidates the workspace, since it is
   treated as a saved change. This, in itself, is probably not such a
   big deal, except that...
 + When metadata is deleted on this didOpen, we break the workspace
   before it can be recomputed.

Fix this by awaiting diagnostics from the didOpen, but it would be
better to have a more robust fix (e.g. CL 271477).

For golang/go#43554

Change-Id: I75d49b818ae2f3730a48ac6a473c24c664227523
Reviewed-on: https://go-review.googlesource.com/c/tools/+/283352
Run-TryBot: Robert Findley <rfindley@google.com>
Trust: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
diff --git a/gopls/internal/regtest/modfile_test.go b/gopls/internal/regtest/modfile_test.go
index e65a7c7..faef053 100644
--- a/gopls/internal/regtest/modfile_test.go
+++ b/gopls/internal/regtest/modfile_test.go
@@ -828,6 +828,7 @@
 		Modes(Singleton),
 	).run(t, mod, func(t *testing.T, env *Env) {
 		env.OpenFile("go.mod")
+		env.Await(CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromDidOpen), 1))
 		env.RegexpReplace("go.mod", "module", "modul")
 		// Confirm that we still have metadata with only on-disk edits.
 		env.OpenFile("main.go")