Skip to content

Commit 032fca9

Browse files
committed
Make cargo run always available for binaries
Previously, items for `cargo test` and `cargo check` would appear as in the `Select Runnable` quick pick that appears when running `rust-analyzer: Run`, but `run` would only appear as a runnable if a `main`` function was selected in the editor. This change adds `cargo run` as an always available runnable command for binary packages. This makes it easier to develop cli / tui applications, as now users can run application from anywhere in their codebase.
1 parent ab10eea commit 032fca9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

crates/rust-analyzer/src/handlers/request.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -836,10 +836,13 @@ pub(crate) fn handle_runnables(
836836
let config = snap.config.runnables();
837837
match cargo_spec {
838838
Some(spec) => {
839-
let all_targets = !snap.analysis.is_crate_no_std(spec.crate_id)?;
840-
for cmd in ["check", "test"] {
839+
for cmd in ["check", "run", "test"] {
840+
if cmd == "run" && spec.target_kind != TargetKind::Bin {
841+
continue;
842+
}
841843
let mut cargo_args =
842844
vec![cmd.to_owned(), "--package".to_owned(), spec.package.clone()];
845+
let all_targets = cmd != "run" && !snap.analysis.is_crate_no_std(spec.crate_id)?;
843846
if all_targets {
844847
cargo_args.push("--all-targets".to_owned());
845848
}

0 commit comments

Comments
 (0)