@@ -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
@@ -254,11 +259,17 @@ export class DebugSessionFeature extends LanguageClientConsumer
254
259
private async resolveAttachDebugConfiguration ( config : DebugConfiguration ) : Promise < DebugConfiguration | undefined | null > {
255
260
const platformDetails = getPlatformDetails ( ) ;
256
261
const versionDetails = this . sessionManager . getPowerShellVersionDetails ( ) ;
262
+ if ( versionDetails === undefined ) {
263
+ vscode . window . showErrorMessage ( `Session version details were not found for ${ config . name } ` )
264
+ return null ;
265
+ }
266
+
257
267
// Cross-platform attach to process was added in 6.2.0-preview.4.
258
268
if ( versionDetails . version < "7.0.0" && platformDetails . operatingSystem !== OperatingSystem . Windows ) {
259
269
vscode . window . showErrorMessage ( `Attaching to a PowerShell Host Process on ${ OperatingSystem [ platformDetails . operatingSystem ] } requires PowerShell 7.0 or higher.` ) ;
260
270
return undefined ;
261
271
}
272
+
262
273
// If nothing is set, prompt for the processId.
263
274
if ( ! config . customPipeName && ! config . processId ) {
264
275
config . processId = await vscode . commands . executeCommand ( "PowerShell.PickPSHostProcess" ) ;
@@ -267,13 +278,15 @@ export class DebugSessionFeature extends LanguageClientConsumer
267
278
return null ;
268
279
}
269
280
}
281
+
270
282
if ( ! config . runspaceId && ! config . runspaceName ) {
271
283
config . runspaceId = await vscode . commands . executeCommand ( "PowerShell.PickRunspace" , config . processId ) ;
272
284
// No runspace selected. Cancel attach.
273
285
if ( ! config . runspaceId ) {
274
286
return null ;
275
287
}
276
288
}
289
+
277
290
return config ;
278
291
}
279
292
}
@@ -341,7 +354,7 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
341
354
342
355
private command : vscode . Disposable ;
343
356
private waitingForClientToken ?: vscode . CancellationTokenSource ;
344
- private getLanguageClientResolve : ( value : LanguageClient ) => void ;
357
+ private getLanguageClientResolve ? : ( value : LanguageClient ) => void ;
345
358
346
359
constructor ( ) {
347
360
super ( ) ;
@@ -356,7 +369,7 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
356
369
public setLanguageClient ( languageClient : LanguageClient ) {
357
370
this . languageClient = languageClient ;
358
371
359
- if ( this . waitingForClientToken ) {
372
+ if ( this . waitingForClientToken && this . getLanguageClientResolve ) {
360
373
this . getLanguageClientResolve ( this . languageClient ) ;
361
374
this . clearWaitingToken ( ) ;
362
375
}
@@ -462,7 +475,7 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
462
475
463
476
private command : vscode . Disposable ;
464
477
private waitingForClientToken ?: vscode . CancellationTokenSource ;
465
- private getLanguageClientResolve : ( value : LanguageClient ) => void ;
478
+ private getLanguageClientResolve ? : ( value : LanguageClient ) => void ;
466
479
467
480
constructor ( ) {
468
481
super ( ) ;
@@ -476,7 +489,7 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
476
489
public setLanguageClient ( languageClient : LanguageClient ) {
477
490
this . languageClient = languageClient ;
478
491
479
- if ( this . waitingForClientToken ) {
492
+ if ( this . waitingForClientToken && this . getLanguageClientResolve ) {
480
493
this . getLanguageClientResolve ( this . languageClient ) ;
481
494
this . clearWaitingToken ( ) ;
482
495
}
@@ -526,7 +539,7 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
526
539
}
527
540
528
541
private async pickRunspace ( processId : string ) : Promise < string | undefined > {
529
- const response = await this . languageClient . sendRequest ( GetRunspaceRequestType , { processId } ) ;
542
+ const response = await this . languageClient ? .sendRequest ( GetRunspaceRequestType , { processId } ) ;
530
543
const items : IRunspaceItem [ ] = [ ] ;
531
544
for ( const runspace of response ) {
532
545
// Skip default runspace
0 commit comments