| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
package goversion |
| 7 |
|
| 8 |
import ( |
| 9 |
"fmt" |
| 10 |
"strings" |
| 11 |
) |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
type Support struct { |
| 17 |
|
| 18 |
GoVersion int |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
DeprecatedVersion string |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
InstallGoplsVersion string |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
var Supported = []Support{ |
| 38 |
{12, "", "v0.7.5"}, |
| 39 |
{15, "", "v0.9.5"}, |
| 40 |
{16, "", "v0.11.0"}, |
| 41 |
{17, "", "v0.11.0"}, |
| 42 |
{18, "", "v0.14.2"}, |
| 43 |
{19, "v0.17.0", "v0.15.3"}, |
| 44 |
{20, "v0.17.0", "v0.15.3"}, |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
func OldestSupported() int { |
| 52 |
return Supported[len(Supported)-1].GoVersion + 1 |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
func Message(goVersion int, fromBuild bool) (string, bool) { |
| 65 |
if goVersion < 0 { |
| 66 |
return "", false |
| 67 |
} |
| 68 |
|
| 69 |
for _, v := range Supported { |
| 70 |
if goVersion <= v.GoVersion { |
| 71 |
var msgBuilder strings.Builder |
| 72 |
|
| 73 |
isError := true |
| 74 |
if fromBuild { |
| 75 |
fmt.Fprintf(&msgBuilder, "Gopls was built with Go version 1.%d", goVersion) |
| 76 |
} else { |
| 77 |
fmt.Fprintf(&msgBuilder, "Found Go version 1.%d", goVersion) |
| 78 |
} |
| 79 |
if v.DeprecatedVersion != "" { |
| 80 |
|
| 81 |
fmt.Fprintf(&msgBuilder, ", which will be unsupported by gopls %s. ", v.DeprecatedVersion) |
| 82 |
isError = false |
| 83 |
} else { |
| 84 |
fmt.Fprint(&msgBuilder, ", which is not supported by this version of gopls. ") |
| 85 |
} |
| 86 |
fmt.Fprintf(&msgBuilder, "Please upgrade to Go 1.%d or later and reinstall gopls. ", OldestSupported()) |
| 87 |
fmt.Fprintf(&msgBuilder, "If you can't upgrade and want this message to go away, please install gopls %s. ", v.InstallGoplsVersion) |
| 88 |
fmt.Fprint(&msgBuilder, "See https://go.dev/s/gopls-support-policy for more details.") |
| 89 |
|
| 90 |
return msgBuilder.String(), isError |
| 91 |
} |
| 92 |
} |
| 93 |
return "", false |
| 94 |
} |