-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Sometimes rust analyzer says "File does not belong to any crate" even though it does. #9910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I ran into a similar issue. A crate don't load into the workspace. The extension says:
I tried to rebuild the whole project again, but nothing changes. Does anyone know how to fix this? |
It looks like it's my fault. I included binary crates as dependencies. I noticed that library crates connected fine. |
ran into this issue, somehow this is specific to a file name? if i rename the file the issue gets resolved. I am not sure how to fix the underlying issue though |
I also get this issue, and it seems to show up in cases where several dependencies have to be checked or indexed by rust-analyzer before anything can be done. So, even though it technically could provide information on the current crate, it refuses to do so until dependencies are scanned. It appears to also get stuck sometimes when indexing crates. Unfortunately, given how opaque rust-analyzer is about its current status, I can't really debug this. Would be more than willing to offer extra info if told how. Oh! I see. At least in my current project, the depended-on version of Nope, it still fails even on the newer versions where |
rust-analyzer does not use the same engine as rustdoc, so it will be weird (but not impossible) if the same bug will appear in both. Can you find a minimal reproducible example? Even just an empty project that has a set of dependencies that make r-a stuck, it will be good. |
If that the case, maybe you have some crates with cyclic dependencies in your VS Code workplace, such as serde ( |
@Mingun |
I mean, this is enough to immediately get the error for me when I open [package]
name = "rust-analyzer-breaks"
version = "0.1.0"
edition = "2021"
[dependencies]
bevy = "0.14.2"
It never seems to hang on |
@ChayimFriedman2, however, this is what rust-analyzer reports as an error, explicitly (I mean, that in the tooltip with error you can see something like btw, what the hell with comment field in this repo? |
This is very weird, since rust-analyzer depends on Cargo to determine the crate graph. Can you post an image of the error (with the tooltip)? @clarfonthey I can't reproduce. rust-analyzer does not report the error for me and definitely does not hang. Are you sure it is stuck and not just doing something for a long time? Can you post your rust-analyzer settings? |
I'm running kak-lsp, so, maybe the missing link is some inconsistency in how the LSP protocol is being followed. I'll try to come up with a minimal config setup to replicate a bit easier, but I don't have any particularly interesting settings, and actually pruned most of the ones I had recently. |
Huh, okay. At least on the latest version of |
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:
cargo clean
ing and rebuilding the whole crate.If it helps, I am on Windows 10.
The text was updated successfully, but these errors were encountered: