[PR #10049] fix(lsp): normalize Windows drive letter case for consistent URIs #13314

Open
opened 2026-02-16 18:18:10 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/10049

State: open
Merged: No


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
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/10049 **State:** open **Merged:** No --- ## 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 ```
yindo added the pull-request label 2026-02-16 18:18:10 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13314