Skip to content

Fix detection of valid PS ext for debugging. #642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 2, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 29 additions & 16 deletions src/features/DebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,37 @@ export class DebugSessionFeature implements IFeature {
// is not a file that can be debugged by PowerShell
if (config.script === "${file}") {
let currentDocument = vscode.window.activeTextEditor.document;
let ext =
currentDocument.fileName.substr(
currentDocument.fileName.lastIndexOf('.') + 1);

if ((currentDocument.languageId !== 'powershell') ||
(!currentDocument.isUntitled) && (ext !== "ps1" && ext !== "psm1")) {
let path = currentDocument.fileName;
let workspaceRootPath = vscode.workspace.rootPath;
if (currentDocument.fileName.startsWith(workspaceRootPath)) {
path = currentDocument.fileName.substring(vscode.workspace.rootPath.length + 1);
}

let msg = "'" + path + "' is a file type that cannot be debugged by the PowerShell debugger.";
vscode.window.showErrorMessage(msg);
return;
if (currentDocument.isUntitled) {
if (currentDocument.languageId === 'powershell') {
config.script = currentDocument.uri.toString();
}
else {
let msg = "To debug '" + currentDocument.fileName +
"', change the document's language mode to PowerShell or save the file with a PowerShell extension.";
vscode.window.showErrorMessage(msg);
return;
}
}
else if (currentDocument.isUntitled) {
config.script = currentDocument.uri.toString();
else {
let isValidExtension = false;
let extIndex = currentDocument.fileName.lastIndexOf('.');
if (extIndex !== -1) {
let ext = currentDocument.fileName.substr(extIndex + 1).toUpperCase();
isValidExtension = (ext === "PS1" || ext === "PSM1");
}

if ((currentDocument.languageId !== 'powershell') || !isValidExtension) {
let path = currentDocument.fileName;
let workspaceRootPath = vscode.workspace.rootPath;
if (currentDocument.fileName.startsWith(workspaceRootPath)) {
path = currentDocument.fileName.substring(vscode.workspace.rootPath.length + 1);
}

let msg = "'" + path + "' is a file type that cannot be debugged by the PowerShell debugger.";
vscode.window.showErrorMessage(msg);
return;
}
}
}
}
Expand Down