Skip to content

Commit bf3573e

Browse files
authored
Merge pull request PowerShell#638 from daviwil/untitled-debugging
Enable debugging of untitled script files
2 parents adcf152 + 7096fe2 commit bf3573e

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

examples/.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
// Use a custom PowerShell Script Analyzer settings file for this workspace.
33
// Relative paths for this setting are always relative to the workspace root dir.
4-
"powershell.scriptAnalysis.settingsPath": "./PSScriptAnalyzerSettings.psd1"
4+
"powershell.scriptAnalysis.settingsPath": "./PSScriptAnalyzerSettings.psd1",
5+
"files.defaultLanguage": "powershell"
56
}

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)