rust-lang / rust-lang/rust-analyzer

Regression: `Semantics::file_to_module_def` sometimes returns no result on Windows DOS device paths

Open
#18,894 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

When using rust-analyzer as a library for analysis, rust analyzer has started to flakily misbehave on Windows paths. This was first seen in https://github.com/github/codeql/pull/18443, but I've managed to reduce the issue in this repository.

What I do is to load a project contained in a workspace using ra_ap_load-cargo::load_workspace_at with default settings, then starting from a path to a module in the crate do some dance to map it to a file ID in the VFS (going from PathBuf to Utf8PathBuf, then to AbsPathBuf, then to VfsPath), and then call Semantics::file_to_module_def. This should work, but in some cases fails on Windows if the initial path is a DOS device path (i.e. //?/ prefixed paths), which is what PathBuf::canonicalize will return on Windows.

This can be seen running this workflow.

Some things I've noticed

  • everything works on Linux
  • this used to work in version 0.0.248
  • failure is flaky, but quite frequent
  • a workaround is to use dunce for canonicalization, but that will not work for long paths (more than 256 chars in general)

rust-analyzer version: 0.0.257

rustc version: 1.83

editor or extension: none (using rust-anlyzer as a library)

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTC, RUSTUP_HOME or CARGO_HOME)

repository link (if public, optional): https://github.com/redsun82/rust-analyzer-windows-issue

code snippet to reproduce: see https://github.com/redsun82/rust-analyzer-windows-issue/blob/main/tests/load.rs, failure can be seen on windows running cargo test multiple times

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with tests/load.rs in the linked reproduction and run its cargo test workflow repeatedly on Windows using a DOS device path. Trace the PathBuf to Utf8PathBuf to AbsPathBuf to VfsPath conversion before Semantics::file_to_module_def. Done means the module definition is found reliably for the reported Windows paths without regressing Linux behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.