diff --git a/src/PowerShellEditorServices/Workspace/Workspace.cs b/src/PowerShellEditorServices/Workspace/Workspace.cs index b9ca0185a..0077af95b 100644 --- a/src/PowerShellEditorServices/Workspace/Workspace.cs +++ b/src/PowerShellEditorServices/Workspace/Workspace.cs @@ -29,6 +29,13 @@ public class Workspace "*.psd1" }; + private static readonly string[] s_supportedUriSchemes = new[] + { + "file", + "untitled", + "inmemory" + }; + private ILogger logger; private Version powerShellVersion; private Dictionary workspaceFiles = new Dictionary(); @@ -142,6 +149,20 @@ public ScriptFile GetFile(string filePath) /// The out parameter that will contain the ScriptFile object. public bool TryGetFile(string filePath, out ScriptFile scriptFile) { + try + { + if (filePath.Contains(":/") // Quick heuristic to determine if we might have a URI + && !s_supportedUriSchemes.Contains(new Uri(filePath).Scheme)) + { + scriptFile = null; + return false; + } + } + catch + { + // If something goes wrong trying to check for URIs, just proceed to normal logic + } + try { scriptFile = GetFile(filePath);