Skip to content

Commit

Permalink
[code] Fix the env $PATH when the go lsp spawned in windows (#45011)
Browse files Browse the repository at this point in the history
The env name 'PATH' is not applied on windows system.
  • Loading branch information
Henry Wong authored Sep 9, 2019
1 parent 3cfe728 commit 17f74a7
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions x-pack/legacy/plugins/code/server/lsp/go_launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,13 @@ export class GoServerLauncher extends AbstractLauncher {
throw new Error('Cannot find executable go language server');
}

let envPath = process.env.PATH;
const goToolchain = await this.getBundledGoToolchain(installationPath, log);
if (!goToolchain) {
throw new Error('Cannot find go toolchain in bundle installation');
}
// Construct $GOROOT from the bundled go toolchain.
const goRoot = goToolchain;
const goHome = path.resolve(goToolchain, 'bin');
envPath = process.platform === 'win32' ? envPath + ';' + goHome : envPath + ':' + goHome;
// Construct $GOPATH under 'kibana/data/code'.
const goPath = this.options.goPath;
if (!fs.existsSync(goPath)) {
Expand All @@ -104,17 +102,18 @@ export class GoServerLauncher extends AbstractLauncher {
const goCache = path.resolve(goPath, '.cache');
const params: string[] = ['-port=' + port.toString()];
const golsp = path.resolve(installationPath, launchersFound[0]);
const env = Object.create(process.env);
env.PATH = process.platform === 'win32' ? goHome + ';' + env.PATH : goHome + ':' + env.PATH;
const p = spawn(golsp, params, {
detached: false,
stdio: 'pipe',
env: {
...process.env,
...env,
CLIENT_HOST: '127.0.0.1',
CLIENT_PORT: port.toString(),
GOROOT: goRoot,
GOPATH: goPath,
GOCACHE: goCache,
PATH: envPath,
CGO_ENABLED: '0',
},
});
Expand Down

0 comments on commit 17f74a7

Please sign in to comment.