rust-lang / rust-lang/rust-analyzer
rust-analyzer often fails to update its file mapping when moving between self-named module files and mod.rs
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
It happens somewhat regularily for me that I switch between foo.rs and foo/mod.rs during refactoring, and most of the times I do this, RA seems to fail to update its internal module to file path mapping. Trying to reproduce this in a small sample project showed me that it doesn't happen all the time, so I can not provide exact reproduction steps but I was able to trigger it with only two modules after a couple of renames back and forth (the one that triggered it happened from within VSCode: I moved the file first so it was foo/bar/bar.rs, then renamed it to mod.rs).
When this happens, rust-analyzer doesn't generate any errors for the mod statement, but Ctrl+Clicking on it tries to load the wrong file. When opening the renamed module file, there's an unlinked file diagnostic at the start of the file and barely any RA functionality works within it, just like for other unlinked files. The issue is only fixable by restarting the server (or the entire extension process / VSCode window), 'reload workspace' doesn't help.
rust-analyzer version: 0.4.2435-standalone
rustc version: 1.88.0-nightly (6bc57c6bf 2025-04-22)
editor or extension: VSCode, extension version 0.4.2435 (pre-release, from Open VSX)
relevant settings:
{
"rust-analyzer.files.watcher": "server",
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the reported VSCode rename sequence with the server file watcher enabled: move a module through foo/bar/bar.rs to mod.rs, then rename it back and forth. Trace the module-to-file mapping update and navigation diagnostics; done means Ctrl+Click and file analysis use the new path without restarting rust-analyzer.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100