-
Notifications
You must be signed in to change notification settings - Fork 223
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
Conversation
Wait, it looks like we already have a test for a path like this and it's expected as a possible in-memory input path: PowerShellEditorServices/test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs Line 163 in fd77c0d
@rkeithhill is it possible this is already fixed? |
@rjmholt multiple folks mentioned the debug adapter in the issues... it could be a different code path? |
@@ -174,6 +180,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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought I had suggested a code change like this before but we eventually decided that the GetFile()
call on line 199 would throw in this case and we'd return false. That said, I'd rather test this in a way that doesn't rely on catching an exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry @rkeithhill, are you for this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My worry is that there seems to be a test that exists already for a git:/
schemed file. My change would just reject those (and anything else that isn't file
, untitled
or inmemory
). The fact that we already have a test for this makes me feel like there is an expectation that we can understand and handle a URI like this -- does that seem right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those tests for git:/
and gitlens-git:/
look like my tests. I think the intent here was to have those uri schemes return true for IsInMemory which we used to signal that you can't do things like set breakpoints with an "in memory" document. In retrospect, perhaps that is not the best approach RE the way we used IsInMemory but the basic idea was to determine whether or not we had a file path we could provide to Set-PSBreakpoint
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In an ideal design, I could walk up to the ScriptFile/EditorDocument and query a property like CanHaveBreakpoints
or something like that to determine whether or not an LSP text document could have a breakpoint set on it. But I think this is good as a stop-gap. Ship it!
The stack trace I'm working against looks like this:
So |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…hell#1000) * Fix git uri problem * Remove unused imports
Fixes PowerShell/vscode-powershell#1994