Skip to content

Go to definition shows duplicate definitions due to URI different between file:///c%3A/ and file:///c:/ on Windows #3285

Closed

Description

@son-urban

Description

On Windows, the "Go to Definition" feature shows duplicate entries for the same definition due to differences in the URI format:

One uses: file:///c%3A/
The other uses: file:///c:/

Reproduction steps

  1. Open a Ruby project in VS Code on Windows.
  2. Use the "Go to Definition" feature on a method or class.
  3. Observe that duplicate definitions appear in the results.

Image

Image

Image

Activity

  1. added
    bugSomething isn't working
    vscodeThis pull request should be included in the VS Code extension's release notes
    on Mar 10, 2025
  2. added theissue type on Mar 13, 2025
  3. egiurleo commented on Mar 13, 2025

    @egiurleo
    Contributor

    Hi @son-urban! Thanks for opening this issue. We don't have the capacity to address this right now, but we'd welcome a PR to fix it!

  4. andriytyurnikov commented on Jul 31, 2026

    @andriytyurnikov

    This looks only partially fixed. #3381 escaped the colon, which removed the raw c: form, but the drive letter case still differs, so the two URIs can still disagree.

    Server side:

    require "ruby_lsp/internal"
    URI::Generic.from_path(path: "C:/foo/bar.rb").to_s #=> "file:///C%3A/foo/bar.rb"
    URI::Generic.from_path(path: "c:/foo/bar.rb").to_s #=> "file:///c%3A/foo/bar.rb"

    Editor side (vscode-uri 3.1.0, which is what VS Code builds its URIs with):

    const { URI } = require("vscode-uri");
    URI.file("C:/foo/bar.rb").toString(); //=> "file:///c%3A/foo/bar.rb"
    URI.file("c:/foo/bar.rb").toString(); //=> "file:///c%3A/foo/bar.rb"

    vscode-uri normalises the drive letter to lower case regardless of input, while from_path preserves whatever case it was given. The server discovers files through Dir.glob and Dir.pwd, which return an upper case drive on Windows, so a file found by indexing becomes file:///C%3A/... while the same file opened in the editor arrives as file:///c%3A/... — two keys for one file, which is the duplicate result reported here.

    #3881 reports the same case mismatch in a different place (Dir.pwd upper case vs. lower case keys in the reporter port database), so it does not appear specific to one code path.

    Two things worth knowing for anyone picking this up:

    • test_from_path_on_windows and test_from_path_on_windows_with_lowercase_drive currently assert that the case is preserved, so today's behaviour is deliberate rather than an oversight.
    • GlobalState#workspace_path comes from the client's URI (lower case drive) while Dir.pwd is upper case, and server.rb has several case-sensitive path.start_with?(@global_state.workspace_path) guards. Normalising only from_path risks trading one Windows bug for another, so those probably need to move together.

    I could only verify the encoding difference above; I do not have a Windows machine to confirm the start_with? half.

    Noticed while working on #4022, which narrows from_path's escaping to match vscode-uri for everything except this. That PR deliberately leaves the drive letter alone, for the reasons above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp-wantedExtra attention is neededvscodeThis pull request should be included in the VS Code extension's release notes

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions