Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fac6e1a

Browse files
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

Lines changed: 11 additions & 14 deletions
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-
awaitvscode.window.showErrorMessage("Please change the current document's language mode to PowerShell.");
244+
voidthis.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-
awaitvscode.window.showErrorMessage(`PowerShell does not support debugging this file type: '${path.basename(config.script)}'`);
251+
voidthis.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)

AltStyle によって変換されたページ (->オリジナル) /