fix(lsp): normalize Windows drive-letter paths from URIs - #3376
Open
H-TTTTT wants to merge 1 commit into
Open
Conversation
Converting a LSP file URI back to a filesystem path could leave a leading path separator in front of a Windows drive letter (e.g. "\G:\foo" instead of "G:\foo"), producing an invalid root-relative/UNC-style path. This caused file refreshes and edits to fail with "The filename, directory name, or volume label syntax is incorrect" on Windows (charmbracelet#3089). Centralize URI-to-path conversion in util.PathFromURI, which strips a stray leading separator before a drive letter, and route all URI->path conversions (RefreshOpenFiles, edit application, and LSP tool result formatting) through it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On Windows, converting a LSP file URI back to a filesystem path could leave a leading path separator in front of the drive letter (e.g.
\G:\fooinstead ofG:\foo). Such paths are invalid on Windows — a leading separator turns them into root-relative or UNC-style paths — so file refreshes and edit application failed with:This broke LSP file sync/refresh on Windows (reported with the codely-unity LSP).
Root cause
protocol.DocumentURI.Path()returns the raw URI path (/G:/...) and appliesfilepath.FromSlash, but the leading separator before a Windows drive letter is only stripped when the drive-letter detection succeeds. When it does not, the result keeps the leading separator, which becomes\after slash conversion, yielding\G:\....Changes
internal/lsp/util/PathFromURI, which converts aprotocol.DocumentURIto a path and strips a stray leading path separator in front of a Windows drive letter.RefreshOpenFiles, edit application (util/edit.go), and the LSP tools that format locations (definition, references, call hierarchy, affected-file collection).Fixes #3089