diff --git a/gopls/internal/regtest/workspace/workspace_test.go b/gopls/internal/regtest/workspace/workspace_test.go index 11ab507708..666f023ace 100644 --- a/gopls/internal/regtest/workspace/workspace_test.go +++ b/gopls/internal/regtest/workspace/workspace_test.go @@ -855,6 +855,7 @@ func TestWorkspaceDirAccess(t *testing.T) { -- moda/a/go.mod -- module a.com +go 1.15 -- moda/a/a.go -- package main @@ -863,6 +864,8 @@ func main() { } -- modb/go.mod -- module b.com + +go 1.16 -- modb/b/b.go -- package main @@ -892,7 +895,7 @@ func main() { t.Fatalf("reading expected workspace modfile: %v", err) } got := string(gotb) - for _, want := range []string{"a.com v1.9999999.0-goplsworkspace", "b.com v1.9999999.0-goplsworkspace"} { + for _, want := range []string{"go 1.16", "a.com v1.9999999.0-goplsworkspace", "b.com v1.9999999.0-goplsworkspace"} { if !strings.Contains(got, want) { // want before got here, since the go.mod is multi-line t.Fatalf("workspace go.mod missing %q. got:\n%s", want, got) diff --git a/internal/lsp/cache/snapshot.go b/internal/lsp/cache/snapshot.go index 486a2287cd..51b00d5b61 100644 --- a/internal/lsp/cache/snapshot.go +++ b/internal/lsp/cache/snapshot.go @@ -2290,7 +2290,8 @@ func buildWorkspaceModFile(ctx context.Context, modFiles map[span.URI]struct{}, if file == nil || parsed.Module == nil { return nil, fmt.Errorf("no module declaration for %s", modURI) } - if parsed.Go != nil && semver.Compare(goVersion, parsed.Go.Version) < 0 { + // Prepend "v" to go versions to make them valid semver. + if parsed.Go != nil && semver.Compare("v"+goVersion, "v"+parsed.Go.Version) < 0 { goVersion = parsed.Go.Version } path := parsed.Module.Mod.Path