Skip to content

fix(lsp): normalize Windows drive letter case for consistent URIs#10049

Open
yimingll wants to merge 1 commit intoanomalyco:devfrom
yimingll:fix/windows-uri-case-sensitivity
Open

fix(lsp): normalize Windows drive letter case for consistent URIs#10049
yimingll wants to merge 1 commit intoanomalyco:devfrom
yimingll:fix/windows-uri-case-sensitivity

Conversation

@yimingll
Copy link

Summary

Fixes the "unresolvable URI" error on Windows when using LSP operations like lsp_document_symbols, lsp_hover, etc.

Problem

On Windows, drive letters are case-insensitive (D: and d: refer to the same drive), but:

  1. pathToFileURL() preserves the original casing of the drive letter
  2. Different code paths may pass paths with different drive letter casing
  3. When the LSP server receives a URI like file:///d:/path but internally tracks file:///D:/path, it can't find the document

Additionally, URL.pathname on Windows returns /D:/path with a leading slash, which is an invalid Windows path.

Solution

  1. Add normalizePathForUri() function that uppercases drive letters on Windows before converting to URI
  2. Replace new URL(uri).pathname with fileURLToPath(uri) which properly handles Windows paths
  3. Apply normalization consistently to all LSP operations that generate file URIs

Changes

  • packages/opencode/src/tool/lsp.ts: Normalize path before generating URI in the LSP tool
  • packages/opencode/src/lsp/index.ts:
    • Add normalizePathForUri() helper
    • Fix documentSymbol() to use fileURLToPath() instead of URL.pathname
    • Apply normalization to hover(), definition(), references(), implementation(), prepareCallHierarchy(), incomingCalls(), outgoingCalls()

Testing

Tested on Windows with clangd LSP server. Before this fix:

lsp_document_symbols with filePath: D:\project\file.cpp
→ Error: unresolvable URI

After this fix:

lsp_document_symbols with filePath: D:\project\file.cpp
→ Returns document symbols correctly

On Windows, drive letters are case-insensitive (D: == d:), but
pathToFileURL() preserves the original casing. This causes URI
mismatches when comparing URIs from different sources.

Changes:
- Add normalizePathForUri() to uppercase drive letters on Windows
- Fix documentSymbol() to use fileURLToPath() instead of URL.pathname
  (URL.pathname returns /D:/path on Windows which is invalid)
- Apply normalization to all LSP operations that generate file URIs

Fixes: unresolvable URI error on Windows for lsp_document_symbols
@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

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.

1 participant