From e9a00ec8213649efca5f5d4e9d6c1e15dfd9b612 Mon Sep 17 00:00:00 2001 From: Heschi Kreinick Date: Tue, 28 Apr 2020 14:06:04 -0400 Subject: [PATCH] internal/lsp/cache: correctly split env vars We were using strings.Split on env vars, which did bad stuff when the var contained an =, e.g. GOFLAGS=-tags=foo. Only split on the first =. Irritatingly, this breaks only `go mod` commands, so almost nothing in gopls failed, just organize imports and the `go.mod` code lens stuff. Fixes golang/go#38669 Change-Id: I8d28c806b77a8df92100af1fa4fbcca5edf97cff Reviewed-on: https://go-review.googlesource.com/c/tools/+/230560 Run-TryBot: Heschi Kreinick TryBot-Result: Gobot Gobot Reviewed-by: Rebecca Stambler --- internal/lsp/cache/view.go | 2 +- internal/lsp/regtest/diagnostics_test.go | 27 +++++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/internal/lsp/cache/view.go b/internal/lsp/cache/view.go index 7aefe630c2..2aaa7b1f18 100644 --- a/internal/lsp/cache/view.go +++ b/internal/lsp/cache/view.go @@ -373,7 +373,7 @@ func (v *view) buildProcessEnv(ctx context.Context) (*imports.ProcessEnv, error) } } for _, kv := range env { - split := strings.Split(kv, "=") + split := strings.SplitN(kv, "=", 2) if len(split) < 2 { continue } diff --git a/internal/lsp/regtest/diagnostics_test.go b/internal/lsp/regtest/diagnostics_test.go index 3bf4fc28a4..eac2a78462 100644 --- a/internal/lsp/regtest/diagnostics_test.go +++ b/internal/lsp/regtest/diagnostics_test.go @@ -245,7 +245,7 @@ func TestHello(t *testing.T) { } ` -func Test_Issue38267(t *testing.T) { +func TestIssue38267(t *testing.T) { runner.Run(t, testPackage, func(t *testing.T, env *Env) { env.OpenFile("lib_test.go") env.Await( @@ -330,7 +330,7 @@ func TestMissingDependency(t *testing.T) { }) } -func TestAdHocPackagesIssue_36951(t *testing.T) { +func TestAdHocPackages_Issue36951(t *testing.T) { const adHoc = ` -- b/b.go -- package b @@ -345,7 +345,7 @@ func Hello() { }) } -func TestNoGOPATHIssue_37984(t *testing.T) { +func TestNoGOPATH_Issue37984(t *testing.T) { const missingImport = ` -- main.go -- package main @@ -362,3 +362,24 @@ func _() { } }, WithEnv("GOPATH=")) } + +func TestEqualInEnv_Issue38669(t *testing.T) { + const missingImport = ` +-- go.mod -- +module mod.com + +-- main.go -- +package main + +var _ = x.X +-- x/x.go -- +package x + +var X = 0 +` + runner.Run(t, missingImport, func(t *testing.T, env *Env) { + env.OpenFile("main.go") + env.OrganizeImports("main.go") + env.Await(EmptyDiagnostics("main.go")) + }, WithEnv("GOFLAGS=-tags=foo")) +}