Skip to content

Commit

Permalink
gopls/internal/util/goversion: warn about EOL for Go 1.18
Browse files Browse the repository at this point in the history
Gopls v0.15.0 will be the final gopls version to support Go 1.18, so
include a warning, as is our practice.

Fixes golang/go#64407

Change-Id: I215631420c05ad1922312f1b1009d15577ddb01e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/549115
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
findleyr authored and gopherbot committed Dec 12, 2023
1 parent bc9cd15 commit 8bd7553
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 12 deletions.
22 changes: 17 additions & 5 deletions gopls/internal/util/goversion/goversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@ import (
//
// Exposed for testing.
type Support struct {
GoVersion int
DeprecatedVersion string // if unset, the version is already deprecated
// GoVersion is the Go version to which these settings relate.
GoVersion int

// DeprecatedVersion is the first version of gopls that no longer supports
// this Go version.
//
// If unset, the version is already deprecated.
DeprecatedVersion string

// InstallGoplsVersion is the latest gopls version that supports this Go
// version without warnings.
InstallGoplsVersion string
}

Expand All @@ -29,12 +38,15 @@ type Support struct {
var Supported = []Support{
{12, "", "v0.7.5"},
{15, "", "v0.9.5"},
{16, "v0.13.0", "v0.11.0"},
{17, "v0.13.0", "v0.11.0"},
{16, "", "v0.11.0"},
{17, "", "v0.11.0"},
{18, "v0.16.0", "v0.14.2"},
}

// OldestSupported is the last X in Go 1.X that this version of gopls
// supports.
// supports without warnings.
//
// Exported for testing.
func OldestSupported() int {
return Supported[len(Supported)-1].GoVersion + 1
}
Expand Down
42 changes: 35 additions & 7 deletions gopls/internal/util/goversion/goversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,55 @@
package goversion_test

import (
"fmt"
"strings"
"testing"

"golang.org/x/tools/gopls/internal/util/goversion"
)

func TestMessage(t *testing.T) {
// Note(rfindley): this test is a change detector, as it must be updated
// whenever we deprecate a version.
//
// However, I chose to leave it as is since it gives us confidence in error
// messages served for Go versions that we no longer support (and therefore
// no longer run in CI).
type test struct {
goVersion int
fromBuild bool
wantContains []string // string fragments that we expect to see
wantIsError bool // an error, not a mere warning
}

deprecated := func(goVersion int, lastVersion string) test {
return test{
goVersion: goVersion,
fromBuild: false,
wantContains: []string{
fmt.Sprintf("Found Go version 1.%d", goVersion),
"not supported",
fmt.Sprintf("upgrade to Go 1.%d", goversion.OldestSupported()),
fmt.Sprintf("install gopls %s", lastVersion),
},
wantIsError: true,
}
}

tests := []struct {
goVersion int
fromBuild bool
wantContains []string // string fragments that we expect to see
wantIsError bool // an error, not a mere warning
}{
{-1, false, nil, false},
{12, false, []string{"1.12", "not supported", "upgrade to Go 1.18", "install gopls v0.7.5"}, true},
{13, false, []string{"1.13", "not supported", "upgrade to Go 1.18", "install gopls v0.9.5"}, true},
{15, false, []string{"1.15", "not supported", "upgrade to Go 1.18", "install gopls v0.9.5"}, true},
{15, true, []string{"Gopls was built with Go version 1.15", "not supported", "upgrade to Go 1.18", "install gopls v0.9.5"}, true},
{16, false, []string{"1.16", "will be unsupported by gopls v0.13.0", "upgrade to Go 1.18", "install gopls v0.11.0"}, false},
{17, false, []string{"1.17", "will be unsupported by gopls v0.13.0", "upgrade to Go 1.18", "install gopls v0.11.0"}, false},
{17, true, []string{"Gopls was built with Go version 1.17", "will be unsupported by gopls v0.13.0", "upgrade to Go 1.18", "install gopls v0.11.0"}, false},
deprecated(12, "v0.7.5"),
deprecated(13, "v0.9.5"),
deprecated(15, "v0.9.5"),
deprecated(16, "v0.11.0"),
deprecated(17, "v0.11.0"),
{18, false, []string{"Found Go version 1.18", "unsupported by gopls v0.16.0", "upgrade to Go 1.19", "install gopls v0.14.2"}, false},
{18, true, []string{"Gopls was built with Go version 1.18", "unsupported by gopls v0.16.0", "upgrade to Go 1.19", "install gopls v0.14.2"}, false},
}

for _, test := range tests {
Expand Down

0 comments on commit 8bd7553

Please sign in to comment.