Skip to content

Commit

Permalink
Fix gopls version check
Browse files Browse the repository at this point in the history
  • Loading branch information
josa42 committed Dec 29, 2020
1 parent 1399f80 commit 3a50779
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function version(): Promise<void> {
}

export async function installGopls(client: LanguageClient): Promise<void> {
await installGoBin(GOPLS, true)
await installGoBin(GOPLS, true, goplsVersion)

if (client.needsStop()) {
await client.stop()
Expand Down Expand Up @@ -79,7 +79,7 @@ async function pkgVersion(): Promise<string> {
async function goplsVersion(): Promise<string> {
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/, '')
}
Expand Down
10 changes: 8 additions & 2 deletions src/utils/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ const isWin = process.platform === 'win32'

////////////////////////////////////////////////////////////////////////////////

export async function installGoBin(source: string, force = false): Promise<boolean> {
interface GetVersionFunction {
(): string | Promise<string>
}

export async function installGoBin(source: string, force = false, getVersion?: GetVersionFunction): Promise<boolean> {
const name = goBinName(source)

if (!force && await goBinExists(name)) {
Expand All @@ -26,7 +30,9 @@ export async function installGoBin(source: string, force = false): Promise<boole
const success = await goRun(`get ${source}@latest`) && await goBinExists(name)

if (success) {
window.showMessage(`Installed '${name}'`)
const vname = getVersion ? `${name}@${await getVersion()}` : name

window.showMessage(`Installed '${vname}'`)
} else {
window.showMessage(`Failed to install '${name}'`, 'error')
}
Expand Down

0 comments on commit 3a50779

Please sign in to comment.