Skip to content

fix(lsp): normalize Windows drive-letter paths from URIs - #3376

Open
H-TTTTT wants to merge 1 commit into
charmbracelet:mainfrom
H-TTTTT:fix/lsp-windows-path
Open

fix(lsp): normalize Windows drive-letter paths from URIs#3376
H-TTTTT wants to merge 1 commit into
charmbracelet:mainfrom
H-TTTTT:fix/lsp-windows-path

Conversation

@H-TTTTT

@H-TTTTT H-TTTTT commented Jul 20, 2026

Copy link
Copy Markdown

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:\foo instead of G:\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:

open \\G:\\_AIXM\\AIXMUnity\\Assets\\Scripts\\Core\\GameManager.cs:
The filename, directory name, or volume label syntax is incorrect.

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 applies filepath.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

  • Add internal/lsp/util/PathFromURI, which converts a protocol.DocumentURI to a path and strips a stray leading path separator in front of a Windows drive letter.
  • Route every URI to filesystem-path conversion through it: LSP RefreshOpenFiles, edit application (util/edit.go), and the LSP tools that format locations (definition, references, call hierarchy, affected-file collection).
  • Add unit tests for the normalization.

Fixes #3089

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LSP Windows11 路径格式错误 ( \\G:\... )

1 participant