rust-lang / rust-lang/rust-analyzer
Sometimes rust analyzer says "File does not belong to any crate" even though it does.
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
I am currently on Rust Analyzer version rust-analyzer version: 5664a2b0b 2021-08-09 stable however, I've experienced this bug before on prior RA versions.
Sometimes, when adding a new file to my rust crate, rust analyzer will seemingly be unable to figure out that this new file is part of my crate. When going to "Rust Analyzer > Status", the status window reports "File info: Does not belong to any crate". When in this state, I am unable to do most actions such as hover-over-function for docs, most autocompletions, and type hints won't display. I am reasonably sure that this is not just me messing up my crate structure, since building via cargo still seems to work (and in fact, sometimes RA will correctly display compile error/warnings).
Unfortunately, I do not know how to reproduce this bug, as it seems to happen at random, and does not go away for a long time. I have had times where renaming the file made it work, but trying to then rename it back to the old file made RA stop working again, as well as times where RA will properly work for every file except for one or two.
Notably, I have seen this behavior persist through:
- Restarting the language server.
- Restarting VS Code.
cargo cleaning and rebuilding the whole crate.- Restarting my computer.
- Reinstalling the Rust Analyzer extension.
If it helps, I am on Windows 10.
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
No source file, test, or reliable reproduction is named. Start by comparing the Rust Analyzer > Status result for an affected file with the same crate built by cargo, using the reported restart, rebuild, and Windows 10 observations; done means identifying a reproducible cause and verifying that affected files are recognized as belonging to their crate.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100