Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when setBreakpoint from VSCode sends a git:/ URI... (#1000) #1012

Merged
merged 1 commit into from
Aug 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/PowerShellEditorServices/Workspace/Workspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, ScriptFile> workspaceFiles = new Dictionary<string, ScriptFile>();
Expand Down Expand Up @@ -142,6 +149,20 @@ public ScriptFile GetFile(string filePath)
/// <param name="scriptFile">The out parameter that will contain the ScriptFile object.</param>
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);
Expand Down