Skip to content

Commit 928d9d8

Browse files
committed
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
1 parent 10029b9 commit 928d9d8

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

src/features/DebugSession.ts

+21-16
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,30 @@ 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;
60-
}
61-
else if (currentDocument.isUntitled) {
46+
if (currentDocument.isUntitled) {
6247
config.script = currentDocument.uri.toString();
6348
}
49+
else {
50+
let isValidExtension = false;
51+
let extIndex = currentDocument.fileName.lastIndexOf('.');
52+
if (extIndex !== -1) {
53+
let ext = currentDocument.fileName.substr(extIndex + 1).toUpperCase();
54+
isValidExtension = (ext === "PS1" || ext === "PSM1");
55+
}
56+
57+
if ((currentDocument.languageId !== 'powershell') || !isValidExtension) {
58+
let path = currentDocument.fileName;
59+
let workspaceRootPath = vscode.workspace.rootPath;
60+
if (currentDocument.fileName.startsWith(workspaceRootPath)) {
61+
path = currentDocument.fileName.substring(vscode.workspace.rootPath.length + 1);
62+
}
63+
64+
let msg = "'" + path + "' is a file type that cannot be debugged by the PowerShell debugger.";
65+
vscode.window.showErrorMessage(msg);
66+
return;
67+
}
68+
}
6469
}
6570
}
6671

0 commit comments

Comments
 (0)