Skip to content

Commit 47b4c5f

Browse files
committed
Enable debugging of untitled script files
This change enables untitled files to be debugged when they are set to the 'powershell' language mode. Fixes #555.
1 parent 0def0af commit 47b4c5f

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/features/DebugSession.ts

+13-7
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,26 @@ export class DebugSessionFeature implements IFeature {
4141
// For launch of "current script", don't start the debugger if the current file
4242
// is not a file that can be debugged by PowerShell
4343
if (config.script === "${file}") {
44-
let filename = vscode.window.activeTextEditor.document.fileName;
45-
let ext = filename.substr(filename.lastIndexOf('.') + 1);
46-
let langId = vscode.window.activeTextEditor.document.languageId;
47-
if ((langId !== 'powershell') || (ext !== "ps1" && ext !== "psm1")) {
48-
let path = filename;
44+
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;
4952
let workspaceRootPath = vscode.workspace.rootPath;
50-
if (filename.startsWith(workspaceRootPath)) {
51-
path = filename.substring(vscode.workspace.rootPath.length + 1);
53+
if (currentDocument.fileName.startsWith(workspaceRootPath)) {
54+
path = currentDocument.fileName.substring(vscode.workspace.rootPath.length + 1);
5255
}
5356

5457
let msg = "'" + path + "' is a file type that cannot be debugged by the PowerShell debugger.";
5558
vscode.window.showErrorMessage(msg);
5659
return;
5760
}
61+
else if (currentDocument.isUntitled) {
62+
config.script = currentDocument.uri.toString();
63+
}
5864
}
5965
}
6066

0 commit comments

Comments
 (0)