gopls/internal/regtest: always await InitialWorkspaceLoad

There's very little reason not to always await IWL, and none of our
tests actually need to be able to execute before it completes.

Await IWL before running the test func.

Change-Id: Ia0626aa4e4c6cfa89dc5d03075b6bd797574a8dc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/258078
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Trust: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
diff --git a/gopls/internal/regtest/bench_test.go b/gopls/internal/regtest/bench_test.go
index 8a7fbdb..5ad9358 100644
--- a/gopls/internal/regtest/bench_test.go
+++ b/gopls/internal/regtest/bench_test.go
@@ -37,9 +37,7 @@
 
 	results := testing.Benchmark(func(b *testing.B) {
 		for i := 0; i < b.N; i++ {
-			withOptions(opts...).run(t, "", func(t *testing.T, env *Env) {
-				env.Await(InitialWorkspaceLoad)
-			})
+			withOptions(opts...).run(t, "", func(t *testing.T, env *Env) {})
 		}
 	})
 
diff --git a/gopls/internal/regtest/codelens_test.go b/gopls/internal/regtest/codelens_test.go
index 5dd3afb..d0af635 100644
--- a/gopls/internal/regtest/codelens_test.go
+++ b/gopls/internal/regtest/codelens_test.go
@@ -253,7 +253,6 @@
 	withOptions(
 		EditorConfig{CodeLens: map[string]bool{"gc_details": true}},
 	).run(t, mod, func(t *testing.T, env *Env) {
-		env.Await(InitialWorkspaceLoad)
 		env.OpenFile("main.go")
 		env.ExecuteCodeLensCommand("main.go", source.CommandToggleDetails)
 		d := &protocol.PublishDiagnosticsParams{}
diff --git a/gopls/internal/regtest/completion_bench_test.go b/gopls/internal/regtest/completion_bench_test.go
index 1b6fe46..267eeb6 100644
--- a/gopls/internal/regtest/completion_bench_test.go
+++ b/gopls/internal/regtest/completion_bench_test.go
@@ -46,7 +46,6 @@
 	opts = append(opts, SkipHooks(false))
 
 	withOptions(opts...).run(t, "", func(t *testing.T, env *Env) {
-		env.Await(InitialWorkspaceLoad)
 		env.OpenFile(options.file)
 
 		// Run edits required for this completion.
diff --git a/gopls/internal/regtest/configuration_test.go b/gopls/internal/regtest/configuration_test.go
index 3fab18f..b61a8a8 100644
--- a/gopls/internal/regtest/configuration_test.go
+++ b/gopls/internal/regtest/configuration_test.go
@@ -26,7 +26,6 @@
 const ThisVariable = 7
 `
 	run(t, files, func(t *testing.T, env *Env) {
-		env.Await(InitialWorkspaceLoad)
 		env.OpenFile("a/a.go")
 		env.Await(
 			CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromDidOpen), 1),
diff --git a/gopls/internal/regtest/diagnostics_test.go b/gopls/internal/regtest/diagnostics_test.go
index a727a9d..0ddf6cb 100644
--- a/gopls/internal/regtest/diagnostics_test.go
+++ b/gopls/internal/regtest/diagnostics_test.go
@@ -847,7 +847,6 @@
 	-- foo/bar_test.go --
 	`
 	run(t, mod, func(t *testing.T, env *Env) {
-		env.Await(InitialWorkspaceLoad)
 		env.OpenFile("foo/bar_test.go")
 		env.EditBuffer("foo/bar_test.go", fake.NewEdit(0, 0, 0, 0, `package foo
 	`))
@@ -876,7 +875,6 @@
 package foo_
 `
 	run(t, mod, func(t *testing.T, env *Env) {
-		env.Await(InitialWorkspaceLoad)
 		env.OpenFile("foo/bar_test.go")
 		env.RegexpReplace("foo/bar_test.go", "package foo_", "package foo_test")
 		env.SaveBuffer("foo/bar_test.go")
@@ -1101,7 +1099,6 @@
 	runner.Run(t, basic, func(t *testing.T, env *Env) {
 		testenv.NeedsGo1Point(t, 15)
 
-		env.Await(InitialWorkspaceLoad)
 		env.WriteWorkspaceFile("foo/foo_test.go", `package main
 
 func main() {
@@ -1130,7 +1127,6 @@
 func main() {}
 `
 	runner.Run(t, basic, func(t *testing.T, env *Env) {
-		env.Await(InitialWorkspaceLoad)
 		env.Editor.OpenFileWithContent(env.Ctx, "foo.go", `package main`)
 		env.Await(
 			CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromDidOpen), 1),
@@ -1289,7 +1285,6 @@
 		log.SetFlags(log.Lshortfile)
 		env.OpenFile("main.go")
 		env.OpenFile("other.go")
-		env.Await(InitialWorkspaceLoad)
 		x := env.DiagnosticsFor("main.go")
 		if x == nil {
 			t.Fatalf("expected 1 diagnostic, got none")
@@ -1338,7 +1333,6 @@
 }
 `
 	run(t, files, func(t *testing.T, env *Env) {
-		env.Await(InitialWorkspaceLoad)
 		env.OpenFile("a/a.go")
 		env.Await(
 			env.DiagnosticAtRegexp("a/a.go", "x"),
diff --git a/gopls/internal/regtest/fix_test.go b/gopls/internal/regtest/fix_test.go
index 423f008..887f282 100644
--- a/gopls/internal/regtest/fix_test.go
+++ b/gopls/internal/regtest/fix_test.go
@@ -28,7 +28,6 @@
 }
 `
 	runner.Run(t, basic, func(t *testing.T, env *Env) {
-		env.Await(InitialWorkspaceLoad)
 		env.OpenFile("main.go")
 		if err := env.Editor.RefactorRewrite(env.Ctx, "main.go", &protocol.Range{
 			Start: protocol.Position{
diff --git a/gopls/internal/regtest/imports_test.go b/gopls/internal/regtest/imports_test.go
index 6b95b17..e92746f 100644
--- a/gopls/internal/regtest/imports_test.go
+++ b/gopls/internal/regtest/imports_test.go
@@ -189,7 +189,6 @@
 }
 `
 	run(t, pkg, func(t *testing.T, env *Env) {
-		env.Await(InitialWorkspaceLoad)
 		env.OpenFile("a/a.go")
 		var d protocol.PublishDiagnosticsParams
 		env.Await(
diff --git a/gopls/internal/regtest/modfile_test.go b/gopls/internal/regtest/modfile_test.go
index 0e28f2e..aa5e864 100644
--- a/gopls/internal/regtest/modfile_test.go
+++ b/gopls/internal/regtest/modfile_test.go
@@ -317,10 +317,7 @@
 go 1.12
 `
 	runner.Run(t, mod, func(t *testing.T, env *Env) {
-		env.Await(
-			InitialWorkspaceLoad,
-			env.DiagnosticAtRegexp("go.mod", "require"),
-		)
+		env.Await(env.DiagnosticAtRegexp("go.mod", "require"))
 		env.Sandbox.RunGoCommand(env.Ctx, "", "mod", []string{"tidy"})
 		env.Await(
 			EmptyDiagnostics("go.mod"),
@@ -436,7 +433,6 @@
 	// Start from a bad state/bad IWL, and confirm that we recover.
 	t.Run("bad", func(t *testing.T) {
 		runner.Run(t, unknown, func(t *testing.T, env *Env) {
-			env.Await(InitialWorkspaceLoad)
 			env.OpenFile("go.mod")
 			env.Await(
 				env.DiagnosticAtRegexp("go.mod", "example.com v1.2.2"),
diff --git a/gopls/internal/regtest/runner.go b/gopls/internal/regtest/runner.go
index 0d466b5..d595a29 100644
--- a/gopls/internal/regtest/runner.go
+++ b/gopls/internal/regtest/runner.go
@@ -281,6 +281,8 @@
 				}
 				env.CloseEditor()
 			}()
+			// Always await the initial workspace load.
+			env.Await(InitialWorkspaceLoad)
 			test(t, env)
 		})
 	}
diff --git a/gopls/internal/regtest/watch_test.go b/gopls/internal/regtest/watch_test.go
index 8ed4f7b..7895787 100644
--- a/gopls/internal/regtest/watch_test.go
+++ b/gopls/internal/regtest/watch_test.go
@@ -309,7 +309,6 @@
 	// Add the new method before the implementation. Expect diagnostics.
 	t.Run("method before implementation", func(t *testing.T) {
 		runner.Run(t, pkg, func(t *testing.T, env *Env) {
-			env.Await(InitialWorkspaceLoad)
 			env.WriteWorkspaceFile("b/b.go", newMethod)
 			env.Await(
 				OnceMet(
@@ -326,7 +325,6 @@
 	// Add the new implementation before the new method. Expect no diagnostics.
 	t.Run("implementation before method", func(t *testing.T) {
 		runner.Run(t, pkg, func(t *testing.T, env *Env) {
-			env.Await(InitialWorkspaceLoad)
 			env.WriteWorkspaceFile("a/a.go", implementation)
 			env.Await(
 				OnceMet(
@@ -343,7 +341,6 @@
 	// Add both simultaneously. Expect no diagnostics.
 	t.Run("implementation and method simultaneously", func(t *testing.T) {
 		runner.Run(t, pkg, func(t *testing.T, env *Env) {
-			env.Await(InitialWorkspaceLoad)
 			env.WriteWorkspaceFiles(map[string]string{
 				"a/a.go": implementation,
 				"b/b.go": newMethod,
@@ -473,7 +470,6 @@
 func _() {}
 `
 	runner.Run(t, pkg, func(t *testing.T, env *Env) {
-		env.Await(InitialWorkspaceLoad)
 		env.ChangeFilesOnDisk([]fake.FileEvent{
 			{
 				Path: "a/a3.go",
@@ -560,7 +556,6 @@
 }
 `
 	withOptions(WithProxyFiles(proxy)).run(t, mod, func(t *testing.T, env *Env) {
-		env.Await(InitialWorkspaceLoad)
 		env.WriteWorkspaceFiles(map[string]string{
 			"go.mod": `module mod.com
 
@@ -606,12 +601,7 @@
 `
 	withOptions(InGOPATH()).run(t, files, func(t *testing.T, env *Env) {
 		env.OpenFile("foo/main.go")
-		env.Await(
-			OnceMet(
-				InitialWorkspaceLoad,
-				env.DiagnosticAtRegexp("foo/main.go", `"blah"`),
-			),
-		)
+		env.Await(env.DiagnosticAtRegexp("foo/main.go", `"blah"`))
 		if err := env.Sandbox.RunGoCommand(env.Ctx, "foo", "mod", []string{"init", "mod.com"}); err != nil {
 			t.Fatal(err)
 		}
@@ -651,7 +641,6 @@
 }
 `
 	run(t, files, func(t *testing.T, env *Env) {
-		env.Await(InitialWorkspaceLoad)
 		// Add a new symbol to the package under test and use it in the test
 		// variant. Expect no diagnostics.
 		env.WriteWorkspaceFiles(map[string]string{
diff --git a/gopls/internal/regtest/workspace_test.go b/gopls/internal/regtest/workspace_test.go
index 72c3ec1..3f79d57 100644
--- a/gopls/internal/regtest/workspace_test.go
+++ b/gopls/internal/regtest/workspace_test.go
@@ -140,7 +140,6 @@
 // replace target is added to the go.mod.
 func TestWatchReplaceTargets(t *testing.T) {
 	withOptions(WithProxyFiles(workspaceProxy), WithRootPath("pkg")).run(t, workspaceModule, func(t *testing.T, env *Env) {
-		env.Await(InitialWorkspaceLoad)
 		// Add a replace directive and expect the files that gopls is watching
 		// to change.
 		dir := env.Sandbox.Workdir.URI("goodbye").SpanURI().Filename()
@@ -198,7 +197,6 @@
 	withOptions(
 		WithProxyFiles(workspaceModuleProxy),
 	).run(t, multiModule, func(t *testing.T, env *Env) {
-		env.Await(InitialWorkspaceLoad)
 		env.Await(
 			env.DiagnosticAtRegexp("moda/a/a.go", "x"),
 			env.DiagnosticAtRegexp("modb/b/b.go", "x"),
@@ -240,7 +238,6 @@
 	withOptions(
 		WithProxyFiles(workspaceModuleProxy),
 	).run(t, multiModule, func(t *testing.T, env *Env) {
-		env.Await(InitialWorkspaceLoad)
 		env.OpenFile("moda/a/a.go")
 
 		original, _ := env.GoToDefinition("moda/a/a.go", env.RegexpSearch("moda/a/a.go", "Hello"))
@@ -284,7 +281,6 @@
 	withOptions(
 		WithProxyFiles(workspaceModuleProxy),
 	).run(t, multiModule, func(t *testing.T, env *Env) {
-		env.Await(InitialWorkspaceLoad)
 		env.OpenFile("moda/a/a.go")
 		original, _ := env.GoToDefinition("moda/a/a.go", env.RegexpSearch("moda/a/a.go", "Hello"))
 		if want := "b.com@v1.2.3/b/b.go"; !strings.HasSuffix(original, want) {
@@ -343,7 +339,6 @@
 }
 `
 	run(t, multiModule, func(t *testing.T, env *Env) {
-		env.Await(InitialWorkspaceLoad)
 		env.OpenFile("modb/go.mod")
 		env.Await(
 			OnceMet(
@@ -399,7 +394,6 @@
 	withOptions(
 		WithProxyFiles(workspaceModuleProxy),
 	).run(t, multiModule, func(t *testing.T, env *Env) {
-		env.Await(InitialWorkspaceLoad)
 		env.OpenFile("moda/a/a.go")
 		original, _ := env.GoToDefinition("moda/a/a.go", env.RegexpSearch("moda/a/a.go", "Hello"))
 		if want := "b.com@v1.2.3/b/b.go"; !strings.HasSuffix(original, want) {