Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Use GOPATH from env set in launch.json if dlv not found (#725)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a authored Jan 19, 2017
1 parent ddb434c commit a1a162a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/debugAdapter/goDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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".`);
Expand Down
16 changes: 8 additions & 8 deletions src/goPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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;
}
Expand Down

0 comments on commit a1a162a

Please sign in to comment.