From 087b80d3cfafac56033d2f98cffdd493a085577f Mon Sep 17 00:00:00 2001 From: zhouhaibing089 Date: Fri, 25 Aug 2017 16:42:11 +0800 Subject: [PATCH] pass to dlv test/debug if applicable --- src/debugAdapter/goDebug.ts | 13 +++++++++++-- src/testUtils.ts | 5 +++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/debugAdapter/goDebug.ts b/src/debugAdapter/goDebug.ts index a629121e1..bc0b782d7 100644 --- a/src/debugAdapter/goDebug.ts +++ b/src/debugAdapter/goDebug.ts @@ -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 { @@ -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) { @@ -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) { diff --git a/src/testUtils.ts b/src/testUtils.ts index 58df55f12..f648c3135 100644 --- a/src/testUtils.ts +++ b/src/testUtils.ts @@ -123,6 +123,11 @@ export function goTest(testconfig: TestConfig): Thenable { 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) {