Skip to content

Commit 9bf0c23

Browse files
committed
Fix error when debugging untitled script with no launch.json
This change fixes an issue which causes and error to appear in the integrated console when debugging an untitled file without a launch.json configuration. The fix is to use the full Uri path when crafting a launch config for an untitled file. Resolves PowerShell#648.
1 parent 030cbf7 commit 9bf0c23

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/features/DebugSession.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,19 @@ export class DebugSessionFeature implements IFeature {
2525

2626
private startDebugSession(config: any) {
2727

28+
let currentDocument = vscode.window.activeTextEditor.document;
29+
2830
if (!config.request) {
2931
// No launch.json, create the default configuration
3032
config.type = 'PowerShell';
3133
config.name = 'PowerShell Launch Current File';
3234
config.request = 'launch';
3335
config.args = [];
34-
config.script = vscode.window.activeTextEditor.document.fileName;
36+
37+
config.script =
38+
currentDocument.isUntitled
39+
? currentDocument.uri.toString()
40+
: currentDocument.fileName;
3541
}
3642

3743
if (config.request === 'launch') {
@@ -41,7 +47,6 @@ export class DebugSessionFeature implements IFeature {
4147
// For launch of "current script", don't start the debugger if the current file
4248
// is not a file that can be debugged by PowerShell
4349
if (config.script === "${file}") {
44-
let currentDocument = vscode.window.activeTextEditor.document;
4550

4651
if (currentDocument.isUntitled) {
4752
if (currentDocument.languageId === 'powershell') {

0 commit comments

Comments
 (0)