diff --git a/src/debugAdapter/goDebug.ts b/src/debugAdapter/goDebug.ts index 3d03cc30b..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,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; diff --git a/src/goDebugConfiguration.ts b/src/goDebugConfiguration.ts index 219463aaa..0c7386e07 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.languageId === 'go' && activeEditor.document.fileName; return debugConfiguration; }