diff --git a/src/debugAdapter/goDebug.ts b/src/debugAdapter/goDebug.ts index 0e0a4497f..f8a4132f1 100644 --- a/src/debugAdapter/goDebug.ts +++ b/src/debugAdapter/goDebug.ts @@ -11,7 +11,7 @@ import { readFileSync, existsSync, lstatSync } from 'fs'; import { basename, dirname } from 'path'; import { spawn, ChildProcess, execSync, spawnSync } from 'child_process'; import { Client, RPCConnection } from 'json-rpc2'; -import { getBinPathWithPreferredGopath } from '../goPath'; +import { getBinPathWithPreferredGopath, resolvePath } from '../goPath'; import * as logger from 'vscode-debug-logger'; require('console-stamp')(console); @@ -187,9 +187,10 @@ class Delve { connectClient(port, host); return; } + if (!env) env = {}; - let dlv = getBinPathWithPreferredGopath('dlv', env['GOPATH']); + let dlv = getBinPathWithPreferredGopath('dlv', resolvePath(env['GOPATH'])); if (!existsSync(dlv)) { verbose(`Couldnt find dlv at ${process.env['GOPATH']}${env['GOPATH'] ? ', ' + env['GOPATH'] : ''} or ${process.env['PATH']}`); diff --git a/src/goInstallTools.ts b/src/goInstallTools.ts index 2f0d208cb..f901a0304 100644 --- a/src/goInstallTools.ts +++ b/src/goInstallTools.ts @@ -11,7 +11,7 @@ import path = require('path'); import os = require('os'); import cp = require('child_process'); import { showGoStatus, hideGoStatus } from './goStatus'; -import { getGoRuntimePath } from './goPath'; +import { getGoRuntimePath, resolvePath } from './goPath'; import { outputChannel } from './goStatus'; import { getBinPath, getToolsGopath, getGoVersion, SemVersion, isVendorSupported } from './util'; @@ -207,7 +207,7 @@ export function updateGoPathGoRootFromConfig() { let gopath = vscode.workspace.getConfiguration('go')['gopath']; if (gopath) { - process.env['GOPATH'] = gopath.replace(/\${workspaceRoot}/g, vscode.workspace.rootPath); + process.env['GOPATH'] = resolvePath(gopath, vscode.workspace.rootPath); } let inferGoPath = vscode.workspace.getConfiguration('go')['inferGopath']; diff --git a/src/goPath.ts b/src/goPath.ts index 3cfe27282..f925b95ee 100644 --- a/src/goPath.ts +++ b/src/goPath.ts @@ -95,4 +95,15 @@ function fileExists(filePath: string): boolean { export function clearCacheForTools() { binPathCache = {}; +} + +/** + * Exapnds ~ to homedir in non-Windows platform and replaces ${workspaceRoot} token with given workspaceroot + */ +export function resolvePath(inputPath: string, workspaceRoot?: string): string { + if (!inputPath || !inputPath.trim()) return inputPath; + if (workspaceRoot) { + inputPath = inputPath.replace(/\${workspaceRoot}/g, workspaceRoot); + } + return inputPath.startsWith('~') ? path.join(os.homedir(), inputPath.substr(1)) : inputPath; } \ No newline at end of file diff --git a/src/util.ts b/src/util.ts index a06e3b24f..b27dbbcde 100644 --- a/src/util.ts +++ b/src/util.ts @@ -5,7 +5,7 @@ import vscode = require('vscode'); import path = require('path'); -import { getGoRuntimePath, getBinPathWithPreferredGopath} from './goPath'; +import { getGoRuntimePath, getBinPathWithPreferredGopath, resolvePath} from './goPath'; import cp = require('child_process'); import TelemetryReporter from 'vscode-extension-telemetry'; @@ -253,7 +253,7 @@ export function getToolsGopath(): string { let goConfig = vscode.workspace.getConfiguration('go'); let toolsGopath = goConfig['toolsGopath']; if (toolsGopath) { - toolsGopath = toolsGopath.replace(/\${workspaceRoot}/g, vscode.workspace.rootPath); + toolsGopath = resolvePath(toolsGopath, vscode.workspace.rootPath); } return toolsGopath; }