@@ -33,9 +33,9 @@ export class DebugSessionFeature extends LanguageClientConsumer
33
33
implements DebugConfigurationProvider , vscode . DebugAdapterDescriptorFactory {
34
34
35
35
private sessionCount : number = 1 ;
36
- private tempDebugProcess : PowerShellProcess ;
37
- private tempSessionDetails : IEditorServicesSessionDetails ;
38
- private handlers : vscode . Disposable [ ] ;
36
+ private tempDebugProcess : PowerShellProcess | undefined ;
37
+ private tempSessionDetails : IEditorServicesSessionDetails | undefined ;
38
+ private handlers : vscode . Disposable [ ] = [ ] ;
39
39
private configs : Record < DebugConfig , DebugConfiguration > = {
40
40
[ DebugConfig . LaunchCurrentFile ] : {
41
41
name : "PowerShell: Launch Current File" ,
@@ -68,7 +68,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
68
68
super ( ) ;
69
69
// Register a debug configuration provider
70
70
context . subscriptions . push ( vscode . debug . registerDebugConfigurationProvider ( "PowerShell" , this ) ) ;
71
- context . subscriptions . push ( vscode . debug . registerDebugAdapterDescriptorFactory ( "PowerShell" , this ) )
71
+ context . subscriptions . push ( vscode . debug . registerDebugAdapterDescriptorFactory ( "PowerShell" , this ) ) ;
72
72
}
73
73
74
74
createDebugAdapterDescriptor (
@@ -79,6 +79,11 @@ export class DebugSessionFeature extends LanguageClientConsumer
79
79
? this . tempSessionDetails
80
80
: this . sessionManager . getSessionDetails ( ) ;
81
81
82
+ if ( sessionDetails === undefined ) {
83
+ this . logger . writeAndShowError ( `No session details available for ${ session . name } ` ) ;
84
+ return ;
85
+ }
86
+
82
87
this . logger . writeVerbose ( `Connecting to pipe: ${ sessionDetails . debugServicePipeName } ` ) ;
83
88
this . logger . writeVerbose ( `Debug configuration: ${ JSON . stringify ( session . configuration ) } ` ) ;
84
89
@@ -234,6 +239,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
234
239
return undefined ;
235
240
}
236
241
}
242
+
237
243
// Check the temporary console setting for untitled documents only, and
238
244
// check the document extension for everything else.
239
245
if ( config . untitled_document ) {
@@ -248,17 +254,24 @@ export class DebugSessionFeature extends LanguageClientConsumer
248
254
return undefined ;
249
255
}
250
256
}
257
+
251
258
return config ;
252
259
}
253
260
254
261
private async resolveAttachDebugConfiguration ( config : DebugConfiguration ) : Promise < DebugConfiguration | undefined | null > {
255
262
const platformDetails = getPlatformDetails ( ) ;
256
263
const versionDetails = this . sessionManager . getPowerShellVersionDetails ( ) ;
264
+ if ( versionDetails === undefined ) {
265
+ vscode . window . showErrorMessage ( `Session version details were not found for ${ config . name } ` )
266
+ return null ;
267
+ }
268
+
257
269
// Cross-platform attach to process was added in 6.2.0-preview.4.
258
270
if ( versionDetails . version < "7.0.0" && platformDetails . operatingSystem !== OperatingSystem . Windows ) {
259
271
vscode . window . showErrorMessage ( `Attaching to a PowerShell Host Process on ${ OperatingSystem [ platformDetails . operatingSystem ] } requires PowerShell 7.0 or higher.` ) ;
260
272
return undefined ;
261
273
}
274
+
262
275
// If nothing is set, prompt for the processId.
263
276
if ( ! config . customPipeName && ! config . processId ) {
264
277
config . processId = await vscode . commands . executeCommand ( "PowerShell.PickPSHostProcess" ) ;
@@ -267,13 +280,15 @@ export class DebugSessionFeature extends LanguageClientConsumer
267
280
return null ;
268
281
}
269
282
}
283
+
270
284
if ( ! config . runspaceId && ! config . runspaceName ) {
271
285
config . runspaceId = await vscode . commands . executeCommand ( "PowerShell.PickRunspace" , config . processId ) ;
272
286
// No runspace selected. Cancel attach.
273
287
if ( ! config . runspaceId ) {
274
288
return null ;
275
289
}
276
290
}
291
+
277
292
return config ;
278
293
}
279
294
}
@@ -341,7 +356,7 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
341
356
342
357
private command : vscode . Disposable ;
343
358
private waitingForClientToken ?: vscode . CancellationTokenSource ;
344
- private getLanguageClientResolve : ( value : LanguageClient ) => void ;
359
+ private getLanguageClientResolve ? : ( value : LanguageClient ) => void ;
345
360
346
361
constructor ( ) {
347
362
super ( ) ;
@@ -356,7 +371,7 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
356
371
public setLanguageClient ( languageClient : LanguageClient ) {
357
372
this . languageClient = languageClient ;
358
373
359
- if ( this . waitingForClientToken ) {
374
+ if ( this . waitingForClientToken && this . getLanguageClientResolve ) {
360
375
this . getLanguageClientResolve ( this . languageClient ) ;
361
376
this . clearWaitingToken ( ) ;
362
377
}
@@ -367,7 +382,7 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
367
382
}
368
383
369
384
private getLanguageClient ( ) : Promise < LanguageClient > {
370
- if ( this . languageClient ) {
385
+ if ( this . languageClient !== undefined ) {
371
386
return Promise . resolve ( this . languageClient ) ;
372
387
} else {
373
388
// If PowerShell isn't finished loading yet, show a loading message
@@ -406,13 +421,14 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
406
421
}
407
422
408
423
private async pickPSHostProcess ( ) : Promise < string | undefined > {
409
- const hostProcesses = await this . languageClient . sendRequest ( GetPSHostProcessesRequestType , { } ) ;
410
424
// Start with the current PowerShell process in the list.
411
425
const items : IProcessItem [ ] = [ {
412
426
label : "Current" ,
413
427
description : "The current PowerShell Extension process." ,
414
428
pid : "current" ,
415
429
} ] ;
430
+
431
+ const hostProcesses = await this . languageClient ?. sendRequest ( GetPSHostProcessesRequestType , { } ) ;
416
432
for ( const p in hostProcesses ) {
417
433
if ( hostProcesses . hasOwnProperty ( p ) ) {
418
434
let windowTitle = "" ;
@@ -427,15 +443,18 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
427
443
} ) ;
428
444
}
429
445
}
446
+
430
447
if ( items . length === 0 ) {
431
448
return Promise . reject ( "There are no PowerShell host processes to attach to." ) ;
432
449
}
450
+
433
451
const options : vscode . QuickPickOptions = {
434
452
placeHolder : "Select a PowerShell host process to attach to" ,
435
453
matchOnDescription : true ,
436
454
matchOnDetail : true ,
437
455
} ;
438
456
const item = await vscode . window . showQuickPick ( items , options ) ;
457
+
439
458
return item ? `${ item . pid } ` : undefined ;
440
459
}
441
460
@@ -462,7 +481,7 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
462
481
463
482
private command : vscode . Disposable ;
464
483
private waitingForClientToken ?: vscode . CancellationTokenSource ;
465
- private getLanguageClientResolve : ( value : LanguageClient ) => void ;
484
+ private getLanguageClientResolve ? : ( value : LanguageClient ) => void ;
466
485
467
486
constructor ( ) {
468
487
super ( ) ;
@@ -476,7 +495,7 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
476
495
public setLanguageClient ( languageClient : LanguageClient ) {
477
496
this . languageClient = languageClient ;
478
497
479
- if ( this . waitingForClientToken ) {
498
+ if ( this . waitingForClientToken && this . getLanguageClientResolve ) {
480
499
this . getLanguageClientResolve ( this . languageClient ) ;
481
500
this . clearWaitingToken ( ) ;
482
501
}
@@ -526,9 +545,9 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
526
545
}
527
546
528
547
private async pickRunspace ( processId : string ) : Promise < string | undefined > {
529
- const response = await this . languageClient . sendRequest ( GetRunspaceRequestType , { processId } ) ;
548
+ const response = await this . languageClient ? .sendRequest ( GetRunspaceRequestType , { processId } ) ;
530
549
const items : IRunspaceItem [ ] = [ ] ;
531
- for ( const runspace of response ) {
550
+ for ( const runspace of response ?? [ ] ) {
532
551
// Skip default runspace
533
552
if ( ( runspace . id === 1 || runspace . name === "PSAttachRunspace" )
534
553
&& processId === "current" ) {
@@ -541,12 +560,14 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
541
560
id : runspace . id . toString ( ) ,
542
561
} ) ;
543
562
}
563
+
544
564
const options : vscode . QuickPickOptions = {
545
565
placeHolder : "Select PowerShell runspace to debug" ,
546
566
matchOnDescription : true ,
547
567
matchOnDetail : true ,
548
568
} ;
549
569
const item = await vscode . window . showQuickPick ( items , options ) ;
570
+
550
571
return item ? `${ item . id } ` : undefined ;
551
572
}
552
573
0 commit comments