@@ -81,8 +81,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
81
81
: this . sessionManager . getSessionDetails ( ) ;
82
82
83
83
if ( sessionDetails === undefined ) {
84
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
85
- this . logger . writeAndShowError ( `No session details available for ${ session . name } ` ) ;
84
+ void this . logger . writeAndShowError ( `PowerShell session details not available for ${ session . name } ` ) ;
86
85
return ;
87
86
}
88
87
@@ -103,17 +102,15 @@ export class DebugSessionFeature extends LanguageClientConsumer
103
102
languageClient . onNotification (
104
103
StartDebuggerNotificationType ,
105
104
// TODO: Use a named debug configuration.
106
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
107
- ( ) => vscode . debug . startDebugging ( undefined , {
105
+ ( ) => void vscode . debug . startDebugging ( undefined , {
108
106
request : "launch" ,
109
107
type : "PowerShell" ,
110
108
name : "PowerShell: Interactive Session"
111
109
} ) ) ,
112
110
113
111
languageClient . onNotification (
114
112
StopDebuggerNotificationType ,
115
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
116
- ( ) => vscode . debug . stopDebugging ( undefined ) )
113
+ ( ) => void vscode . debug . stopDebugging ( undefined ) )
117
114
] ;
118
115
}
119
116
@@ -192,7 +189,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
192
189
193
190
if ( config . script === "${file}" || config . script === "${relativeFile}" ) {
194
191
if ( vscode . window . activeTextEditor === undefined ) {
195
- await vscode . window . showErrorMessage ( "To debug the 'Current File', you must first open a PowerShell script file in the editor." ) ;
192
+ void this . logger . writeAndShowError ( "To debug the 'Current File', you must first open a PowerShell script file in the editor." ) ;
196
193
return undefined ;
197
194
}
198
195
config . current_document = true ;
@@ -218,7 +215,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
218
215
} else if ( config . request === "launch" ) {
219
216
resolvedConfig = await this . resolveLaunchDebugConfiguration ( config ) ;
220
217
} else {
221
- await vscode . window . showErrorMessage ( `The request type was invalid: '${ config . request } '`) ;
218
+ void this . logger . writeAndShowError ( `PowerShell debug configuration's request type was invalid: '${ config . request } '. `) ;
222
219
return null ;
223
220
}
224
221
@@ -235,48 +232,45 @@ export class DebugSessionFeature extends LanguageClientConsumer
235
232
}
236
233
237
234
private async resolveLaunchDebugConfiguration ( config : DebugConfiguration ) : Promise < DebugConfiguration | undefined > {
238
- // Check the languageId only for current documents (which includes untitled documents).
235
+ // Check the languageId and file extension only for current documents
236
+ // (which includes untitled documents). This prevents accidentally
237
+ // running the debugger for an open non-PowerShell file.
239
238
if ( config . current_document ) {
240
239
const currentDocument = vscode . window . activeTextEditor ?. document ;
241
240
if ( currentDocument ?. languageId !== "powershell" ) {
242
- await vscode . window . showErrorMessage ( "Please change the current document's language mode to PowerShell." ) ;
241
+ void this . logger . writeAndShowError ( `PowerShell does not support debugging this language mode: ' ${ currentDocument ?. languageId } '.` ) ;
243
242
return undefined ;
244
243
}
245
- }
246
244
247
- // Check the temporary console setting for untitled documents only, and
248
- // check the document extension for if the script is an extant file (it
249
- // could be inline).
250
- if ( config . untitled_document ) {
251
- if ( config . createTemporaryIntegratedConsole ) {
252
- await vscode . window . showErrorMessage ( "Debugging untitled files in a temporary console is not supported." ) ;
253
- return undefined ;
254
- }
255
- } else if ( config . script ) {
256
- // TODO: Why even bother with this complexity?
257
245
if ( await utils . checkIfFileExists ( config . script ) ) {
258
246
const ext = path . extname ( config . script ) . toLowerCase ( ) ;
259
247
if ( ! ( ext === ".ps1" || ext === ".psm1" ) ) {
260
- await vscode . window . showErrorMessage ( `PowerShell does not support debugging this file type: '${ path . basename ( config . script ) } '` ) ;
248
+ void this . logger . writeAndShowError ( `PowerShell does not support debugging this file type: '${ path . basename ( config . script ) } '. ` ) ;
261
249
return undefined ;
262
250
}
263
251
}
264
252
}
265
253
254
+ // Check the temporary console setting for untitled documents only.
255
+ if ( config . untitled_document && config . createTemporaryIntegratedConsole ) {
256
+ void this . logger . writeAndShowError ( "PowerShell does not support debugging untitled files in a temporary console." ) ;
257
+ return undefined ;
258
+ }
259
+
266
260
return config ;
267
261
}
268
262
269
263
private async resolveAttachDebugConfiguration ( config : DebugConfiguration ) : Promise < DebugConfiguration | undefined | null > {
270
264
const platformDetails = getPlatformDetails ( ) ;
271
265
const versionDetails = this . sessionManager . getPowerShellVersionDetails ( ) ;
272
266
if ( versionDetails === undefined ) {
273
- await vscode . window . showErrorMessage ( `Session version details were not found for ${ config . name } `) ;
267
+ void this . logger . writeAndShowError ( `PowerShell session version details were not found for ' ${ config . name } '. `) ;
274
268
return null ;
275
269
}
276
270
277
271
// Cross-platform attach to process was added in 6.2.0-preview.4.
278
272
if ( versionDetails . version < "7.0.0" && platformDetails . operatingSystem !== OperatingSystem . Windows ) {
279
- await vscode . window . showErrorMessage ( `Attaching to a PowerShell Host Process on ${ OperatingSystem [ platformDetails . operatingSystem ] } requires PowerShell 7.0 or higher.` ) ;
273
+ void this . logger . writeAndShowError ( `Attaching to a PowerShell Host Process on ${ OperatingSystem [ platformDetails . operatingSystem ] } requires PowerShell 7.0 or higher.` ) ;
280
274
return undefined ;
281
275
}
282
276
@@ -309,10 +303,9 @@ export class SpecifyScriptArgsFeature implements vscode.Disposable {
309
303
constructor ( context : vscode . ExtensionContext ) {
310
304
this . context = context ;
311
305
312
- this . command =
313
- vscode . commands . registerCommand ( "PowerShell.SpecifyScriptArgs" , ( ) => {
314
- return this . specifyScriptArguments ( ) ;
315
- } ) ;
306
+ this . command = vscode . commands . registerCommand ( "PowerShell.SpecifyScriptArgs" , ( ) => {
307
+ return this . specifyScriptArguments ( ) ;
308
+ } ) ;
316
309
}
317
310
318
311
public dispose ( ) {
@@ -366,7 +359,7 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
366
359
private waitingForClientToken ?: vscode . CancellationTokenSource ;
367
360
private getLanguageClientResolve ?: ( value : LanguageClient ) => void ;
368
361
369
- constructor ( ) {
362
+ constructor ( private logger : Logger ) {
370
363
super ( ) ;
371
364
372
365
this . command =
@@ -401,7 +394,6 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
401
394
( resolve , reject ) => {
402
395
this . getLanguageClientResolve = resolve ;
403
396
404
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
405
397
vscode . window
406
398
. showQuickPick (
407
399
[ "Cancel" ] ,
@@ -412,17 +404,15 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
412
404
this . clearWaitingToken ( ) ;
413
405
reject ( ) ;
414
406
}
415
- } ) ;
407
+ } , undefined ) ;
416
408
417
409
// Cancel the loading prompt after 60 seconds
418
410
setTimeout ( ( ) => {
419
411
if ( this . waitingForClientToken ) {
420
412
this . clearWaitingToken ( ) ;
421
413
reject ( ) ;
422
414
423
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
424
- vscode . window . showErrorMessage (
425
- "Attach to PowerShell host process: PowerShell session took too long to start." ) ;
415
+ void this . logger . writeAndShowError ( "Attach to PowerShell host process: PowerShell session took too long to start." ) ;
426
416
}
427
417
} , 60000 ) ;
428
418
} ,
@@ -495,7 +485,7 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
495
485
private waitingForClientToken ?: vscode . CancellationTokenSource ;
496
486
private getLanguageClientResolve ?: ( value : LanguageClient ) => void ;
497
487
498
- constructor ( ) {
488
+ constructor ( private logger : Logger ) {
499
489
super ( ) ;
500
490
this . command =
501
491
vscode . commands . registerCommand ( "PowerShell.PickRunspace" , ( processId ) => {
@@ -529,7 +519,6 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
529
519
( resolve , reject ) => {
530
520
this . getLanguageClientResolve = resolve ;
531
521
532
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
533
522
vscode . window
534
523
. showQuickPick (
535
524
[ "Cancel" ] ,
@@ -540,17 +529,15 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
540
529
this . clearWaitingToken ( ) ;
541
530
reject ( ) ;
542
531
}
543
- } ) ;
532
+ } , undefined ) ;
544
533
545
534
// Cancel the loading prompt after 60 seconds
546
535
setTimeout ( ( ) => {
547
536
if ( this . waitingForClientToken ) {
548
537
this . clearWaitingToken ( ) ;
549
538
reject ( ) ;
550
539
551
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
552
- vscode . window . showErrorMessage (
553
- "Attach to PowerShell host process: PowerShell session took too long to start." ) ;
540
+ void this . logger . writeAndShowError ( "Attach to PowerShell host process: PowerShell session took too long to start." ) ;
554
541
}
555
542
} , 60000 ) ;
556
543
} ,
0 commit comments