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

Fix 'Debug: Start Without Debugging' to use current file and include buildFlags/args #2123

Merged
merged 3 commits into from
Nov 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 36 additions & 20 deletions src/debugAdapter/goDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ interface LaunchRequestArguments extends DebugProtocol.LaunchRequestArguments {
apiVersion: number;
/** Delve maximum stack trace depth */
stackTraceDepth: number;
currentFile: string;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ramya-rao-a This was the only way to pass along currentFile, but this is obviously not configuration. Is it OK to not have currentFile in the schema in package.json?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, its ok. In this case, this is an internal implementation. Current file can always be determined by VS Code using the vscode.window.activeTextEditor. It need not be provided by the user

}

process.on('uncaughtException', (err: any) => {
Expand Down Expand Up @@ -318,26 +319,41 @@ class Delve {
verbose(`Using GOPATH: ${env['GOPATH']}`);

if (!!launchArgs.noDebug) {
if (mode === 'debug' && !isProgramDirectory) {
this.noDebug = true;
this.debugProcess = spawn(getBinPathWithPreferredGopath('go', []), ['run', program], { env });
this.debugProcess.stderr.on('data', chunk => {
let str = chunk.toString();
if (this.onstderr) { this.onstderr(str); }
});
this.debugProcess.stdout.on('data', chunk => {
let str = chunk.toString();
if (this.onstdout) { this.onstdout(str); }
});
this.debugProcess.on('close', (code) => {
logError('Process exiting with code: ' + code);
if (this.onclose) { this.onclose(code); }
});
this.debugProcess.on('error', function (err) {
reject(err);
});
resolve();
return;
if (mode === 'debug') {
if (isProgramDirectory && launchArgs.currentFile) {
program = launchArgs.currentFile;
isProgramDirectory = false;
}

if (!isProgramDirectory) {
this.noDebug = true;
let runArgs = ['run'];
if (launchArgs.buildFlags) {
runArgs.push(launchArgs.buildFlags);
}
runArgs.push(program);
if (launchArgs.args) {
runArgs.push(...launchArgs.args);
}
this.debugProcess = spawn(getBinPathWithPreferredGopath('go', []), runArgs, { env });
this.debugProcess.stderr.on('data', chunk => {
let str = chunk.toString();
if (this.onstderr) { this.onstderr(str); }
});
this.debugProcess.stdout.on('data', chunk => {
let str = chunk.toString();
if (this.onstdout) { this.onstdout(str); }
});
this.debugProcess.on('close', (code) => {
logError('Process exiting with code: ' + code);
if (this.onclose) { this.onclose(code); }
});
this.debugProcess.on('error', function (err) {
reject(err);
});
resolve();
return;
}
}
}
this.noDebug = false;
Expand Down
1 change: 1 addition & 0 deletions src/goDebugConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
if (debugConfiguration['mode'] === 'auto') {
debugConfiguration['mode'] = (activeEditor && activeEditor.document.fileName.endsWith('_test.go')) ? 'test' : 'debug';
}
debugConfiguration['currentFile'] = activeEditor && activeEditor.document.languageId === 'go' && activeEditor.document.fileName;

return debugConfiguration;
}
Expand Down