Skip to content

Commit 5ff5cbb

Browse files
committed
gopls: deprecate support for Go 1.16 and 1.17, update warnings
Update our version table to reflect the existence of [email protected], and deprecate support for Go 1.16 and 1.17. Fixes golang/go#60341 Change-Id: Id061aafacb4099f57d464b5a7453bc1f98fda80a Reviewed-on: https://go-review.googlesource.com/c/tools/+/496881 Run-TryBot: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
1 parent e6fd7f4 commit 5ff5cbb

File tree

3 files changed

+44
-15
lines changed

3 files changed

+44
-15
lines changed

gopls/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ version of gopls.
9393
| ----------- | --------------------------------------------------- |
9494
| Go 1.12 | [[email protected]](https://github.com/golang/tools/releases/tag/gopls%2Fv0.7.5) |
9595
| Go 1.15 | [[email protected]](https://github.com/golang/tools/releases/tag/gopls%2Fv0.9.5) |
96+
| Go 1.17 | [[email protected]](https://github.com/golang/tools/releases/tag/gopls%2Fv0.11.0) |
9697

9798
Our extended support is enforced via [continuous integration with older Go
9899
versions](doc/contributing.md#ci). This legacy Go CI may not block releases:

gopls/internal/lsp/general.go

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"context"
99
"encoding/json"
1010
"fmt"
11+
"go/build"
1112
"log"
1213
"os"
1314
"path"
@@ -239,14 +240,16 @@ func (s *Server) initialized(ctx context.Context, params *protocol.InitializedPa
239240

240241
// GoVersionTable maps Go versions to the gopls version in which support will
241242
// be deprecated, and the final gopls version supporting them without warnings.
242-
// Keep this in sync with gopls/README.md
243+
// Keep this in sync with gopls/README.md.
243244
//
244245
// Must be sorted in ascending order of Go version.
245246
//
246247
// Mutable for testing.
247248
var GoVersionTable = []GoVersionSupport{
248249
{12, "", "v0.7.5"},
249-
{15, "v0.11.0", "v0.9.5"},
250+
{15, "", "v0.9.5"},
251+
{16, "v0.13.0", "v0.11.0"},
252+
{17, "v0.13.0", "v0.11.0"},
250253
}
251254

252255
// GoVersionSupport holds information about end-of-life Go version support.
@@ -262,11 +265,13 @@ func OldestSupportedGoVersion() int {
262265
return GoVersionTable[len(GoVersionTable)-1].GoVersion + 1
263266
}
264267

265-
// versionMessage returns the warning/error message to display if the user is
266-
// on the given Go version, if any. The goVersion variable is the X in Go 1.X.
268+
// versionMessage returns the warning/error message to display if the user has
269+
// the given Go version, if any. The goVersion variable is the X in Go 1.X. If
270+
// fromBuild is set, the Go version is the version used to build gopls.
271+
// Otherwise, it is the go command version.
267272
//
268273
// If goVersion is invalid (< 0), it returns "", 0.
269-
func versionMessage(goVersion int) (string, protocol.MessageType) {
274+
func versionMessage(goVersion int, fromBuild bool) (string, protocol.MessageType) {
270275
if goVersion < 0 {
271276
return "", 0
272277
}
@@ -276,7 +281,11 @@ func versionMessage(goVersion int) (string, protocol.MessageType) {
276281
var msgBuilder strings.Builder
277282

278283
mType := protocol.Error
279-
fmt.Fprintf(&msgBuilder, "Found Go version 1.%d", goVersion)
284+
if fromBuild {
285+
fmt.Fprintf(&msgBuilder, "Gopls was built with Go version 1.%d", goVersion)
286+
} else {
287+
fmt.Fprintf(&msgBuilder, "Found Go version 1.%d", goVersion)
288+
}
280289
if v.DeprecatedVersion != "" {
281290
// not deprecated yet, just a warning
282291
fmt.Fprintf(&msgBuilder, ", which will be unsupported by gopls %s. ", v.DeprecatedVersion)
@@ -299,22 +308,37 @@ func versionMessage(goVersion int) (string, protocol.MessageType) {
299308
//
300309
// It should be called after views change.
301310
func (s *Server) checkViewGoVersions() {
302-
oldestVersion := -1
311+
oldestVersion, fromBuild := go1Point(), true
303312
for _, view := range s.session.Views() {
304313
viewVersion := view.GoVersion()
305314
if oldestVersion == -1 || viewVersion < oldestVersion {
306-
oldestVersion = viewVersion
315+
oldestVersion, fromBuild = viewVersion, false
307316
}
308317
}
309318

310-
if msg, mType := versionMessage(oldestVersion); msg != "" {
319+
if msg, mType := versionMessage(oldestVersion, fromBuild); msg != "" {
311320
s.eventuallyShowMessage(context.Background(), &protocol.ShowMessageParams{
312321
Type: mType,
313322
Message: msg,
314323
})
315324
}
316325
}
317326

327+
// go1Point returns the x in Go 1.x. If an error occurs extracting the go
328+
// version, it returns -1.
329+
//
330+
// Copied from the testenv package.
331+
func go1Point() int {
332+
for i := len(build.Default.ReleaseTags) - 1; i >= 0; i-- {
333+
var version int
334+
if _, err := fmt.Sscanf(build.Default.ReleaseTags[i], "go1.%d", &version); err != nil {
335+
continue
336+
}
337+
return version
338+
}
339+
return -1
340+
}
341+
318342
func (s *Server) addFolders(ctx context.Context, folders []protocol.WorkspaceFolder) error {
319343
originalViews := len(s.session.Views())
320344
viewErrors := make(map[span.URI]error)

gopls/internal/lsp/general_test.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,22 @@ import (
1414
func TestVersionMessage(t *testing.T) {
1515
tests := []struct {
1616
goVersion int
17+
fromBuild bool
1718
wantContains []string // string fragments that we expect to see
1819
wantType protocol.MessageType
1920
}{
20-
{-1, nil, 0},
21-
{12, []string{"1.12", "not supported", "upgrade to Go 1.16", "install gopls v0.7.5"}, protocol.Error},
22-
{13, []string{"1.13", "will be unsupported by gopls v0.11.0", "upgrade to Go 1.16", "install gopls v0.9.5"}, protocol.Warning},
23-
{15, []string{"1.15", "will be unsupported by gopls v0.11.0", "upgrade to Go 1.16", "install gopls v0.9.5"}, protocol.Warning},
24-
{16, nil, 0},
21+
{-1, false, nil, 0},
22+
{12, false, []string{"1.12", "not supported", "upgrade to Go 1.18", "install gopls v0.7.5"}, protocol.Error},
23+
{13, false, []string{"1.13", "not supported", "upgrade to Go 1.18", "install gopls v0.9.5"}, protocol.Error},
24+
{15, false, []string{"1.15", "not supported", "upgrade to Go 1.18", "install gopls v0.9.5"}, protocol.Error},
25+
{15, true, []string{"Gopls was built with Go version 1.15", "not supported", "upgrade to Go 1.18", "install gopls v0.9.5"}, protocol.Error},
26+
{16, false, []string{"1.16", "will be unsupported by gopls v0.13.0", "upgrade to Go 1.18", "install gopls v0.11.0"}, protocol.Warning},
27+
{17, false, []string{"1.17", "will be unsupported by gopls v0.13.0", "upgrade to Go 1.18", "install gopls v0.11.0"}, protocol.Warning},
28+
{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"}, protocol.Warning},
2529
}
2630

2731
for _, test := range tests {
28-
gotMsg, gotType := versionMessage(test.goVersion)
32+
gotMsg, gotType := versionMessage(test.goVersion, test.fromBuild)
2933

3034
if len(test.wantContains) == 0 && gotMsg != "" {
3135
t.Errorf("versionMessage(%d) = %q, want \"\"", test.goVersion, gotMsg)

0 commit comments

Comments
 (0)