From 8bd7553f7c595ecbf244343302e1bfe890f1f947 Mon Sep 17 00:00:00 2001 From: Rob Findley Date: Tue, 12 Dec 2023 10:14:55 -0500 Subject: [PATCH] gopls/internal/util/goversion: warn about EOL for Go 1.18 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 Auto-Submit: Robert Findley LUCI-TryBot-Result: Go LUCI --- gopls/internal/util/goversion/goversion.go | 22 +++++++--- .../internal/util/goversion/goversion_test.go | 42 +++++++++++++++---- 2 files changed, 52 insertions(+), 12 deletions(-) diff --git a/gopls/internal/util/goversion/goversion.go b/gopls/internal/util/goversion/goversion.go index 0aa56f895bc..5b849b22b85 100644 --- a/gopls/internal/util/goversion/goversion.go +++ b/gopls/internal/util/goversion/goversion.go @@ -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 } @@ -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 } diff --git a/gopls/internal/util/goversion/goversion_test.go b/gopls/internal/util/goversion/goversion_test.go index 5ee596f9a29..f48ef5008c8 100644 --- a/gopls/internal/util/goversion/goversion_test.go +++ b/gopls/internal/util/goversion/goversion_test.go @@ -5,6 +5,7 @@ package goversion_test import ( + "fmt" "strings" "testing" @@ -12,6 +13,33 @@ import ( ) 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 @@ -19,13 +47,13 @@ func TestMessage(t *testing.T) { 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 {