PowerShell / PowerShellEditorServices

A common platform for PowerShell development support in any editor or application!
MIT License
616 stars 209 forks source link

Debugger relies on case-insensitive paths #2047

Open andyleejordan opened 11 months ago

andyleejordan commented 11 months ago

This odd behavior was first noticed in a test:

https://github.com/PowerShell/PowerShellEditorServices/blob/bfe334df7e4bdd4b92c5c0319655e40444e185ff/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs#L140-L141

It turns out that the URIs and paths we're receiving "over the wire" (in the raw LSP requests themselves) are mostly cased correctly, with the exception of driver letters being lower case. Because of this, when https://github.com/PowerShell/PowerShell/issues/20057 was temporarily fixed by making PowerShell's debugger's _pendingBreakpoints collection case-sensitive, it broke the extension's debugger https://github.com/PowerShell/vscode-powershell/issues/4668.

We need to figure out why those drive letters are coming over lower-case, as the rest of the Windows ecosystem doesn't expect drive letters to be lowercase. Worst case scenario is that we fix the casing as we handle the request, but I'd like to see where the issue originates (thinking perhaps in the LSP client library...) and try to fix it there. Though technically c:/ is valid, and it's mostly PowerShell that's caring about it not being C:/.

andyleejordan commented 11 months ago

Well would you look at that, someone somewhere is enforcing this behavior:

https://github.com/OmniSharp/csharp-language-server-protocol/blob/ca7b9ce52dd43d57d05673ffdca8cfff6bf7fba0/test/Lsp.Tests/VsCodeDocumentUriTests.cs#L438-L447

andyleejordan commented 11 months ago

Yup, it's an intentional VS Code design decision which means I doubt I can get it fixed upstream: https://github.com/Microsoft/vscode/issues/40057

andyleejordan commented 11 months ago

Per @jrieken in https://github.com/Microsoft/vscode/issues/68325#issuecomment-462239992, this has been brought up as breaking others before, but the decision is "something we cannot change anymore."

In summary, this isn't something PSES or vscode-powershell is doing wrong, it's a consequence of receiving URIs from VS Code where they enforce the drive-letter being lowercase, and this does not match up with PowerShell's own expectation that the drive-letter is upper-case. So @fflaten I think that when https://github.com/PowerShell/PowerShell/issues/20057 is fixed to support distinguishing files in the PowerShell debugger on case-sensitive filesystems, the simplest answer is to fix it only when on a case-sensitive filesystem.

I don't like the idea of trying to handle this in PSES be re-upper-casing drive letters in each and every handler; we're going to miss something and things will suspiciously break again.