From 40beca5d1444bb754a46d43b275b96f9dfd7a55e Mon Sep 17 00:00:00 2001 From: Ramya Achutha Rao Date: Tue, 17 Jan 2017 10:18:47 -0800 Subject: [PATCH] Use GOPATH from env set in launch.json if dlv not found --- src/debugAdapter/goDebug.ts | 6 ++++++ src/goPath.ts | 16 ++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/debugAdapter/goDebug.ts b/src/debugAdapter/goDebug.ts index acc6e2d77..7273ea991 100644 --- a/src/debugAdapter/goDebug.ts +++ b/src/debugAdapter/goDebug.ts @@ -169,6 +169,12 @@ class Delve { return; } let dlv = getBinPath('dlv'); + + // If dlv not found, try using the GOPATH that was set in env in launch.json + if (!existsSync(dlv) && env['GOPATH']) { + dlv = getBinPath('dlv', env['GOPATH']); + } + log('Using dlv at: ', dlv); if (!existsSync(dlv)) { return reject(`Cannot find Delve debugger at ${dlv}. Ensure it is in your "GOPATH/bin" or "PATH".`); diff --git a/src/goPath.ts b/src/goPath.ts index 07c018d52..427fe8bc6 100644 --- a/src/goPath.ts +++ b/src/goPath.ts @@ -15,10 +15,10 @@ import os = require('os'); let binPathCache: { [bin: string]: string; } = {}; let runtimePathCache: string = ''; -export function getBinPathFromEnvVar(toolName: string, envVar: string, appendBinToPath: boolean): string { +export function getBinPathFromEnvVar(toolName: string, envVarValue: string, appendBinToPath: boolean): string { toolName = correctBinname(toolName); - if (process.env[envVar]) { - let paths = process.env[envVar].split(path.delimiter); + if (envVarValue) { + let paths = envVarValue.split(path.delimiter); for (let i = 0; i < paths.length; i++) { let binpath = path.join(paths[i], appendBinToPath ? 'bin' : '', toolName); if (fileExists(binpath)) { @@ -30,29 +30,29 @@ export function getBinPathFromEnvVar(toolName: string, envVar: string, appendBin return null; } -export function getBinPath(binname: string) { +export function getBinPath(binname: string, goPath: string = null) { if (binPathCache[correctBinname(binname)]) return binPathCache[correctBinname(binname)]; // First search VSCODE_GOTOOLS' bin folder - let pathFromToolsGoPath = getBinPathFromEnvVar(binname, 'VSCODE_GOTOOLS', true); + let pathFromToolsGoPath = getBinPathFromEnvVar(binname, process.env['VSCODE_GOTOOLS'], true); if (pathFromToolsGoPath) { return pathFromToolsGoPath; } // Then search each GOPATH workspace's bin folder - let pathFromGoPath = getBinPathFromEnvVar(binname, 'GOPATH', true); + let pathFromGoPath = getBinPathFromEnvVar(binname, goPath ? goPath : process.env['GOPATH'], true); if (pathFromGoPath) { return pathFromGoPath; } // Then search PATH parts - let pathFromPath = getBinPathFromEnvVar(binname, 'PATH', false); + let pathFromPath = getBinPathFromEnvVar(binname, process.env['PATH'], false); if (pathFromPath) { return pathFromPath; } // Finally check GOROOT just in case - let pathFromGoRoot = getBinPathFromEnvVar(binname, 'GOROOT', true); + let pathFromGoRoot = getBinPathFromEnvVar(binname, process.env['GOROOT'], true); if (pathFromGoRoot) { return pathFromGoRoot; }