-
-
Notifications
You must be signed in to change notification settings - Fork 249
fix(lsp): use fileURLToPath for Windows path handling #281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
Ahoy! The old code be walkin' the plank on Windows, ARRRR! 🏴☠️
The Problem (a cursed treasure map):
- LSP returns URIs like file:///C:/path/to/file.ts
- Old code: uri.replace("file://", "") produces /C:/path (INVALID on Windows!)
- Windows needs the leadin' slash removed after file:///
The Fix (proper pirate navigation):
- Import fileURLToPath from node:url (the sacred scroll)
- Add uriToPath() helper function (our trusty compass)
- Replace all 10 occurrences of .replace("file://", "")
This matches how the OpenCode mothership handles it in packages/opencode/src/lsp/client.ts
Now Windows users can sail the LSP seas without crashin' on the rocks! 🦜
|
All contributors have signed the CLA. Thank you! ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
Greptile SummaryFixed LSP tools failing on Windows by replacing naive Key changes:
Issues found:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant LSP as LSP Server
participant Utils as utils.ts
participant FS as File System
LSP->>Utils: Return file URI (file:///C:/path/file.ts)
Note over Utils: OLD: uri.replace("file://", "")<br/>Result: /C:/path/file.ts ❌
Note over Utils: NEW: fileURLToPath(uri)<br/>Result: C:\path\file.ts ✅
Utils->>Utils: uriToPath(uri)
Utils->>Utils: fileURLToPath(uri)
alt formatLocation
Utils->>Utils: Convert targetUri/uri to path
end
alt formatWorkspaceEdit
Utils->>Utils: Convert URI keys to paths
end
alt applyWorkspaceEdit
Utils->>Utils: Convert URIs to paths
Utils->>FS: Read/Write/Delete files
FS-->>Utils: Success/Error
end
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional Comments (1)
-
src/tools/lsp/utils.ts, line 368 (link)syntax: Missing indentation - this line should have 12 spaces at the start to match the surrounding code
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
1 file reviewed, 1 comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional Comments (1)
-
src/tools/lsp/utils.ts, line 368 (link)syntax: Indentation broken - missing leading whitespace
1 file reviewed, 1 comment
|
@sisyphus-dev-ai review this, and is there any duplicated code that covers this? |
|
👋 Hey @code-yeongyu! I'm on it... |
Review Summary✅ Excellent Fix for Windows Compatibility!The core approach is absolutely correct - using Node.js's built-in 🔍 Duplicated Code AnalysisYES, there is similar code in the codebase: Location: if (entry.startsWith("file://") && entry.includes(PACKAGE_NAME)) {
try {
return fileURLToPath(entry)
} catch {
return entry.replace("file://", "")
}
}Key Difference: The
Recommendation: Consider adding error handling to your export function uriToPath(uri: string): string {
try {
return fileURLToPath(uri)
} catch (err) {
// LSP servers should always return valid file:// URIs
// but log if we encounter invalid ones
console.warn(`Invalid file URI from LSP: ${uri}`, err)
// Fallback to naive replacement as last resort
return uri.replace("file://", "")
}
}However, if LSP servers are guaranteed to return valid URIs (which they should), the simpler implementation without error handling is also acceptable. 🐛 Critical Issue FoundIndentation error on line 368 (as noted by Greptile): - const oldPath = uriToPath(change.oldUri)
+ const oldPath = uriToPath(change.oldUri)This line needs 12 spaces of indentation to match the surrounding code. This will cause a syntax error and must be fixed before merge. ✅ Verdict
Great work on identifying and fixing this Windows compatibility issue! 🎉 |
Summary
lsp_rename,lsp_goto_definition, etc.) failing on Windows with invalid pathsfileURLToPath()instead of naive string replacementProblem (a cursed treasure map, ARRRR! 🏴☠️)
LSP returns file URIs like
file:///C:/path/to/file.ts. The old code used:This produces
/C:/path/to/file.tson Windows - invalid path with leading slash!file:///C:/Users/test.ts/C:/Users/test.tsfile:///tmp/test.ts/tmp/test.tsSolution (proper pirate navigation 🦜)
Use Node.js built-in
fileURLToPath()fromnode:url:C:)\server\share)%20→ space)This matches how OpenCode handles it in
packages/opencode/src/lsp/client.ts:Changes
import { fileURLToPath } from "node:url"export function uriToPath(uri: string): string.replace("file://", "")Testing
Now Windows users can sail the LSP seas without crashin' on the rocks! 🏴☠️