diff --git a/src/commands.ts b/src/commands.ts index f809754..24ae5ba 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -15,7 +15,7 @@ export async function version(): Promise { } export async function installGopls(client: LanguageClient): Promise { - await installGoBin(GOPLS, true) + await installGoBin(GOPLS, true, goplsVersion) if (client.needsStop()) { await client.stop() @@ -79,7 +79,7 @@ async function pkgVersion(): Promise { async function goplsVersion(): Promise { const [, versionOut] = await runGoTool("gopls", ["version"]) - const m = versionOut.trim().match(/^golang\.org\/x\/tools\/gopls (v?\d+\.\d+\.\d+)/) + const m = versionOut.trim().match(/\s{4}golang\.org\/x\/tools\/gopls@(v?\d+\.\d+\.\d+) .*/) if (m && isValidVersion(m[1])) { return m[1].replace(/^v/, '') } diff --git a/src/utils/tools.ts b/src/utils/tools.ts index 3bf3579..d8298f7 100644 --- a/src/utils/tools.ts +++ b/src/utils/tools.ts @@ -12,7 +12,11 @@ const isWin = process.platform === 'win32' //////////////////////////////////////////////////////////////////////////////// -export async function installGoBin(source: string, force = false): Promise { +interface GetVersionFunction { + (): string | Promise +} + +export async function installGoBin(source: string, force = false, getVersion?: GetVersionFunction): Promise { const name = goBinName(source) if (!force && await goBinExists(name)) { @@ -26,7 +30,9 @@ export async function installGoBin(source: string, force = false): Promise