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

Commit

Permalink
pass <package> to dlv test/debug if applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouhaibing089 committed Sep 15, 2017
1 parent 9618aa0 commit c622d85
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/debugAdapter/goDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ class Delve {
return reject('The program attribute must point to valid directory, .go file or executable.');
}

// get the package information
let pkgname = '';
let dirname = isProgramDirectory ? program : path.dirname(program);
if (process.env['GOPATH'] !== '' && dirname.startsWith(process.env['GOPATH'])) {
pkgname = dirname.substr(process.env['GOPATH'].length + 5);
}

// read env from disk and merge into env variables
let fileEnv = {};
try {
Expand All @@ -233,9 +240,9 @@ class Delve {
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'];
}
}

Expand Down Expand Up @@ -285,6 +292,8 @@ class Delve {
let dlvArgs = [mode || 'debug'];
if (mode === 'exec') {
dlvArgs = dlvArgs.concat([program]);
} else if (pkgname !== '') {
dlvArgs = dlvArgs.concat([pkgname]);
}
dlvArgs = dlvArgs.concat(['--headless=true', '--listen=' + host + ':' + port.toString()]);
if (launchArgs.showLog) {
Expand Down
5 changes: 5 additions & 0 deletions src/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ export function goTest(testconfig: TestConfig): Thenable<boolean> {
return Promise.resolve();
}

// append the package name to args if applicable
if (process.env['GOPATH'] !== '' && testconfig.dir.startsWith(process.env['GOPATH'])) {
args.push(testconfig.dir.substr(process.env['GOPATH'].length + 5));
}

targetArgs(testconfig).then(targets => {
let outTargets = args.slice(0);
if (targets.length > 2) {
Expand Down

0 comments on commit c622d85

Please sign in to comment.