Skip to content

Conversation

@adam2am
Copy link

@adam2am adam2am commented Dec 27, 2025

Summary

  • Fixes LSP tools (lsp_rename, lsp_goto_definition, etc.) failing on Windows with invalid paths
  • Uses Node.js fileURLToPath() instead of naive string replacement

Problem (a cursed treasure map, ARRRR! 🏴‍☠️)

LSP returns file URIs like file:///C:/path/to/file.ts. The old code used:

const filePath = uri.replace("file://", "")

This produces /C:/path/to/file.ts on Windows - invalid path with leading slash!

Input URI Old Output Valid?
file:///C:/Users/test.ts /C:/Users/test.ts
file:///tmp/test.ts /tmp/test.ts ✅ (Unix)

Solution (proper pirate navigation 🦜)

Use Node.js built-in fileURLToPath() from node:url:

  • Correctly handles Windows drive letters (C:)
  • Handles UNC paths (\server\share)
  • Handles URL-encoded characters (%20 → space)
  • Cross-platform compatible

This matches how OpenCode handles it in packages/opencode/src/lsp/client.ts:

import { pathToFileURL, fileURLToPath } from "url"
const filePath = Filesystem.normalizePath(fileURLToPath(params.uri))

Changes

  • Added import: import { fileURLToPath } from "node:url"
  • Added helper: export function uriToPath(uri: string): string
  • Replaced all 10 occurrences of .replace("file://", "")

Testing

  • Build passes ✅
  • Tested on Windows with LSP rename operations

Now Windows users can sail the LSP seas without crashin' on the rocks! 🏴‍☠️

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! 🦜
@github-actions
Copy link
Contributor

github-actions bot commented Dec 27, 2025

All contributors have signed the CLA. Thank you! ✅
Posted by the CLA Assistant Lite bot.

@adam2am
Copy link
Author

adam2am commented Dec 27, 2025

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Dec 27, 2025
@greptile-apps
Copy link

greptile-apps bot commented Dec 27, 2025

Greptile Summary

Fixed LSP tools failing on Windows by replacing naive uri.replace("file://", "") with Node.js built-in fileURLToPath() from node:url. This correctly handles Windows drive letters (C:), UNC paths, and URL-encoded characters across all 10 URI conversion points.

Key changes:

  • Added helper function uriToPath() wrapping fileURLToPath()
  • Replaced all occurrences in formatLocation(), formatWorkspaceEdit(), and applyWorkspaceEdit()
  • Matches existing pattern used elsewhere in codebase (auto-update-checker/checker.ts)

Issues found:

  • Line 368: Indentation broken (missing leading whitespace) - will cause syntax error

Confidence Score: 4/5

  • Safe to merge after fixing indentation error on line 368
  • Implementation is correct and follows Node.js best practices for cross-platform path handling, but contains one syntax error that will break the build
  • Line 368 in src/tools/lsp/utils.ts needs indentation fix before merge

Important Files Changed

Filename Overview
src/tools/lsp/utils.ts Replaced naive string replacement with fileURLToPath() for Windows compatibility, but introduced indentation error on line 368

Sequence Diagram

sequenceDiagram
    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
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Comments (1)

  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

Edit Code Review Agent Settings | Greptile

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Comments (1)

  1. src/tools/lsp/utils.ts, line 368 (link)

    syntax: Indentation broken - missing leading whitespace

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@code-yeongyu
Copy link
Owner

@sisyphus-dev-ai review this, and is there any duplicated code that covers this?

@sisyphus-dev-ai sisyphus-dev-ai added the sisyphus: working Sisyphus is currently working on this label Dec 27, 2025
@sisyphus-dev-ai
Copy link
Collaborator

👋 Hey @code-yeongyu! I'm on it...

@sisyphus-dev-ai
Copy link
Collaborator

Review Summary

✅ Excellent Fix for Windows Compatibility!

The core approach is absolutely correct - using Node.js's built-in fileURLToPath() is the proper, cross-platform way to handle file:// URIs. This will fix LSP tools on Windows.

🔍 Duplicated Code Analysis

YES, there is similar code in the codebase:

Location: src/hooks/auto-update-checker/checker.ts:43-48

if (entry.startsWith("file://") && entry.includes(PACKAGE_NAME)) {
  try {
    return fileURLToPath(entry)
  } catch {
    return entry.replace("file://", "")
  }
}

Key Difference: The checker.ts implementation includes:

  • Error handling (try/catch)
  • Fallback to string replacement if fileURLToPath() throws

Recommendation: Consider adding error handling to your uriToPath() helper:

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 Found

Indentation 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

  • Approve after fixing the indentation issue
  • Consider adding error handling like in checker.ts (optional but recommended)
  • The approach matches Node.js best practices and solves the Windows path problem correctly

Great work on identifying and fixing this Windows compatibility issue! 🎉

@sisyphus-dev-ai sisyphus-dev-ai removed the sisyphus: working Sisyphus is currently working on this label Dec 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants