rust-analyzer
rust-analyzer copied to clipboard
Intelisense works only in main file
Hi yesterday I tried some project in VS code, but I found out rust-analyzer is working only main.rs file, nowhere else:
But when I come to any other file than main, code completion won't work.
I also tried to reinstall rust plugin, or switch to prerelease, nothing helped.
rust-analyzer version: v0.3.1212
rustc version: 1.64.0 (also tried on 1.39 I think)
I'm guessing there's a hint on the first line saying that the file is not included in the project. You need a mod projects_astorage
declaration in the parent module.
@lnicola Nope, intelisense in mod.rs is also not working, any file I create is broken
Do you have a mod projects
declaration in databases/mod.rs
?
Oh, wait you wonna say, if the file isn't moded intelisense will not work? This is interesting IDE behaviour, like ok, some warning about file is never included or something, never used function, but disable whole intelisense for that file ??? (yeah after mod file it worked)
The file isn't even compiled if you don't declare it as a module. And you do get a warning:
@lnicola
This means file is not included, I know, I didn't included it, because I created it to prototype first. But this is still no explanation why intel sense works,.... (not included file should be shown in hierarchy, not disable whole code completion for that file, there is no other extension that works in this way, c++, react,... I never seen this behaviour and I though its bug. Maybe if this is some behavior authors want, there should be button which pops up "This file is not included, intelisense will not work for this file do you want to include it ? -> Yes" )
I have 4 main files main1, main2, main3, where I have my code snippets, and I don't have where to include them. (I'm just switching names when I need, its test purpose,...)
But thank you for your time, I will know how to write code in VS code now :) have a nice day
not included file should be shown in hierarchy
But it doesn't exist in the module hierarchy. C++ and javascript have a different module system where every file is effectively their own module root. In rust however you have a single crate root per crate and this crate root then can have sub modules. Any file not (indirectly) included from the crate root is ignored by rustc. While it would be possible to pretend that non-includee files are their own crate root, this will still prevent intellisense from working with dependencies and items that are part of the crate in which you intended to include the module.
Arguably, we could tell where these files should be declared as modules: in their parent, according to the disk structure, not as separate crates.
pycharm rust module has no problem with it,....
this
not included file should be shown in hierarchy
But it doesn't exist in the module hierarchy. C++ and javascript have a different module system where every file is effectively their own module root. In rust however you have a single crate root per crate and this crate root then can have sub modules. Any file not (indirectly) included from the crate root is ignored by rustc. While it would be possible to pretend that non-includee files are their own crate root, this will still prevent intellisense from working with dependencies and items that are part of the crate in which you intended to include the module.
I've recently started programming in rust and this doesn't seem to make complete sense to me, and it wasn't obvious what was the problem.