Skip to content

Commit fac6e1a

Browse files
committed
Check script extension for current file only
1 parent 3924151 commit fac6e1a

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/features/DebugSession.ts

+11-14
Original file line numberDiff line numberDiff line change
@@ -235,34 +235,31 @@ export class DebugSessionFeature extends LanguageClientConsumer
235235
}
236236

237237
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.
239241
if (config.current_document) {
240242
const currentDocument = vscode.window.activeTextEditor?.document;
241243
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}'.`);
243245
return undefined;
244246
}
245-
}
246247

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?
257248
if (await utils.checkIfFileExists(config.script)) {
258249
const ext = path.extname(config.script).toLowerCase();
259250
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)}'.`);
261252
return undefined;
262253
}
263254
}
264255
}
265256

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+
266263
return config;
267264
}
268265

0 commit comments

Comments
 (0)