rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

Intelisense works only in main file

Open erikpa1 opened this issue 2 years ago • 8 comments

Hi yesterday I tried some project in VS code, but I found out rust-analyzer is working only main.rs file, nowhere else:

image

But when I come to any other file than main, code completion won't work.

image

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)

erikpa1 avatar Sep 23 '22 15:09 erikpa1

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 avatar Sep 23 '22 15:09 lnicola

@lnicola Nope, intelisense in mod.rs is also not working, any file I create is broken

erikpa1 avatar Sep 23 '22 15:09 erikpa1

Do you have a mod projects declaration in databases/mod.rs?

lnicola avatar Sep 23 '22 15:09 lnicola

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)

erikpa1 avatar Sep 23 '22 17:09 erikpa1

The file isn't even compiled if you don't declare it as a module. And you do get a warning:

image

lnicola avatar Sep 23 '22 17:09 lnicola

@lnicola
image

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

erikpa1 avatar Sep 23 '22 18:09 erikpa1

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.

bjorn3 avatar Sep 23 '22 19:09 bjorn3

Arguably, we could tell where these files should be declared as modules: in their parent, according to the disk structure, not as separate crates.

lnicola avatar Sep 23 '22 19:09 lnicola

pycharm rust module has no problem with it,....

erikpa1 avatar Sep 26 '22 05:09 erikpa1

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.

CaneMandarinesco avatar Sep 02 '23 19:09 CaneMandarinesco