visual-studio-coderustrust-cargorust-language-server

VS Code: run RLS on all .rs files


I have a Cargo package that I have opened as a workspace in Visual Studio Code. This way, the source code in .rs files in type checked through the Rust Language Server. But it only catches the files which are dependencies of main.rs where the main function is. It does not do type checking when I edit a new newfile.rs file, so trivial errors like this, are not caught by VS Code: let a: int = "hi!";

However, if I include this section in Cargo.toml, then the source code is handled by RLS:

[[bin]]
name = "foo"
path = "src/newfile.rs"

Is it possible to add something to Cargo.toml such that all .rs files are handled by RLS?


Solution

  • It is impossible because that is how rust code is resolved. Rust code can only be valid under a crate context with a certain module-wise path. The compilation of a mod also depends on how the mod is defined (accessibility modifier and attributes/macros attached to the mod).