Skip to content

Commit 8b5db74

Browse files
committed
Clean up the utility function for getting server command
1 parent a3d8ce7 commit 8b5db74

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

vscode-client/src/extension.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ import {
77
ServerOptions,
88
} from 'vscode-languageclient'
99

10-
import * as Util from './util'
10+
import { getServerCommand } from './util'
1111

1212
export function activate(context: ExtensionContext) {
13-
Util.base()
14-
.then(base => Util.executable(base))
13+
getServerCommand()
1514
.then(command => start(context, command))
1615
.catch(_ => handleMissingExecutable())
1716
}

vscode-client/src/util.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
import * as Process from 'child_process'
1+
import { execFile } from 'child_process'
22
import * as Path from 'path'
33

44
function isWindows() {
55
return process.platform === 'win32'
66
}
77

8-
/**
9-
*
10-
*/
11-
export function base(): Promise<string> {
8+
function getBasePath(): Promise<string> {
129
return new Promise((resolve, reject) => {
13-
Process.execFile('npm', ['bin', '-g'], (err, stdout) => {
10+
execFile('npm', ['bin', '-g'], (err, stdout) => {
1411
if (err) {
1512
reject(err)
1613
}
@@ -20,12 +17,14 @@ export function base(): Promise<string> {
2017
})
2118
}
2219

23-
export function executable(basePath: string): Promise<string> {
20+
export async function getServerCommand(): Promise<string> {
21+
const basePath = await getBasePath()
2422
const name = isWindows() ? 'bash-language-server.cmd' : 'bash-language-server'
2523
const command = Path.join(basePath, name)
26-
return new Promise((resolve, reject) => {
24+
25+
return new Promise<string>((resolve, reject) => {
2726
// Simply check if the bash-language-server is installed.
28-
Process.execFile(command, ['-v'], err => {
27+
execFile(command, ['-v'], err => {
2928
if (err) {
3029
reject(err)
3130
}

0 commit comments

Comments
 (0)