@@ -235,34 +235,31 @@ export class DebugSessionFeature extends LanguageClientConsumer
235
235
}
236
236
237
237
private async resolveLaunchDebugConfiguration ( config : DebugConfiguration ) : Promise < DebugConfiguration | undefined > {
238
- // Check the languageId only for current documents (which includes untitled documents).
238
+ // Check the languageId and file extension only for current documents
239
+ // (which includes untitled documents). This prevents accidentally
240
+ // running the debugger for an open non-PowerShell file.
239
241
if ( config . current_document ) {
240
242
const currentDocument = vscode . window . activeTextEditor ?. document ;
241
243
if ( currentDocument ?. languageId !== "powershell" ) {
242
- await vscode . window . showErrorMessage ( "Please change the current document's language mode to PowerShell." ) ;
244
+ void this . logger . writeAndShowError ( `PowerShell does not support debugging this language mode: ' ${ currentDocument ?. languageId } '.` ) ;
243
245
return undefined ;
244
246
}
245
- }
246
247
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
248
if ( await utils . checkIfFileExists ( config . script ) ) {
258
249
const ext = path . extname ( config . script ) . toLowerCase ( ) ;
259
250
if ( ! ( ext === ".ps1" || ext === ".psm1" ) ) {
260
- await vscode . window . showErrorMessage ( `PowerShell does not support debugging this file type: '${ path . basename ( config . script ) } '` ) ;
251
+ void this . logger . writeAndShowError ( `PowerShell does not support debugging this file type: '${ path . basename ( config . script ) } '. ` ) ;
261
252
return undefined ;
262
253
}
263
254
}
264
255
}
265
256
257
+ // Check the temporary console setting for untitled documents only.
258
+ if ( config . untitled_document && config . createTemporaryIntegratedConsole ) {
259
+ void this . logger . writeAndShowError ( "PowerShell does not support debugging untitled files in a temporary console." ) ;
260
+ return undefined ;
261
+ }
262
+
266
263
return config ;
267
264
}
268
265
0 commit comments