Skip to content

Commit c88d5dc

Browse files
committed
Auto merge of #16972 - joshka:cargo-run-runnable, r=Veykril
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.
2 parents 73a4275 + aa49926 commit c88d5dc

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -855,10 +855,14 @@ pub(crate) fn handle_runnables(
855855
let config = snap.config.runnables();
856856
match cargo_spec {
857857
Some(spec) => {
858-
let all_targets = !snap.analysis.is_crate_no_std(spec.crate_id)?;
859-
for cmd in ["check", "test"] {
858+
let is_crate_no_std = snap.analysis.is_crate_no_std(spec.crate_id)?;
859+
for cmd in ["check", "run", "test"] {
860+
if cmd == "run" && spec.target_kind != TargetKind::Bin {
861+
continue;
862+
}
860863
let mut cargo_args =
861864
vec![cmd.to_owned(), "--package".to_owned(), spec.package.clone()];
865+
let all_targets = cmd != "run" && !is_crate_no_std;
862866
if all_targets {
863867
cargo_args.push("--all-targets".to_owned());
864868
}

0 commit comments

Comments
 (0)