Skip to content

Commit 974bb1d

Browse files
authored
Fix crash when setBreakpoint from VSCode sends a git:/ URI... (#1000)
* Fix git uri problem * Remove unused imports
1 parent fd77c0d commit 974bb1d

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/PowerShellEditorServices/Workspace/Workspace.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
using System.Text;
1313
using System.Runtime.InteropServices;
1414
using Microsoft.Extensions.FileSystemGlobbing;
15-
using Microsoft.Extensions.FileSystemGlobbing.Abstractions;
1615

1716
namespace Microsoft.PowerShell.EditorServices
1817
{
@@ -49,6 +48,13 @@ public class Workspace
4948
"**/*"
5049
};
5150

51+
private static readonly string[] s_supportedUriSchemes = new[]
52+
{
53+
"file",
54+
"untitled",
55+
"inmemory"
56+
};
57+
5258
private ILogger logger;
5359
private Version powerShellVersion;
5460
private Dictionary<string, ScriptFile> workspaceFiles = new Dictionary<string, ScriptFile>();
@@ -174,6 +180,20 @@ public ScriptFile GetFile(string filePath)
174180
/// <param name="scriptFile">The out parameter that will contain the ScriptFile object.</param>
175181
public bool TryGetFile(string filePath, out ScriptFile scriptFile)
176182
{
183+
try
184+
{
185+
if (filePath.Contains(":/") // Quick heuristic to determine if we might have a URI
186+
&& !s_supportedUriSchemes.Contains(new Uri(filePath).Scheme))
187+
{
188+
scriptFile = null;
189+
return false;
190+
}
191+
}
192+
catch
193+
{
194+
// If something goes wrong trying to check for URIs, just proceed to normal logic
195+
}
196+
177197
try
178198
{
179199
scriptFile = GetFile(filePath);

0 commit comments

Comments
 (0)