@@ -16,6 +16,7 @@ import * as net from 'net';
16
16
import { getTool } from './goTools' ;
17
17
import { Logger , TimestampedLogger } from './goLogging' ;
18
18
import { DebugProtocol } from 'vscode-debugprotocol' ;
19
+ import { getWorkspaceFolderPath } from './util' ;
19
20
20
21
export class GoDebugAdapterDescriptorFactory implements vscode . DebugAdapterDescriptorFactory {
21
22
constructor ( private outputChannel ?: vscode . OutputChannel ) { }
@@ -194,7 +195,7 @@ export class ProxyDebugAdapter implements vscode.DebugAdapter {
194
195
// VSCode and a dlv dap process spawned and managed by this adapter.
195
196
// It turns the process's stdout/stderrr into OutputEvent.
196
197
export class DelveDAPOutputAdapter extends ProxyDebugAdapter {
197
- constructor ( private config : vscode . DebugConfiguration , logger ?: Logger ) {
198
+ constructor ( private configuration : vscode . DebugConfiguration , logger ?: Logger ) {
198
199
super ( logger ) ;
199
200
this . connected = this . startAndConnectToServer ( ) ;
200
201
}
@@ -276,7 +277,7 @@ export class DelveDAPOutputAdapter extends ProxyDebugAdapter {
276
277
private async startAndConnectToServer ( ) {
277
278
try {
278
279
const { port, host, dlvDapServer } = await startDapServer (
279
- this . config ,
280
+ this . configuration ,
280
281
( msg ) => this . outputEvent ( 'stdout' , msg ) ,
281
282
( msg ) => this . outputEvent ( 'stderr' , msg ) ,
282
283
( msg ) => {
@@ -336,17 +337,17 @@ async function startDapServer(
336
337
}
337
338
338
339
function spawnDlvDapServerProcess (
339
- launchArgs : vscode . DebugConfiguration ,
340
+ launchAttachArgs : vscode . DebugConfiguration ,
340
341
host : string ,
341
342
port : number ,
342
343
log : ( msg : string ) => void ,
343
344
logErr : ( msg : string ) => void ,
344
345
logConsole : ( msg : string ) => void
345
346
) : Promise < ChildProcess > {
346
- const launchArgsEnv = launchArgs . env || { } ;
347
+ const launchArgsEnv = launchAttachArgs . env || { } ;
347
348
const env = Object . assign ( { } , process . env , launchArgsEnv ) ;
348
349
349
- const dlvPath = launchArgs . dlvToolPath ?? getTool ( 'dlv-dap' ) ;
350
+ const dlvPath = launchAttachArgs . dlvToolPath ?? getTool ( 'dlv-dap' ) ;
350
351
351
352
if ( ! fs . existsSync ( dlvPath ) ) {
352
353
const envPath = process . env [ 'PATH' ] || ( process . platform === 'win32' ? process . env [ 'Path' ] : null ) ;
@@ -358,27 +359,29 @@ function spawnDlvDapServerProcess(
358
359
) ;
359
360
throw new Error ( 'Cannot find Delve debugger (dlv dap)' ) ;
360
361
}
361
- let dir = '' ;
362
- try {
363
- dir = parseProgramArgSync ( launchArgs ) . dirname ;
364
- } catch ( err ) {
365
- logErr ( `Program arg: ${ launchArgs . program } \n${ err } \n` ) ;
366
- throw err ; // rethrow so the caller knows it failed.
362
+ let dir = getWorkspaceFolderPath ( ) ;
363
+ if ( launchAttachArgs . request === 'launch' ) {
364
+ try {
365
+ dir = parseProgramArgSync ( launchAttachArgs ) . dirname ;
366
+ } catch ( err ) {
367
+ logErr ( `Program arg: ${ launchAttachArgs . program } \n${ err } \n` ) ;
368
+ throw err ; // rethrow so the caller knows it failed.
369
+ }
367
370
}
368
371
369
372
const dlvArgs = new Array < string > ( ) ;
370
373
dlvArgs . push ( 'dap' ) ;
371
374
// add user-specified dlv flags first. When duplicate flags are specified,
372
375
// dlv doesn't mind but accepts the last flag value.
373
- if ( launchArgs . dlvFlags && launchArgs . dlvFlags . length > 0 ) {
374
- dlvArgs . push ( ...launchArgs . dlvFlags ) ;
376
+ if ( launchAttachArgs . dlvFlags && launchAttachArgs . dlvFlags . length > 0 ) {
377
+ dlvArgs . push ( ...launchAttachArgs . dlvFlags ) ;
375
378
}
376
379
dlvArgs . push ( `--listen=${ host } :${ port } ` ) ;
377
- if ( launchArgs . showLog ) {
378
- dlvArgs . push ( '--log=' + launchArgs . showLog . toString ( ) ) ;
380
+ if ( launchAttachArgs . showLog ) {
381
+ dlvArgs . push ( '--log=' + launchAttachArgs . showLog . toString ( ) ) ;
379
382
}
380
- if ( launchArgs . logOutput ) {
381
- dlvArgs . push ( '--log-output=' + launchArgs . logOutput ) ;
383
+ if ( launchAttachArgs . logOutput ) {
384
+ dlvArgs . push ( '--log-output=' + launchAttachArgs . logOutput ) ;
382
385
}
383
386
384
387
const onWindows = process . platform === 'win32' ;
@@ -387,7 +390,7 @@ function spawnDlvDapServerProcess(
387
390
dlvArgs . push ( '--log-dest=3' ) ;
388
391
}
389
392
390
- const logDest = launchArgs . logDest ;
393
+ const logDest = launchAttachArgs . logDest ;
391
394
if ( typeof logDest === 'number' ) {
392
395
logErr ( `Using a file descriptor for 'logDest' (${ logDest } ) is not allowed.\n` ) ;
393
396
throw new Error ( 'Using a file descriptor for `logDest` is not allowed.' ) ;
@@ -511,9 +514,9 @@ function spawnDlvDapServerProcess(
511
514
}
512
515
513
516
export function parseProgramArgSync (
514
- launchArgs : vscode . DebugConfiguration
517
+ launchAttachArgs : vscode . DebugConfiguration
515
518
) : { program : string ; dirname : string ; programIsDirectory : boolean } {
516
- const program = launchArgs . program ;
519
+ const program = launchAttachArgs . program ;
517
520
if ( ! program ) {
518
521
throw new Error ( 'The program attribute is missing in the debug configuration in launch.json' ) ;
519
522
}
@@ -524,7 +527,7 @@ export function parseProgramArgSync(
524
527
// TODO(hyangah): why can't the program be a package name?
525
528
throw new Error ( 'The program attribute must point to valid directory, .go file or executable.' ) ;
526
529
}
527
- if ( ! programIsDirectory && launchArgs . mode !== 'exec' && path . extname ( program ) !== '.go' ) {
530
+ if ( ! programIsDirectory && launchAttachArgs . mode !== 'exec' && path . extname ( program ) !== '.go' ) {
528
531
throw new Error ( 'The program attribute must be a directory or .go file in debug and test mode' ) ;
529
532
}
530
533
const dirname = programIsDirectory ? program : path . dirname ( program ) ;
0 commit comments