Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions vscode-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
32 changes: 21 additions & 11 deletions vscode-client/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
'use strict'

import semverCompare = require('semver-compare')
import { ExtensionContext, window, workspace } from 'vscode'
import {
LanguageClient,
LanguageClientOptions,
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) {
Expand Down Expand Up @@ -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 })
}
13 changes: 8 additions & 5 deletions vscode-client/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,21 @@ function getBasePath(): Promise<string> {
})
}

export async function getServerCommand(): Promise<string> {
type ServerInfo = { command: string; version: string }

export async function getServerInfo(): Promise<ServerInfo> {
const basePath = await getBasePath()
const name = isWindows() ? 'bash-language-server.cmd' : 'bash-language-server'
const command = Path.join(basePath, name)

return new Promise<string>((resolve, reject) => {
// Simply check if the bash-language-server is installed.
execFile(command, ['-v'], err => {
return new Promise<ServerInfo>((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 })
})
})
}
8 changes: 8 additions & 0 deletions vscode-client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down