Skip to content

Commit 22a8272

Browse files
authored
Merge pull request #408 from daviwil/untitled-debugging
Enable debugging of untitled script files
2 parents a003902 + 305c4ac commit 22a8272

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs

+23-3
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,29 @@ protected Task LaunchScript(RequestContext<object> requestContext)
102102
// Ensure the read loop is stopped
103103
this.editorSession.ConsoleService.CancelReadLoop();
104104

105-
return editorSession.PowerShellContext
106-
.ExecuteScriptWithArgs(this.scriptToLaunch, this.arguments, writeInputToHost: true)
107-
.ContinueWith(this.OnExecutionCompleted);
105+
// Is this an untitled script?
106+
Task launchTask = null;
107+
108+
if (this.scriptToLaunch.StartsWith("untitled"))
109+
{
110+
ScriptFile untitledScript =
111+
this.editorSession.Workspace.GetFile(
112+
this.scriptToLaunch);
113+
114+
launchTask =
115+
this.editorSession
116+
.PowerShellContext
117+
.ExecuteScriptString(untitledScript.Contents, true, true);
118+
}
119+
else
120+
{
121+
launchTask =
122+
this.editorSession
123+
.PowerShellContext
124+
.ExecuteScriptWithArgs(this.scriptToLaunch, this.arguments, writeInputToHost: true);
125+
}
126+
127+
return launchTask.ContinueWith(this.OnExecutionCompleted);
108128
}
109129

110130
private async Task OnExecutionCompleted(Task executeTask)

0 commit comments

Comments
 (0)