Skip to content

Commit 18ca702

Browse files
authored
Fix detection of valid PS ext for debugging. (#642)
* Fix detection of valid PS ext for debugging. Was previously only allowing lower case ps1 and psm1. I'm assuming that on *nix file systems, that PowerShell allows all variations of ps1,PS1,pS1,Ps1 as valid script extensions. Fix #641 * Fix issue with debugging unsaved file. * Use same term used in the command palette. * Shorten error message based on juneb feedback.
1 parent 10029b9 commit 18ca702

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

src/features/DebugSession.ts

+29-16
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,37 @@ export class DebugSessionFeature implements IFeature {
4242
// is not a file that can be debugged by PowerShell
4343
if (config.script === "${file}") {
4444
let currentDocument = vscode.window.activeTextEditor.document;
45-
let ext =
46-
currentDocument.fileName.substr(
47-
currentDocument.fileName.lastIndexOf('.') + 1);
48-
49-
if ((currentDocument.languageId !== 'powershell') ||
50-
(!currentDocument.isUntitled) && (ext !== "ps1" && ext !== "psm1")) {
51-
let path = currentDocument.fileName;
52-
let workspaceRootPath = vscode.workspace.rootPath;
53-
if (currentDocument.fileName.startsWith(workspaceRootPath)) {
54-
path = currentDocument.fileName.substring(vscode.workspace.rootPath.length + 1);
55-
}
5645

57-
let msg = "'" + path + "' is a file type that cannot be debugged by the PowerShell debugger.";
58-
vscode.window.showErrorMessage(msg);
59-
return;
46+
if (currentDocument.isUntitled) {
47+
if (currentDocument.languageId === 'powershell') {
48+
config.script = currentDocument.uri.toString();
49+
}
50+
else {
51+
let msg = "To debug '" + currentDocument.fileName +
52+
"', change the document's language mode to PowerShell or save the file with a PowerShell extension.";
53+
vscode.window.showErrorMessage(msg);
54+
return;
55+
}
6056
}
61-
else if (currentDocument.isUntitled) {
62-
config.script = currentDocument.uri.toString();
57+
else {
58+
let isValidExtension = false;
59+
let extIndex = currentDocument.fileName.lastIndexOf('.');
60+
if (extIndex !== -1) {
61+
let ext = currentDocument.fileName.substr(extIndex + 1).toUpperCase();
62+
isValidExtension = (ext === "PS1" || ext === "PSM1");
63+
}
64+
65+
if ((currentDocument.languageId !== 'powershell') || !isValidExtension) {
66+
let path = currentDocument.fileName;
67+
let workspaceRootPath = vscode.workspace.rootPath;
68+
if (currentDocument.fileName.startsWith(workspaceRootPath)) {
69+
path = currentDocument.fileName.substring(vscode.workspace.rootPath.length + 1);
70+
}
71+
72+
let msg = "'" + path + "' is a file type that cannot be debugged by the PowerShell debugger.";
73+
vscode.window.showErrorMessage(msg);
74+
return;
75+
}
6376
}
6477
}
6578
}

0 commit comments

Comments
 (0)