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 (#1164)
Browse files Browse the repository at this point in the history
* pass <package> to dlv test/debug if applicable

* Refactoring
  • Loading branch information
zhouhaibing089 authored and ramya-rao-a committed Sep 28, 2017
1 parent 23399bf commit 2520e29
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/debugAdapter/goDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
}

Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 8 additions & 2 deletions src/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -127,6 +127,12 @@ export function goTest(testconfig: TestConfig): Thenable<boolean> {
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) {
Expand Down

0 comments on commit 2520e29

Please sign in to comment.