Autocomplete does not work in Vscode for files other than main.rs

I'm new to rust programming and don't understand a lot, but when using rust-analyzer in Vscode, tooltips in files other than main.rs do not work. I initialize the project using the cargo new command.

what is file name ?
example a.rs

create file lib.rs and write
pub mod a;

2 Likes

As parinya.ao said, in Rust the module tree is not automatically mapped to the file structure, but is manually mapped by the programmer.

In other words, everytime that you create a file you need to manually add it to the module tree.

3 Likes

Thank you very much, everything worked! I thought that I could just add the line β€œpub mod a.rs” to main.rs.

Correction: I meant you should put this line in lib.rs:

```rust
pub mod a;

You can. You don't need a lib.rs. Just put

pub mod a;

At the top of your main.rs.

Note: No .rs after the module name.

1 Like

Of course, I didn't add .rs to the mod line, but whether I use lib.rs or not it works unstable for multiple files.

In more detail, in addition to main.rs there are two files:

one file contains a function for working with a third-party crate,

the second file contains a trait and implementation for the types in this crate.

When including these files in main.rs/lib.rs auto-completion works only for one file. All files are located in /src

UPD: it doesn't work only for one specific file, if I add new ones then autocompletion works well