Install https://marketplace.visualstudio.com/items?itemName=MattStark.bazel-rust-analyzer extension.
Rustc outputs paths relative to src, and vscode attempts to interpret paths as relative to the first workspace root.
Thus, for now, this only works with single-folder workspaces, and if you‘re having performance problems with vscode, use search.exclude to prevent vscode from indexing or searching directories you don’t care about. The following workspace configuration is a good start.
{
"folders": [
{
"name": "src
"path": "."
},
],
"settings": {
"files.exclude": {
},
"search.exclude": {
"bazel-bin/**": true,
"bazel-out/**": true,
"bazel-src/**": true,
"bazel-testlogs/**": true,
},
}
}
Add the following configuration to your vscode's settings.json.
"rust-analyzer.linkedProjects": ["${workspaceFolder}/rust-project.json"],
"rust-analyzer.check.overrideCommand": ["bazel/rust/ide_support/flycheck.sh"],
"bazel-rust-analyzer.genRustProjectCommand": [
"env",
"RUST_LOG=info",
"bazel",
"run",
"//bazel/rust/ide_support:gen_rust_project",
"--",
"--files"
],
"bazel-rust-analyzer.autoGenRustProjectCommand": true,
Follow the usage instructions instructions for the https://marketplace.visualstudio.com/items?itemName=MattStark.bazel-rust-analyzer extension.
You can also use bazel to make the error messages automatically refresh on save.