From 4d0b3834583013776f95cae07b2edbfc451c1898 Mon Sep 17 00:00:00 2001 From: Robert Findley Date: Tue, 2 Aug 2022 10:54:01 -0400 Subject: [PATCH] internal/lsp/regtest: minor cleanup for magic regtest envvar For some reason, we were not reusing the constant runTestAsGoplsEnvVar in the regtest Main function. Fix this, add a bit more commentary, and check the envvar before doing anything else. Also fix the threading of hooks to the created gopls server. Tested manually via -enable_gopls_subprocess_tests. Change-Id: Ieb5329aa5850e845f4d9e3868703bfa16387bce3 Reviewed-on: https://go-review.googlesource.com/c/tools/+/420716 Reviewed-by: Hyang-Ah Hana Kim TryBot-Result: Gopher Robot Run-TryBot: Robert Findley gopls-CI: kokoro --- internal/lsp/regtest/regtest.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/internal/lsp/regtest/regtest.go b/internal/lsp/regtest/regtest.go index cfd999dfa5..b041891702 100644 --- a/internal/lsp/regtest/regtest.go +++ b/internal/lsp/regtest/regtest.go @@ -94,16 +94,19 @@ func DefaultModes() Mode { // Main sets up and tears down the shared regtest state. func Main(m *testing.M, hook func(*source.Options)) { + // If this magic environment variable is set, run gopls instead of the test + // suite. See the documentation for runTestAsGoplsEnvvar for more details. + if os.Getenv(runTestAsGoplsEnvvar) == "true" { + tool.Main(context.Background(), cmd.New("gopls", "", nil, hook), os.Args[1:]) + os.Exit(0) + } + testenv.ExitIfSmallMachine() // Disable GOPACKAGESDRIVER, as it can cause spurious test failures. os.Setenv("GOPACKAGESDRIVER", "off") flag.Parse() - if os.Getenv("_GOPLS_TEST_BINARY_RUN_AS_GOPLS") == "true" { - tool.Main(context.Background(), cmd.New("gopls", "", nil, nil), os.Args[1:]) - os.Exit(0) - } runner = &Runner{ DefaultModes: DefaultModes(),