diff --git a/src/PowerShellEditorServices/Workspace/Workspace.cs b/src/PowerShellEditorServices/Workspace/Workspace.cs index 34cb0d641..e063877be 100644 --- a/src/PowerShellEditorServices/Workspace/Workspace.cs +++ b/src/PowerShellEditorServices/Workspace/Workspace.cs @@ -12,7 +12,6 @@ using System.Text; using System.Runtime.InteropServices; using Microsoft.Extensions.FileSystemGlobbing; -using Microsoft.Extensions.FileSystemGlobbing.Abstractions; namespace Microsoft.PowerShell.EditorServices { @@ -49,6 +48,13 @@ public class Workspace "**/*" }; + private static readonly string[] s_supportedUriSchemes = new[] + { + "file", + "untitled", + "inmemory" + }; + private ILogger logger; private Version powerShellVersion; private Dictionary workspaceFiles = new Dictionary(); @@ -174,6 +180,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);