@@ -17,19 +17,18 @@ import {
17
17
logger ,
18
18
Logger ,
19
19
LoggingDebugSession ,
20
- TerminatedEvent ,
21
- OutputEvent
20
+ OutputEvent ,
21
+ TerminatedEvent
22
22
} from 'vscode-debugadapter' ;
23
23
import { DebugProtocol } from 'vscode-debugprotocol' ;
24
24
25
25
import {
26
26
envPath ,
27
- parseEnvFile ,
28
- getBinPathWithPreferredGopathGoroot
27
+ getBinPathWithPreferredGopathGoroot ,
28
+ parseEnvFile
29
29
} from '../goPath' ;
30
30
import { DAPClient } from './dapClient' ;
31
31
32
-
33
32
interface LoadConfig {
34
33
// FollowPointers requests pointers to be automatically dereferenced.
35
34
followPointers : boolean ;
@@ -264,73 +263,6 @@ export class GoDlvDapDebugSession extends LoggingDebugSession {
264
263
} ) ;
265
264
}
266
265
267
- // Launch the debugee process without starting a debugger.
268
- // This implements the `Run > Run Without Debugger` functionality in vscode.
269
- // Note: this method currently assumes launchArgs.mode === 'debug'.
270
- private launchNoDebug ( launchArgs : LaunchRequestArguments ) : void {
271
- let program = launchArgs . program ;
272
- if ( ! program ) {
273
- throw new Error ( 'The program attribute is missing in the debug configuration in launch.json' ) ;
274
- }
275
- let programIsDirectory = false ;
276
- try {
277
- programIsDirectory = fs . lstatSync ( program ) . isDirectory ( ) ;
278
- } catch ( e ) {
279
- throw new Error ( 'The program attribute must point to valid directory, .go file or executable.' ) ;
280
- }
281
- if ( ! programIsDirectory && path . extname ( program ) !== '.go' ) {
282
- throw new Error ( 'The program attribute must be a directory or .go file in debug mode' ) ;
283
- }
284
-
285
- let goRunArgs = [ 'run' ] ;
286
- if ( launchArgs . buildFlags ) {
287
- goRunArgs . push ( launchArgs . buildFlags ) ;
288
- }
289
-
290
- if ( programIsDirectory ) {
291
- goRunArgs . push ( '.' ) ;
292
- } else {
293
- goRunArgs . push ( program ) ;
294
- }
295
-
296
- if ( launchArgs . args ) {
297
- goRunArgs . push ( ...launchArgs . args ) ;
298
- }
299
-
300
- // Read env from disk and merge into env variables.
301
- const fileEnvs = [ ] ;
302
- if ( typeof launchArgs . envFile === 'string' ) {
303
- fileEnvs . push ( parseEnvFile ( launchArgs . envFile ) ) ;
304
- }
305
- if ( Array . isArray ( launchArgs . envFile ) ) {
306
- launchArgs . envFile . forEach ( ( envFile ) => {
307
- fileEnvs . push ( parseEnvFile ( envFile ) ) ;
308
- } ) ;
309
- }
310
-
311
- const launchArgsEnv = launchArgs . env || { } ;
312
- let programEnv = Object . assign ( { } , process . env , ...fileEnvs , launchArgsEnv ) ;
313
-
314
- const dirname = programIsDirectory ? program : path . dirname ( program ) ;
315
- const goExe = getBinPathWithPreferredGopathGoroot ( 'go' , [ ] ) ;
316
- log ( `Current working directory: ${ dirname } ` ) ;
317
- log ( `Running: ${ goExe } ${ goRunArgs . join ( ' ' ) } ` ) ;
318
-
319
- this . debugProcess = spawn ( goExe , goRunArgs , {
320
- cwd : dirname ,
321
- env : programEnv
322
- } ) ;
323
- this . debugProcess . stderr . on ( 'data' , ( str ) => {
324
- this . sendEvent ( new OutputEvent ( str . toString ( ) , 'stderr' ) ) ;
325
- } ) ;
326
- this . debugProcess . stdout . on ( 'data' , ( str ) => {
327
- this . sendEvent ( new OutputEvent ( str . toString ( ) , 'stdout' ) ) ;
328
- } ) ;
329
- this . debugProcess . on ( 'close' , ( rc ) => {
330
- this . sendEvent ( new TerminatedEvent ( ) ) ;
331
- } ) ;
332
- }
333
-
334
266
protected attachRequest (
335
267
response : DebugProtocol . AttachResponse ,
336
268
args : AttachRequestArguments ,
@@ -355,14 +287,14 @@ export class GoDlvDapDebugSession extends LoggingDebugSession {
355
287
if ( this . debugProcess !== null ) {
356
288
log ( `killing debugee (pid: ${ this . debugProcess . pid } )...` ) ;
357
289
358
- // Kill the debuggee and notify the client when the killing is
290
+ // Kill the debugee and notify the client when the killing is
359
291
// completed, to ensure a clean shutdown sequence.
360
292
killProcessTree ( this . debugProcess ) . then ( ( ) => {
361
293
super . disconnectRequest ( response , args ) ;
362
294
log ( 'DisconnectResponse' ) ;
363
- } )
295
+ } ) ;
364
296
} else if ( this . dlvClient !== null ) {
365
- // Forward this DisconnectRequest to Delve.
297
+ // Forward this DisconnectRequest to Delve.
366
298
this . dlvClient . send ( request ) ;
367
299
} else {
368
300
logError ( `both debug process and dlv client are null` ) ;
@@ -661,6 +593,73 @@ export class GoDlvDapDebugSession extends LoggingDebugSession {
661
593
) : void {
662
594
this . dlvClient . send ( request ) ;
663
595
}
596
+
597
+ // Launch the debugee process without starting a debugger.
598
+ // This implements the `Run > Run Without Debugger` functionality in vscode.
599
+ // Note: this method currently assumes launchArgs.mode === 'debug'.
600
+ private launchNoDebug ( launchArgs : LaunchRequestArguments ) : void {
601
+ const program = launchArgs . program ;
602
+ if ( ! program ) {
603
+ throw new Error ( 'The program attribute is missing in the debug configuration in launch.json' ) ;
604
+ }
605
+ let programIsDirectory = false ;
606
+ try {
607
+ programIsDirectory = fs . lstatSync ( program ) . isDirectory ( ) ;
608
+ } catch ( e ) {
609
+ throw new Error ( 'The program attribute must point to valid directory, .go file or executable.' ) ;
610
+ }
611
+ if ( ! programIsDirectory && path . extname ( program ) !== '.go' ) {
612
+ throw new Error ( 'The program attribute must be a directory or .go file in debug mode' ) ;
613
+ }
614
+
615
+ const goRunArgs = [ 'run' ] ;
616
+ if ( launchArgs . buildFlags ) {
617
+ goRunArgs . push ( launchArgs . buildFlags ) ;
618
+ }
619
+
620
+ if ( programIsDirectory ) {
621
+ goRunArgs . push ( '.' ) ;
622
+ } else {
623
+ goRunArgs . push ( program ) ;
624
+ }
625
+
626
+ if ( launchArgs . args ) {
627
+ goRunArgs . push ( ...launchArgs . args ) ;
628
+ }
629
+
630
+ // Read env from disk and merge into env variables.
631
+ const fileEnvs = [ ] ;
632
+ if ( typeof launchArgs . envFile === 'string' ) {
633
+ fileEnvs . push ( parseEnvFile ( launchArgs . envFile ) ) ;
634
+ }
635
+ if ( Array . isArray ( launchArgs . envFile ) ) {
636
+ launchArgs . envFile . forEach ( ( envFile ) => {
637
+ fileEnvs . push ( parseEnvFile ( envFile ) ) ;
638
+ } ) ;
639
+ }
640
+
641
+ const launchArgsEnv = launchArgs . env || { } ;
642
+ const programEnv = Object . assign ( { } , process . env , ...fileEnvs , launchArgsEnv ) ;
643
+
644
+ const dirname = programIsDirectory ? program : path . dirname ( program ) ;
645
+ const goExe = getBinPathWithPreferredGopathGoroot ( 'go' , [ ] ) ;
646
+ log ( `Current working directory: ${ dirname } ` ) ;
647
+ log ( `Running: ${ goExe } ${ goRunArgs . join ( ' ' ) } ` ) ;
648
+
649
+ this . debugProcess = spawn ( goExe , goRunArgs , {
650
+ cwd : dirname ,
651
+ env : programEnv
652
+ } ) ;
653
+ this . debugProcess . stderr . on ( 'data' , ( str ) => {
654
+ this . sendEvent ( new OutputEvent ( str . toString ( ) , 'stderr' ) ) ;
655
+ } ) ;
656
+ this . debugProcess . stdout . on ( 'data' , ( str ) => {
657
+ this . sendEvent ( new OutputEvent ( str . toString ( ) , 'stdout' ) ) ;
658
+ } ) ;
659
+ this . debugProcess . on ( 'close' , ( rc ) => {
660
+ this . sendEvent ( new TerminatedEvent ( ) ) ;
661
+ } ) ;
662
+ }
664
663
}
665
664
666
665
// DelveClient provides a DAP client to talk to a DAP server in Delve.
@@ -786,4 +785,4 @@ function killProcessTree(p: ChildProcess): Promise<void> {
786
785
resolve ( ) ;
787
786
} ) ;
788
787
} ) ;
789
- }
788
+ }
0 commit comments