From a3bbd8f49cb4204b0d81ac8214f27d6b98a6679b Mon Sep 17 00:00:00 2001 From: Bryce Kahle Date: Tue, 13 Nov 2018 18:21:07 -0500 Subject: [PATCH 1/3] Include buildFlags and args when running without debugging Fixes #2086 --- src/debugAdapter/goDebug.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/debugAdapter/goDebug.ts b/src/debugAdapter/goDebug.ts index 3d03cc30b..c7ac914ee 100644 --- a/src/debugAdapter/goDebug.ts +++ b/src/debugAdapter/goDebug.ts @@ -320,7 +320,15 @@ class Delve { if (!!launchArgs.noDebug) { if (mode === 'debug' && !isProgramDirectory) { this.noDebug = true; - this.debugProcess = spawn(getBinPathWithPreferredGopath('go', []), ['run', program], { env }); + 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); } From 74c81dc6d26b120e55091a8dffc0def50193a83d Mon Sep 17 00:00:00 2001 From: Bryce Kahle Date: Tue, 13 Nov 2018 18:46:41 -0500 Subject: [PATCH 2/3] Use current file for 'Start Without Debugging' Fixes #2085 --- src/debugAdapter/goDebug.ts | 60 +++++++++++++++++++++---------------- src/goDebugConfiguration.ts | 1 + 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/debugAdapter/goDebug.ts b/src/debugAdapter/goDebug.ts index c7ac914ee..4ad857c25 100644 --- a/src/debugAdapter/goDebug.ts +++ b/src/debugAdapter/goDebug.ts @@ -211,6 +211,7 @@ interface LaunchRequestArguments extends DebugProtocol.LaunchRequestArguments { apiVersion: number; /** Delve maximum stack trace depth */ stackTraceDepth: number; + currentFile: string; } process.on('uncaughtException', (err: any) => { @@ -318,34 +319,41 @@ class Delve { verbose(`Using GOPATH: ${env['GOPATH']}`); if (!!launchArgs.noDebug) { - if (mode === 'debug' && !isProgramDirectory) { - this.noDebug = true; - let runArgs = ['run']; - if (launchArgs.buildFlags) { - runArgs.push(launchArgs.buildFlags); + if (mode === 'debug') { + if (isProgramDirectory && launchArgs.currentFile) { + program = launchArgs.currentFile; + isProgramDirectory = false; } - runArgs.push(program); - if (launchArgs.args) { - runArgs.push(...launchArgs.args); + + 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.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; diff --git a/src/goDebugConfiguration.ts b/src/goDebugConfiguration.ts index 219463aaa..7b91ccb5a 100644 --- a/src/goDebugConfiguration.ts +++ b/src/goDebugConfiguration.ts @@ -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.fileName; return debugConfiguration; } From 9427b811221b23dab22dfedf7aeccd3ed23be4fb Mon Sep 17 00:00:00 2001 From: Ramya Achutha Rao Date: Tue, 20 Nov 2018 20:30:14 -0800 Subject: [PATCH 3/3] Additional check to ensure Go file --- src/goDebugConfiguration.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/goDebugConfiguration.ts b/src/goDebugConfiguration.ts index 7b91ccb5a..0c7386e07 100644 --- a/src/goDebugConfiguration.ts +++ b/src/goDebugConfiguration.ts @@ -89,7 +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.fileName; + debugConfiguration['currentFile'] = activeEditor && activeEditor.document.languageId === 'go' && activeEditor.document.fileName; return debugConfiguration; }