[code] Append go env variable 'GOCACHE' to go lsp spawn command. (#44864) (#44901)

'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.
This commit is contained in:
Henry Wong 2019-09-06 01:37:03 +08:00 committed by GitHub
parent 5bc76f8438
commit 3ff0b88539
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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',
},