diff --git a/src/debugAdapter/goDebug.ts b/src/debugAdapter/goDebug.ts index 5c5f35542..4307e7e84 100644 --- a/src/debugAdapter/goDebug.ts +++ b/src/debugAdapter/goDebug.ts @@ -230,12 +230,13 @@ class Delve { let env = Object.assign({}, process.env, fileEnv, launchArgsEnv); + let dirname = isProgramDirectory ? program : path.dirname(program); if (!fileEnv['GOPATH'] && !launchArgsEnv['GOPATH'] && (mode === 'debug' || mode === 'test')) { // If user hasnt specified GOPATH & file/package to debug is not under env['GOPATH'], then infer it from the file/package path // Not applicable to exec mode in which case `program` need not point to source code under GOPATH - let programNotUnderGopath = !env['GOPATH'] || !getCurrentGoWorkspaceFromGOPATH(env['GOPATH'], isProgramDirectory ? program : path.dirname(program)); + let programNotUnderGopath = !env['GOPATH'] || !getCurrentGoWorkspaceFromGOPATH(env['GOPATH'], dirname); if (programNotUnderGopath ) { - env['GOPATH'] = getInferredGopath(isProgramDirectory ? program : path.dirname(program)) || env['GOPATH']; + env['GOPATH'] = getInferredGopath(dirname) || env['GOPATH']; } } @@ -282,9 +283,12 @@ class Delve { } verbose('Using dlv at: ' + dlv); + let currentGOWorkspace = getCurrentGoWorkspaceFromGOPATH(env['GOPATH'], dirname); let dlvArgs = [mode || 'debug']; if (mode === 'exec') { dlvArgs = dlvArgs.concat([program]); + } else if (currentGOWorkspace) { + dlvArgs = dlvArgs.concat([dirname.substr(currentGOWorkspace.length + 1)]); } dlvArgs = dlvArgs.concat(['--headless=true', '--listen=' + host + ':' + port.toString()]); if (launchArgs.showLog) { diff --git a/src/testUtils.ts b/src/testUtils.ts index 3090bff17..44acb17ad 100644 --- a/src/testUtils.ts +++ b/src/testUtils.ts @@ -7,8 +7,8 @@ import cp = require('child_process'); import path = require('path'); import vscode = require('vscode'); import util = require('util'); -import { parseEnvFile, getGoRuntimePath } from './goPath'; -import { getToolsEnvVars, getGoVersion, LineBuffer, SemVersion, resolvePath } from './util'; +import { parseEnvFile, getGoRuntimePath, getCurrentGoWorkspaceFromGOPATH } from './goPath'; +import { getToolsEnvVars, getGoVersion, LineBuffer, SemVersion, resolvePath, getCurrentGoPath } from './util'; import { GoDocumentSymbolProvider } from './goOutline'; import { getNonVendorPackages } from './goPackages'; @@ -127,6 +127,12 @@ export function goTest(testconfig: TestConfig): Thenable { return Promise.resolve(); } + // append the package name to args if applicable + let currentGoWorkspace = getCurrentGoWorkspaceFromGOPATH(getCurrentGoPath(), testconfig.dir); + if (currentGoWorkspace && !testconfig.includeSubDirectories) { + args.push(testconfig.dir.substr(currentGoWorkspace.length + 1)); + } + targetArgs(testconfig).then(targets => { let outTargets = args.slice(0); if (targets.length > 2) {