Skip to content

Commit

Permalink
refactor: Wrap CargoRunnableArgs in RunnableArgs enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilfred committed Mar 27, 2024
1 parent 5cd677c commit 4d6a8c6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
15 changes: 9 additions & 6 deletions crates/rust-analyzer/src/handlers/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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,
},
}),
})
}
}
Expand All @@ -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,
},
}),
});
}
}
Expand Down
9 changes: 8 additions & 1 deletion crates/rust-analyzer/src/lsp/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,14 @@ pub struct Runnable {
#[serde(skip_serializing_if = "Option::is_none")]
pub location: Option<lsp_types::LocationLink>,
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)]
Expand Down
17 changes: 9 additions & 8 deletions crates/rust-analyzer/src/lsp/to_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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,
},
}),
})
}
}
Expand All @@ -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,
Expand Down

0 comments on commit 4d6a8c6

Please sign in to comment.