rust-lang / rust-lang/rust-analyzer

Feature request: Add a bazel Runnable kind

Open
#12,105 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-config A-ide C-enhancement
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

As a developer using rust-analyzer with bazel (using rules_rust and rust-project.json generated by @rules_rust//tools/rust_analyzer:gen_rust_project)
I would like rust-analyzer to use bazel test for test runnables
so that I can enjoy the same UX regardless of the build system.

The Runnables extension is a great productivity boost and it's very easy to run a test
from a code lens. According to my experiments and the lsp-extensions.md documentation, it
currently only supports one Runnable.kind = "cargo".

Given the consistency and stability of the bazel test intereface, we should be able to use bazel test and pass additional command line arguments

bazel test //path_to_rust_package:rust_test_name --test_arg $THE_TEST_SELECTED_BY_USER

While the --test_arg is definitely something that rust-analyzer can already reliable populate, working out the //path_to_rust_package:rust_test_name might require an expansion to rules_rust to add test targets to rust-project.json file.

Once this is implemented, the same interface could be used for the Related Tests extension.

For rust-analyzer to automatically work out the runnable kind is "bazel", rules_rust can add a field to rust-project.json that declares runnable kind to be bazel (or we can heuristically guess?).

For the rest, rust-analyzer works like a charm with bazel, so thanks very much.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with lsp-extensions.md and the existing cargo Runnable behavior, then trace how rust-project.json supplies test information. Investigate the rules_rust-generated project data and the proposed bazel runnable kind; done means test runnables can identify their Bazel targets, pass the selected test argument, and support the related-tests interface.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.