diff --git a/crates/rust-analyzer/src/handlers/request.rs b/crates/rust-analyzer/src/handlers/request.rs index 2ee563eefc7b..4a6a546848bd 100644 --- a/crates/rust-analyzer/src/handlers/request.rs +++ b/crates/rust-analyzer/src/handlers/request.rs @@ -826,8 +826,11 @@ pub(crate) fn handle_runnables( } let mut runnable = to_proto::runnable(&snap, runnable)?; if expect_test { - runnable.label = format!("{} + expect", runnable.label); - runnable.args.expect_test = Some(true); + #[allow(irrefutable_let_patterns)] + if let lsp_ext::RunnableArgs::Cargo(r) = &mut runnable.args { + runnable.label = format!("{} + expect", runnable.label); + r.expect_test = Some(true); + } } res.push(runnable); } @@ -851,14 +854,14 @@ pub(crate) fn handle_runnables( ), location: None, kind: lsp_ext::RunnableKind::Cargo, - args: lsp_ext::CargoRunnableArgs { + args: lsp_ext::RunnableArgs::Cargo(lsp_ext::CargoRunnableArgs { workspace_root: Some(spec.workspace_root.clone().into()), override_cargo: config.override_cargo.clone(), cargo_args, cargo_extra_args: config.cargo_extra_args.clone(), executable_args: Vec::new(), expect_test: None, - }, + }), }) } } @@ -868,14 +871,14 @@ pub(crate) fn handle_runnables( label: "cargo check --workspace".to_owned(), location: None, kind: lsp_ext::RunnableKind::Cargo, - args: lsp_ext::CargoRunnableArgs { + args: lsp_ext::RunnableArgs::Cargo(lsp_ext::CargoRunnableArgs { workspace_root: None, override_cargo: config.override_cargo, cargo_args: vec!["check".to_owned(), "--workspace".to_owned()], cargo_extra_args: config.cargo_extra_args, executable_args: Vec::new(), expect_test: None, - }, + }), }); } } diff --git a/crates/rust-analyzer/src/lsp/ext.rs b/crates/rust-analyzer/src/lsp/ext.rs index c7bb6fbb7e12..41814190ba29 100644 --- a/crates/rust-analyzer/src/lsp/ext.rs +++ b/crates/rust-analyzer/src/lsp/ext.rs @@ -423,7 +423,14 @@ pub struct Runnable { #[serde(skip_serializing_if = "Option::is_none")] pub location: Option, pub kind: RunnableKind, - pub args: CargoRunnableArgs, + pub args: RunnableArgs, +} + +#[derive(Deserialize, Serialize, Debug)] +#[serde(rename_all = "camelCase")] +#[serde(untagged)] +pub enum RunnableArgs { + Cargo(CargoRunnableArgs), } #[derive(Serialize, Deserialize, Debug)] diff --git a/crates/rust-analyzer/src/lsp/to_proto.rs b/crates/rust-analyzer/src/lsp/to_proto.rs index 9c5c716bcf5e..8dc2744a6327 100644 --- a/crates/rust-analyzer/src/lsp/to_proto.rs +++ b/crates/rust-analyzer/src/lsp/to_proto.rs @@ -1364,14 +1364,14 @@ pub(crate) fn runnable( label, location: Some(location), kind: lsp_ext::RunnableKind::Cargo, - args: lsp_ext::CargoRunnableArgs { + args: lsp_ext::RunnableArgs::Cargo(lsp_ext::CargoRunnableArgs { workspace_root: Some(workspace_root.into()), override_cargo: config.override_cargo, cargo_args, cargo_extra_args: config.cargo_extra_args, executable_args, expect_test: None, - }, + }), }) } None => { @@ -1384,14 +1384,14 @@ pub(crate) fn runnable( label, location: Some(location), kind: lsp_ext::RunnableKind::Cargo, - args: lsp_ext::CargoRunnableArgs { + args: lsp_ext::RunnableArgs::Cargo(lsp_ext::CargoRunnableArgs { workspace_root: None, override_cargo: config.override_cargo, cargo_args, cargo_extra_args: config.cargo_extra_args, executable_args, expect_test: None, - }, + }), }) } } @@ -1418,11 +1418,12 @@ pub(crate) fn code_lens( }; let r = runnable(snap, run)?; + let has_root = match &r.args { + lsp_ext::RunnableArgs::Cargo(c) => c.workspace_root.is_some(), + }; + let lens_config = snap.config.lens(); - if lens_config.run - && client_commands_config.run_single - && r.args.workspace_root.is_some() - { + if lens_config.run && client_commands_config.run_single && has_root { let command = command::run_single(&r, &title); acc.push(lsp_types::CodeLens { range: annotation_range,