diff --git a/docs/rust_analyzer.vm b/docs/rust_analyzer.vm index b9743320b5..6822b95eb2 100644 --- a/docs/rust_analyzer.vm +++ b/docs/rust_analyzer.vm @@ -8,23 +8,46 @@ such a file. ### Setup +#### Bzlmod + First, ensure `rules_rust` is setup in your workspace. By default, `rust_register_toolchains` will ensure a [rust_analyzer_toolchain](#rust_analyzer_toolchain) is registered within the WORKSPACE. Next, load the dependencies for the `rust-project.json` generator tool: ```python +# BUILD.bazel + load("@rules_rust//tools/rust_analyzer:deps.bzl", "rust_analyzer_dependencies") +``` -rust_analyzer_dependencies() +Bazel will create the target `@rules_rust//tools/rust_analyzer:gen_rust_project`, which you can build +with + +``` +bazel run @rules_rust//tools/rust_analyzer:gen_rust_project ``` -Finally, run `bazel run @rules_rust//tools/rust_analyzer:gen_rust_project` whenever dependencies change to regenerate the `rust-project.json` file. It should be added to `.gitignore` because it is effectively a build artifact. Once the `rust-project.json` has been generated in the project root, rust-analyzer can pick it up upon restart. +#### WORKSPACE + +As with Bzlmod, ensure `rules_rust` is setup in your workspace. + +Moreover, when loading the dependencies for the tool, you should call the function `rust_analyzer_dependencies()`: + +```python +load("@rules_rust//tools/rust_analyzer:deps.bzl", "rust_analyzer_dependencies") + +rust_analyzer_dependencies() +``` + +Again, you can now run `bazel run @rules_rust//tools/rust_analyzer:gen_rust_project` +whenever dependencies change to regenerate the `rust-project.json` file. + For users who do not use `rust_register_toolchains` to register toolchains, the following can be added to their WORKSPACE to register a `rust_analyzer_toolchain`. Please make sure the Rust version used in this toolchain matches the version used by the currently registered toolchain or the sources/documentation