Skip to content

Commit

Permalink
Auto merge of rust-lang#16972 - joshka:cargo-run-runnable, r=Veykril
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Apr 25, 2024
2 parents 039b821 + 944aa3e commit 8293f0a
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -855,10 +855,14 @@ pub(crate) fn handle_runnables(
let config = snap.config.runnables();
match cargo_spec {
Some(spec) => {
let all_targets = !snap.analysis.is_crate_no_std(spec.crate_id)?;
for cmd in ["check", "test"] {
let is_crate_no_std = snap.analysis.is_crate_no_std(spec.crate_id)?;
for cmd in ["check", "run", "test"] {
if cmd == "run" && spec.target_kind != TargetKind::Bin {
continue;
}
let mut cargo_args =
vec![cmd.to_owned(), "--package".to_owned(), spec.package.clone()];
let all_targets = cmd != "run" && !is_crate_no_std;
if all_targets {
cargo_args.push("--all-targets".to_owned());
}
Expand Down

0 comments on commit 8293f0a

Please sign in to comment.