Skip to content

Commit e9a00ec

Browse files
committed
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 #38669 Change-Id: I8d28c806b77a8df92100af1fa4fbcca5edf97cff Reviewed-on: https://go-review.googlesource.com/c/tools/+/230560 Run-TryBot: Heschi Kreinick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
1 parent 006b16f commit e9a00ec

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

internal/lsp/cache/view.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ func (v *view) buildProcessEnv(ctx context.Context) (*imports.ProcessEnv, error)
373373
}
374374
}
375375
for _, kv := range env {
376-
split := strings.Split(kv, "=")
376+
split := strings.SplitN(kv, "=", 2)
377377
if len(split) < 2 {
378378
continue
379379
}

internal/lsp/regtest/diagnostics_test.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func TestHello(t *testing.T) {
245245
}
246246
`
247247

248-
func Test_Issue38267(t *testing.T) {
248+
func TestIssue38267(t *testing.T) {
249249
runner.Run(t, testPackage, func(t *testing.T, env *Env) {
250250
env.OpenFile("lib_test.go")
251251
env.Await(
@@ -330,7 +330,7 @@ func TestMissingDependency(t *testing.T) {
330330
})
331331
}
332332

333-
func TestAdHocPackagesIssue_36951(t *testing.T) {
333+
func TestAdHocPackages_Issue36951(t *testing.T) {
334334
const adHoc = `
335335
-- b/b.go --
336336
package b
@@ -345,7 +345,7 @@ func Hello() {
345345
})
346346
}
347347

348-
func TestNoGOPATHIssue_37984(t *testing.T) {
348+
func TestNoGOPATH_Issue37984(t *testing.T) {
349349
const missingImport = `
350350
-- main.go --
351351
package main
@@ -362,3 +362,24 @@ func _() {
362362
}
363363
}, WithEnv("GOPATH="))
364364
}
365+
366+
func TestEqualInEnv_Issue38669(t *testing.T) {
367+
const missingImport = `
368+
-- go.mod --
369+
module mod.com
370+
371+
-- main.go --
372+
package main
373+
374+
var _ = x.X
375+
-- x/x.go --
376+
package x
377+
378+
var X = 0
379+
`
380+
runner.Run(t, missingImport, func(t *testing.T, env *Env) {
381+
env.OpenFile("main.go")
382+
env.OrganizeImports("main.go")
383+
env.Await(EmptyDiagnostics("main.go"))
384+
}, WithEnv("GOFLAGS=-tags=foo"))
385+
}

0 commit comments

Comments
 (0)