@@ -226,11 +226,54 @@ func (s *Server) initialized(ctx context.Context, params *protocol.InitializedPa
226
226
return nil
227
227
}
228
228
229
- // OldestSupportedGoVersion is the last X in Go 1.X that we support.
229
+ // GoVersionTable maps Go versions to the gopls version in which support will
230
+ // be deprecated, and the final gopls version supporting them without warnings.
231
+ // Keep this in sync with gopls/README.md
230
232
//
231
- // Mutable for testing, since we won't otherwise run CI on unsupported Go
232
- // versions.
233
- var OldestSupportedGoVersion = 16
233
+ // Must be sorted in ascending order of Go version.
234
+ //
235
+ // Mutable for testing.
236
+ var GoVersionTable = []GoVersionSupport {
237
+ {12 , "" , "v0.7.5" },
238
+ {15 , "v0.11.0" , "v0.9.5" },
239
+ }
240
+
241
+ // GoVersionSupport holds information about end-of-life Go version support.
242
+ type GoVersionSupport struct {
243
+ GoVersion int
244
+ DeprecatedVersion string // if unset, the version is already deprecated
245
+ InstallGoplsVersion string
246
+ }
247
+
248
+ // OldestSupportedGoVersion is the last X in Go 1.X that this version of gopls
249
+ // supports.
250
+ func OldestSupportedGoVersion () int {
251
+ return GoVersionTable [len (GoVersionTable )- 1 ].GoVersion + 1
252
+ }
253
+
254
+ func versionMessage (oldestVersion int ) (string , protocol.MessageType ) {
255
+ for _ , v := range GoVersionTable {
256
+ if oldestVersion <= v .GoVersion {
257
+ var msgBuilder strings.Builder
258
+
259
+ mType := protocol .Error
260
+ fmt .Fprintf (& msgBuilder , "Found Go version 1.%d" , oldestVersion )
261
+ if v .DeprecatedVersion != "" {
262
+ // not deprecated yet, just a warning
263
+ fmt .Fprintf (& msgBuilder , ", which will be unsupported by gopls %s. " , v .DeprecatedVersion )
264
+ mType = protocol .Warning
265
+ } else {
266
+ fmt .Fprint (& msgBuilder , ", which is not supported by this version of gopls. " )
267
+ }
268
+ fmt .Fprintf (& msgBuilder , "Please upgrade to Go 1.%d or later and reinstall gopls. " , OldestSupportedGoVersion ())
269
+ fmt .Fprintf (& msgBuilder , "If you can't upgrade and want this message to go away, please install gopls %s. " , v .InstallGoplsVersion )
270
+ fmt .Fprint (& msgBuilder , "See https://go.dev/s/gopls-support-policy for more details." )
271
+
272
+ return msgBuilder .String (), mType
273
+ }
274
+ }
275
+ return "" , 0
276
+ }
234
277
235
278
// checkViewGoVersions checks whether any Go version used by a view is too old,
236
279
// raising a showMessage notification if so.
@@ -245,10 +288,9 @@ func (s *Server) checkViewGoVersions() {
245
288
}
246
289
}
247
290
248
- if oldestVersion >= 0 && oldestVersion < OldestSupportedGoVersion {
249
- msg := fmt .Sprintf ("Found Go version 1.%d, which is unsupported. Please upgrade to Go 1.%d or later." , oldestVersion , OldestSupportedGoVersion )
291
+ if msg , mType := versionMessage (oldestVersion ); msg != "" {
250
292
s .eventuallyShowMessage (context .Background (), & protocol.ShowMessageParams {
251
- Type : protocol . Error ,
293
+ Type : mType ,
252
294
Message : msg ,
253
295
})
254
296
}
0 commit comments