From 964219f0be87d189e13dd63a6ffc4d9d53eafbb4 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 26 Aug 2020 17:33:03 +0200 Subject: Allow running a test as a binary --- crates/rust-analyzer/src/cargo_target_spec.rs | 6 +++++- crates/rust-analyzer/src/handlers.rs | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/rust-analyzer/src/cargo_target_spec.rs b/crates/rust-analyzer/src/cargo_target_spec.rs index 3041915e1..ddc028148 100644 --- a/crates/rust-analyzer/src/cargo_target_spec.rs +++ b/crates/rust-analyzer/src/cargo_target_spec.rs @@ -72,7 +72,11 @@ impl CargoTargetSpec { extra_args.push("--nocapture".to_string()); } RunnableKind::Bin => { - args.push("run".to_string()); + let subcommand = match spec { + Some(CargoTargetSpec { target_kind: TargetKind::Test, .. }) => "test", + _ => "run", + }; + args.push(subcommand.to_string()); if let Some(spec) = spec { spec.push_to(&mut args, kind); } diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index 33e60b500..8568f7b05 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs @@ -1399,7 +1399,10 @@ fn should_skip_target(runnable: &Runnable, cargo_spec: Option<&CargoTargetSpec>) RunnableKind::Bin => { // Do not suggest binary run on other target than binary match &cargo_spec { - Some(spec) => !matches!(spec.target_kind, TargetKind::Bin | TargetKind::Example), + Some(spec) => !matches!( + spec.target_kind, + TargetKind::Bin | TargetKind::Example | TargetKind::Test + ), None => true, } } -- cgit v1.2.3