Skip to content

Commit f01846b

Browse files
committed
Generalize Flycheckconfig
1 parent aad0e63 commit f01846b

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

crates/ra_flycheck/src/lib.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ use crate::conv::{map_rust_diagnostic_to_lsp, MappedRustDiagnostic};
2323
pub use crate::conv::url_from_path_with_drive_lowercasing;
2424

2525
#[derive(Clone, Debug)]
26-
pub struct FlycheckConfig {
27-
pub command: String,
28-
pub all_targets: bool,
29-
pub extra_args: Vec<String>,
26+
pub enum FlycheckConfig {
27+
CargoCommand { command: String, all_targets: bool, extra_args: Vec<String> },
28+
CustomCommand { command: String, args: Vec<String> },
3029
}
3130

3231
/// Flycheck wraps the shared state and communication machinery used for
@@ -215,18 +214,25 @@ impl FlycheckThread {
215214
self.message_recv = never();
216215
self.check_process = None;
217216

218-
let cmd = {
219-
let mut cmd = Command::new(cargo_binary());
220-
cmd.arg(&self.config.command);
221-
cmd.args(&["--workspace", "--message-format=json", "--manifest-path"]);
222-
cmd.arg(self.workspace_root.join("Cargo.toml"));
223-
if self.config.all_targets {
224-
cmd.arg("--all-targets");
217+
let mut cmd = match &self.config {
218+
FlycheckConfig::CargoCommand { command, all_targets, extra_args } => {
219+
let mut cmd = Command::new(cargo_binary());
220+
cmd.arg(command);
221+
cmd.args(&["--workspace", "--message-format=json", "--manifest-path"]);
222+
cmd.arg(self.workspace_root.join("Cargo.toml"));
223+
if *all_targets {
224+
cmd.arg("--all-targets");
225+
}
226+
cmd.args(extra_args);
227+
cmd
228+
}
229+
FlycheckConfig::CustomCommand { command, args } => {
230+
let mut cmd = Command::new(command);
231+
cmd.args(args);
232+
cmd
225233
}
226-
cmd.args(self.config.extra_args.iter());
227-
cmd.current_dir(&self.workspace_root);
228-
cmd
229234
};
235+
cmd.current_dir(&self.workspace_root);
230236

231237
let (message_send, message_recv) = unbounded();
232238
self.message_recv = message_recv;

crates/rust-analyzer/src/main_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ fn get_config(
102102
max_length: config.inlay_hints_max_length,
103103
},
104104
check: if config.cargo_watch_enable {
105-
Some(FlycheckConfig {
105+
Some(FlycheckConfig::CargoCommand {
106106
command: config.cargo_watch_command.clone(),
107107
all_targets: config.cargo_watch_all_targets,
108108
extra_args: config.cargo_watch_args.clone(),

0 commit comments

Comments
 (0)