Skip to content

Commit

Permalink
goLanguageServer: use semver.parse instead of semver.coerce
Browse files Browse the repository at this point in the history
Didn't spend enough time investigating why this is necessary, but this
fixes the handling of pre-releases. Noticed that it wasn't suggesting an
update for a pre-release for me (when I already had a pre-release
installed).

Change-Id: I8d4bd24a922d593eb4e214447534fccba10c4fd7
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/239984
Run-TryBot: Rebecca Stambler <[email protected]>
Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
  • Loading branch information
stamblerre committed Jun 25, 2020
1 parent 057186f commit ebf7f83
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/goLanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,10 @@ export async function shouldUpdateLanguageServer(

// If the user's version does not contain a timestamp,
// default to a semver comparison of the two versions.
const usersVersionSemver = semver.coerce(usersVersion, { includePrerelease: true, loose: true });
const usersVersionSemver = semver.parse(usersVersion, {
includePrerelease: true,
loose: true,
});
return semver.lt(usersVersionSemver, latestVersion) ? latestVersion : null;
}

Expand Down Expand Up @@ -678,6 +681,7 @@ async function goProxyRequest(tool: Tool, endpoint: string): Promise<any> {
throwResponseError: true
});
} catch (e) {
console.log(`Error sending request to ${proxy}: ${e}`);
return null;
}
return data;
Expand Down
2 changes: 1 addition & 1 deletion test/gopls/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ suite('gopls update tests', () => {
test('prompt for update', async () => {
const tool = getTool('gopls');

const toSemver = (v: string) => semver.coerce(v, {includePrerelease: true, loose: true});
const toSemver = (v: string) => semver.parse(v, { includePrerelease: true, loose: true });

// Fake data stubbed functions will serve.
const latestVersion = toSemver('0.4.1');
Expand Down

0 comments on commit ebf7f83

Please sign in to comment.