src/util: adjust go dev version regex
During the go1.17 dev cycle, the dev version string format was
changed to include the go base version.
See https://github.com/golang/go/issues/44960.
Recognize the new format.
We can improve the version comparison logic utilizing this further
but this does not utilize it yet.
Fixes golang/vscode-go#1464
Change-Id: If2084ad9d86cb8b4c0f59c36b1347c0188452189
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/315853
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
diff --git a/src/goEnvironmentStatus.ts b/src/goEnvironmentStatus.ts
index 135eed1..b236e16 100644
--- a/src/goEnvironmentStatus.ts
+++ b/src/goEnvironmentStatus.ts
@@ -428,8 +428,8 @@
const versionStr = version.format(true);
const versionWords = versionStr.split(' ');
if (versionWords.length > 1 && versionWords[0] === 'devel') {
- // Go devel +hash
- return `Go ${versionWords[1]}`;
+ // go devel +hash or go devel go1.17-hash
+ return versionWords[1].startsWith('go') ? `Go ${versionWords[1].slice(2)}` : `Go ${versionWords[1]}`;
} else {
return `Go ${versionWords[0]}`;
}
diff --git a/src/util.ts b/src/util.ts
index 038ac7b..00fe941 100644
--- a/src/util.ts
+++ b/src/util.ts
@@ -92,11 +92,11 @@
public svString?: string;
public isDevel?: boolean;
- private commit?: string;
+ private devVersion?: string;
constructor(public binaryPath: string, public version: string) {
const matchesRelease = /^go version go(\d\.\d+\S*)\s+/.exec(version);
- const matchesDevel = /go version devel \+(.[a-zA-Z0-9]+).*/.exec(version);
+ const matchesDevel = /^go version devel (\S+)\s+/.exec(version);
if (matchesRelease) {
// note: semver.parse does not work with Go version string like go1.14.
const sv = semver.coerce(matchesRelease[1]);
@@ -106,7 +106,7 @@
}
} else if (matchesDevel) {
this.isDevel = true;
- this.commit = matchesDevel[1];
+ this.devVersion = matchesDevel[1];
}
}
@@ -122,7 +122,7 @@
return this.sv.format();
}
if (this.isDevel) {
- return `devel +${this.commit}`;
+ return `devel ${this.devVersion}`;
}
return 'unknown';
}
diff --git a/test/integration/utils.test.ts b/test/integration/utils.test.ts
index 6620157..b9102b6 100644
--- a/test/integration/utils.test.ts
+++ b/test/integration/utils.test.ts
@@ -35,6 +35,12 @@
'devel +a295d59d',
true
],
+ [
+ 'go version devel go1.17-756fd56bbf Thu Apr 29 01:15:34 2021 +0000 darwin/amd64',
+ 'devel go1.17-756fd56bbf',
+ 'devel go1.17-756fd56bbf',
+ true
+ ],
['go version go1.14 darwin/amd64', '1.14.0', '1.14', true],
['go version go1.14.1 linux/amd64', '1.14.1', '1.14.1', true],
['go version go1.15rc1 darwin/amd64', '1.15.0', '1.15rc1', true],