From 4025fd27f9b0a52fb699429b875a516e04ccd427 Mon Sep 17 00:00:00 2001 From: Henry Wong Date: Thu, 5 Sep 2019 21:55:37 +0800 Subject: [PATCH] [code] Append go env variable 'GOCACHE' to go lsp spawn command. 'GOCACHE' is set to '$HOME/.cache' by default. It is not portable because it relies on the users who run the kibana. Customize 'GOCACHE' to $GOPATH/.cache to make the go lsp more portable. FYI: The build cache is now required as a step toward eliminating $GOPATH/pkg. --- .../legacy/plugins/code/server/lsp/go_launcher.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/x-pack/legacy/plugins/code/server/lsp/go_launcher.ts b/x-pack/legacy/plugins/code/server/lsp/go_launcher.ts index 016afdc18eb49..c8b707f9b5fb9 100644 --- a/x-pack/legacy/plugins/code/server/lsp/go_launcher.ts +++ b/x-pack/legacy/plugins/code/server/lsp/go_launcher.ts @@ -77,9 +77,12 @@ export class GoServerLauncher extends AbstractLauncher { } async spawnProcess(installationPath: string, port: number, log: Logger) { - const launchersFound = glob.sync('go-langserver', { - cwd: installationPath, - }); + const launchersFound = glob.sync( + process.platform === 'win32' ? 'go-langserver.exe' : 'go-langserver', + { + cwd: installationPath, + } + ); if (!launchersFound.length) { throw new Error('Cannot find executable go language server'); } @@ -92,12 +95,13 @@ export class GoServerLauncher extends AbstractLauncher { // Construct $GOROOT from the bundled go toolchain. const goRoot = goToolchain; const goHome = path.resolve(goToolchain, 'bin'); - envPath = envPath + ':' + goHome; + envPath = process.platform === 'win32' ? envPath + ';' + goHome : envPath + ':' + goHome; // Construct $GOPATH under 'kibana/data/code'. const goPath = this.options.goPath; if (!fs.existsSync(goPath)) { fs.mkdirSync(goPath); } + const goCache = path.resolve(goPath, '.cache'); const params: string[] = ['-port=' + port.toString()]; const golsp = path.resolve(installationPath, launchersFound[0]); const p = spawn(golsp, params, { @@ -109,6 +113,7 @@ export class GoServerLauncher extends AbstractLauncher { CLIENT_PORT: port.toString(), GOROOT: goRoot, GOPATH: goPath, + GOCACHE: goCache, PATH: envPath, CGO_ENABLED: '0', },