Skip to content

Commit 4f41195

Browse files
committed
refactor: Wrap CargoRunnableArgs in RunnableArgs enum
1 parent b0cbf80 commit 4f41195

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -826,8 +826,11 @@ pub(crate) fn handle_runnables(
826826
}
827827
let mut runnable = to_proto::runnable(&snap, runnable)?;
828828
if expect_test {
829-
runnable.label = format!("{} + expect", runnable.label);
830-
runnable.args.expect_test = Some(true);
829+
#[allow(irrefutable_let_patterns)]
830+
if let lsp_ext::RunnableArgs::Cargo(r) = &mut runnable.args {
831+
runnable.label = format!("{} + expect", runnable.label);
832+
r.expect_test = Some(true);
833+
}
831834
}
832835
res.push(runnable);
833836
}
@@ -851,14 +854,14 @@ pub(crate) fn handle_runnables(
851854
),
852855
location: None,
853856
kind: lsp_ext::RunnableKind::Cargo,
854-
args: lsp_ext::CargoRunnableArgs {
857+
args: lsp_ext::RunnableArgs::Cargo(lsp_ext::CargoRunnableArgs {
855858
workspace_root: Some(spec.workspace_root.clone().into()),
856859
override_cargo: config.override_cargo.clone(),
857860
cargo_args,
858861
cargo_extra_args: config.cargo_extra_args.clone(),
859862
executable_args: Vec::new(),
860863
expect_test: None,
861-
},
864+
}),
862865
})
863866
}
864867
}
@@ -868,14 +871,14 @@ pub(crate) fn handle_runnables(
868871
label: "cargo check --workspace".to_owned(),
869872
location: None,
870873
kind: lsp_ext::RunnableKind::Cargo,
871-
args: lsp_ext::CargoRunnableArgs {
874+
args: lsp_ext::RunnableArgs::Cargo(lsp_ext::CargoRunnableArgs {
872875
workspace_root: None,
873876
override_cargo: config.override_cargo,
874877
cargo_args: vec!["check".to_owned(), "--workspace".to_owned()],
875878
cargo_extra_args: config.cargo_extra_args,
876879
executable_args: Vec::new(),
877880
expect_test: None,
878-
},
881+
}),
879882
});
880883
}
881884
}

crates/rust-analyzer/src/lsp/ext.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,14 @@ pub struct Runnable {
423423
#[serde(skip_serializing_if = "Option::is_none")]
424424
pub location: Option<lsp_types::LocationLink>,
425425
pub kind: RunnableKind,
426-
pub args: CargoRunnableArgs,
426+
pub args: RunnableArgs,
427+
}
428+
429+
#[derive(Deserialize, Serialize, Debug)]
430+
#[serde(rename_all = "camelCase")]
431+
#[serde(untagged)]
432+
pub enum RunnableArgs {
433+
Cargo(CargoRunnableArgs),
427434
}
428435

429436
#[derive(Serialize, Deserialize, Debug)]

crates/rust-analyzer/src/lsp/to_proto.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,14 +1364,14 @@ pub(crate) fn runnable(
13641364
label,
13651365
location: Some(location),
13661366
kind: lsp_ext::RunnableKind::Cargo,
1367-
args: lsp_ext::CargoRunnableArgs {
1367+
args: lsp_ext::RunnableArgs::Cargo(lsp_ext::CargoRunnableArgs {
13681368
workspace_root: Some(workspace_root.into()),
13691369
override_cargo: config.override_cargo,
13701370
cargo_args,
13711371
cargo_extra_args: config.cargo_extra_args,
13721372
executable_args,
13731373
expect_test: None,
1374-
},
1374+
}),
13751375
})
13761376
}
13771377
None => {
@@ -1384,14 +1384,14 @@ pub(crate) fn runnable(
13841384
label,
13851385
location: Some(location),
13861386
kind: lsp_ext::RunnableKind::Cargo,
1387-
args: lsp_ext::CargoRunnableArgs {
1387+
args: lsp_ext::RunnableArgs::Cargo(lsp_ext::CargoRunnableArgs {
13881388
workspace_root: None,
13891389
override_cargo: config.override_cargo,
13901390
cargo_args,
13911391
cargo_extra_args: config.cargo_extra_args,
13921392
executable_args,
13931393
expect_test: None,
1394-
},
1394+
}),
13951395
})
13961396
}
13971397
}
@@ -1418,11 +1418,12 @@ pub(crate) fn code_lens(
14181418
};
14191419
let r = runnable(snap, run)?;
14201420

1421+
let has_root = match &r.args {
1422+
lsp_ext::RunnableArgs::Cargo(c) => c.workspace_root.is_some(),
1423+
};
1424+
14211425
let lens_config = snap.config.lens();
1422-
if lens_config.run
1423-
&& client_commands_config.run_single
1424-
&& r.args.workspace_root.is_some()
1425-
{
1426+
if lens_config.run && client_commands_config.run_single && has_root {
14261427
let command = command::run_single(&r, &title);
14271428
acc.push(lsp_types::CodeLens {
14281429
range: annotation_range,

0 commit comments

Comments
 (0)