From 3ed75dc3f0e24fe99da7c229d83825beff0a4284 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 22 Jun 2022 12:12:20 -0700 Subject: [PATCH] Fix logic checking for untitled or raw scripts 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. --- .../Handlers/ConfigurationDoneHandler.cs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/PowerShellEditorServices/Services/DebugAdapter/Handlers/ConfigurationDoneHandler.cs b/src/PowerShellEditorServices/Services/DebugAdapter/Handlers/ConfigurationDoneHandler.cs index b1bc42142..2cfc24a2d 100644 --- a/src/PowerShellEditorServices/Services/DebugAdapter/Handlers/ConfigurationDoneHandler.cs +++ b/src/PowerShellEditorServices/Services/DebugAdapter/Handlers/ConfigurationDoneHandler.cs @@ -105,9 +105,13 @@ public Task Handle(ConfigurationDoneArguments request private async Task LaunchScriptAsync(string scriptToLaunch) { PSCommand command; - // Script could an actual script, or a URI to a script file (or untitled document). - if (!System.Uri.IsWellFormedUriString(scriptToLaunch, System.UriKind.RelativeOrAbsolute) - || ScriptFile.IsUntitledPath(scriptToLaunch)) + if (System.IO.File.Exists(scriptToLaunch)) + { + // For a saved file we just execute its path (after escaping it). + command = PSCommandHelpers.BuildDotSourceCommandWithArguments( + string.Concat('"', scriptToLaunch, '"'), _debugStateService.Arguments); + } + else // It's a URI to an untitled script, or a raw script. { bool isScriptFile = _workspaceService.TryGetFile(scriptToLaunch, out ScriptFile untitledScript); if (isScriptFile && BreakpointApiUtils.SupportsBreakpointApis(_runspaceContext.CurrentRunspace)) @@ -147,12 +151,6 @@ private async Task LaunchScriptAsync(string scriptToLaunch) _debugStateService.Arguments); } } - else - { - // For a saved file we just execute its path (after escaping it). - command = PSCommandHelpers.BuildDotSourceCommandWithArguments( - string.Concat('"', scriptToLaunch, '"'), _debugStateService.Arguments); - } await _executionService.ExecutePSCommandAsync( command,