Skip to content

Commit cd2cfdd

Browse files
Fix logic checking for untitled or raw scripts (#1839)
This was much more easily accomplished by checking if what we were given exists as a file path, in which case we use it as-is (a file path, that must exist, since we launch it directly). Otherwise we can assume that it's a raw script block, or a URI from the client that probably represents an untitled file.
1 parent 1c167d0 commit cd2cfdd

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/PowerShellEditorServices/Services/DebugAdapter/Handlers/ConfigurationDoneHandler.cs

+7-9
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,13 @@ public Task<ConfigurationDoneResponse> Handle(ConfigurationDoneArguments request
105105
private async Task LaunchScriptAsync(string scriptToLaunch)
106106
{
107107
PSCommand command;
108-
// Script could an actual script, or a URI to a script file (or untitled document).
109-
if (!System.Uri.IsWellFormedUriString(scriptToLaunch, System.UriKind.RelativeOrAbsolute)
110-
|| ScriptFile.IsUntitledPath(scriptToLaunch))
108+
if (System.IO.File.Exists(scriptToLaunch))
109+
{
110+
// For a saved file we just execute its path (after escaping it).
111+
command = PSCommandHelpers.BuildDotSourceCommandWithArguments(
112+
string.Concat('"', scriptToLaunch, '"'), _debugStateService.Arguments);
113+
}
114+
else // It's a URI to an untitled script, or a raw script.
111115
{
112116
bool isScriptFile = _workspaceService.TryGetFile(scriptToLaunch, out ScriptFile untitledScript);
113117
if (isScriptFile && BreakpointApiUtils.SupportsBreakpointApis(_runspaceContext.CurrentRunspace))
@@ -147,12 +151,6 @@ private async Task LaunchScriptAsync(string scriptToLaunch)
147151
_debugStateService.Arguments);
148152
}
149153
}
150-
else
151-
{
152-
// For a saved file we just execute its path (after escaping it).
153-
command = PSCommandHelpers.BuildDotSourceCommandWithArguments(
154-
string.Concat('"', scriptToLaunch, '"'), _debugStateService.Arguments);
155-
}
156154

157155
await _executionService.ExecutePSCommandAsync(
158156
command,

0 commit comments

Comments
 (0)