Skip to content

Commit cd0e7bc

Browse files
committed
Fix crash when setBreakpoint from VSCode sends a git:/ URI... (PowerShell#1000)
* Fix git uri problem * Remove unused imports
1 parent 4518fa1 commit cd0e7bc

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/PowerShellEditorServices/Workspace/Workspace.cs

+21
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ public class Workspace
2929
"*.psd1"
3030
};
3131

32+
private static readonly string[] s_supportedUriSchemes = new[]
33+
{
34+
"file",
35+
"untitled",
36+
"inmemory"
37+
};
38+
3239
private ILogger logger;
3340
private Version powerShellVersion;
3441
private Dictionary<string, ScriptFile> workspaceFiles = new Dictionary<string, ScriptFile>();
@@ -142,6 +149,20 @@ public ScriptFile GetFile(string filePath)
142149
/// <param name="scriptFile">The out parameter that will contain the ScriptFile object.</param>
143150
public bool TryGetFile(string filePath, out ScriptFile scriptFile)
144151
{
152+
try
153+
{
154+
if (filePath.Contains(":/") // Quick heuristic to determine if we might have a URI
155+
&& !s_supportedUriSchemes.Contains(new Uri(filePath).Scheme))
156+
{
157+
scriptFile = null;
158+
return false;
159+
}
160+
}
161+
catch
162+
{
163+
// If something goes wrong trying to check for URIs, just proceed to normal logic
164+
}
165+
145166
try
146167
{
147168
scriptFile = GetFile(filePath);

0 commit comments

Comments
 (0)