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 Aug 25, 2017
1 parent eaa1ed1 commit 087b80d
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 @@ -219,6 +219,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 @@ -231,9 +238,9 @@ class Delve {

// If 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 && (mode === 'debug' || mode === 'test')) {
env['GOPATH'] = getInferredGopath(isProgramDirectory ? program : path.dirname(program));
env['GOPATH'] = getInferredGopath(dirname);
}

if (!!launchArgs.noDebug) {
Expand Down Expand Up @@ -280,6 +287,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 @@ -123,6 +123,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 087b80d

Please sign in to comment.