diff --git a/vscode-client/package.json b/vscode-client/package.json index bf1a1e369..72e5e119b 100644 --- a/vscode-client/package.json +++ b/vscode-client/package.json @@ -35,6 +35,8 @@ "postinstall": "node ./node_modules/vscode/bin/install" }, "dependencies": { + "@types/semver-compare": "^1.0.0", + "semver-compare": "^1.0.0", "vscode": "^1.1.14", "vscode-languageclient": "^4.1.3" } diff --git a/vscode-client/src/extension.ts b/vscode-client/src/extension.ts index 4014de86e..b8833e26f 100644 --- a/vscode-client/src/extension.ts +++ b/vscode-client/src/extension.ts @@ -1,5 +1,6 @@ 'use strict' +import semverCompare = require('semver-compare') import { ExtensionContext, window, workspace } from 'vscode' import { LanguageClient, @@ -7,12 +8,20 @@ import { ServerOptions, } from 'vscode-languageclient' -import { getServerCommand } from './util' +import { getServerInfo } from './util' -export function activate(context: ExtensionContext) { - getServerCommand() - .then(command => start(context, command)) - .catch(_ => handleMissingExecutable()) +const MINIMUM_SERVER_VERSION = '1.1.2' + +export async function activate(context: ExtensionContext) { + try { + const { command, version } = await getServerInfo() + if (semverCompare(version, MINIMUM_SERVER_VERSION) === -1) { + return handleOutdatedExecutable() + } + start(context, command) + } catch (error) { + handleMissingExecutable() + } } function start(context: ExtensionContext, command: string) { @@ -53,11 +62,12 @@ function start(context: ExtensionContext, command: string) { context.subscriptions.push(disposable) } -function handleMissingExecutable() { - const message = `Can't find bash-language-server on your PATH. Please install it using npm i -g bash-language-server.` - const options = { - modal: false, - } +function handleOutdatedExecutable() { + const message = `Outdated bash server. Please upgrade by running "npm i -g bash-language-server".` + window.showErrorMessage(message, { modal: false }) +} - window.showErrorMessage(message, options) +function handleMissingExecutable() { + const message = `Can't find bash-language-server on your PATH. Please install it using "npm i -g bash-language-server".` + window.showErrorMessage(message, { modal: false }) } diff --git a/vscode-client/src/util.ts b/vscode-client/src/util.ts index 3709e1a02..a5525743b 100644 --- a/vscode-client/src/util.ts +++ b/vscode-client/src/util.ts @@ -17,18 +17,21 @@ function getBasePath(): Promise { }) } -export async function getServerCommand(): Promise { +type ServerInfo = { command: string; version: string } + +export async function getServerInfo(): Promise { const basePath = await getBasePath() const name = isWindows() ? 'bash-language-server.cmd' : 'bash-language-server' const command = Path.join(basePath, name) - return new Promise((resolve, reject) => { - // Simply check if the bash-language-server is installed. - execFile(command, ['-v'], err => { + return new Promise((resolve, reject) => { + execFile(command, ['-v'], (err, stdout) => { if (err) { reject(err) } - resolve(command) + const versionMatch = stdout.match(/\d+[.]\d+[.]\d+/) + const version = (versionMatch && versionMatch[0]) || '0.0.0' + resolve({ command, version }) }) }) } diff --git a/vscode-client/yarn.lock b/vscode-client/yarn.lock index 256667355..722d59ed6 100644 --- a/vscode-client/yarn.lock +++ b/vscode-client/yarn.lock @@ -2,6 +2,10 @@ # yarn lockfile v1 +"@types/semver-compare@^1.0.0": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@types/semver-compare/-/semver-compare-1.0.0.tgz#b6e39ec7d0d3f03e5e74ec654bfbbfbc3bbe1b19" + ajv@^5.1.0: version "5.5.2" resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.5.2.tgz#73b5eeca3fab653e3d3f9422b341ad42205dc965" @@ -1377,6 +1381,10 @@ safe-buffer@^5.0.1, safe-buffer@^5.1.1, safe-buffer@~5.1.0, safe-buffer@~5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853" +semver-compare@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/semver-compare/-/semver-compare-1.0.0.tgz#0dee216a1c941ab37e9efb1788f6afc5ff5537fc" + semver@^5.4.1: version "5.5.0" resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.0.tgz#dc4bbc7a6ca9d916dee5d43516f0092b58f7b8ab"