diff --git a/crates/flycheck/src/lib.rs b/crates/flycheck/src/lib.rs index fdc03f4053a2..50828e293c06 100644 --- a/crates/flycheck/src/lib.rs +++ b/crates/flycheck/src/lib.rs @@ -32,6 +32,7 @@ pub enum FlycheckConfig { features: Vec, extra_args: Vec, extra_env: FxHashMap, + single_crate: Option, }, CustomCommand { command: String, @@ -250,7 +251,7 @@ impl FlycheckActor { } fn check_command(&self) -> Command { - let mut cmd = match &self.config { + match &self.config { FlycheckConfig::CargoCommand { command, target_triple, @@ -260,12 +261,26 @@ impl FlycheckActor { extra_args, features, extra_env, + single_crate, } => { let mut cmd = Command::new(toolchain::cargo()); cmd.arg(command); cmd.current_dir(&self.workspace_root); - cmd.args(&["--workspace", "--message-format=json", "--manifest-path"]) - .arg(self.workspace_root.join("Cargo.toml").as_os_str()); + cmd.args(&["--message-format=json"]); + + // If we check single crates, then check just that crate's cargo.toml + // + // Else, check the entire workspace + if let Some(single) = single_crate.as_ref() { + cmd.arg("--manifest-path"); + cmd.arg(single.join("Cargo.toml").as_os_str()); + cmd.current_dir(single); + } else { + cmd.arg("--workspace"); + cmd.arg("--manifest-path"); + cmd.arg(self.workspace_root.join("Cargo.toml").as_os_str()); + cmd.current_dir(&self.workspace_root); + } if let Some(target) = target_triple { cmd.args(&["--target", target.as_str()]); @@ -292,11 +307,10 @@ impl FlycheckActor { let mut cmd = Command::new(command); cmd.args(args); cmd.envs(extra_env); + cmd.current_dir(&self.workspace_root); cmd } - }; - cmd.current_dir(&self.workspace_root); - cmd + } } fn send(&self, check_task: Message) { diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 577a8640a4c0..24e470a0176a 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -148,6 +148,18 @@ config_data! { /// `#rust-analyzer.cargo.target#`. checkOnSave_target: Option = "null", + /// Only check the currently opened crate of a workspace. + /// + /// Lets Rust analyzer perform less work by only checking the currently + /// opened crate when a crate of a workspace is opened alone. This + /// means you won't receive diagnostics about the entire workspace, but + /// can significantly improve performance when single crates are modified + /// as part of a much larger workspace. + /// + /// Defaults to + /// `#rust-analyzer.cargo.target#`. + checkSingleCrate_enable: bool = "false", + /// Toggles the additional completions that automatically add imports when completed. /// Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled. completion_autoimport_enable: bool = "true", @@ -1116,11 +1128,19 @@ impl Config { }, extra_args: self.data.checkOnSave_extraArgs.clone(), extra_env: self.check_on_save_extra_env(), + single_crate: self.get_crate_for_check(), }, }; Some(flycheck_config) } + fn get_crate_for_check(&self) -> Option { + match self.data.checkSingleCrate_enable { + true => Some(self.root_path().clone()), + false => None, + } + } + pub fn runnables(&self) -> RunnablesConfig { RunnablesConfig { override_cargo: self.data.runnables_command.clone(), diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc index acf0aaea859a..a9a74a731033 100644 --- a/docs/user/generated_config.adoc +++ b/docs/user/generated_config.adoc @@ -152,6 +152,20 @@ cargo check --workspace --message-format=json --all-targets Check for a specific target. Defaults to `#rust-analyzer.cargo.target#`. -- +[[rust-analyzer.checkSingleCrate.enable]]rust-analyzer.checkSingleCrate.enable (default: `false`):: ++ +-- +Only check the currently opened crate of a workspace. + +Lets Rust analyzer perform less work by only checking the currently +opened crate when a crate of a workspace is opened alone. This +means you won't receive diagnostics about the entire workspace, but +can significantly improve performance when single crates are modified +as part of a much larger workspace. + + Defaults to +`#rust-analyzer.cargo.target#`. +-- [[rust-analyzer.completion.autoimport.enable]]rust-analyzer.completion.autoimport.enable (default: `true`):: + -- diff --git a/editors/code/package.json b/editors/code/package.json index f1dd3aa79ff0..c2c29223aacc 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -573,6 +573,11 @@ "string" ] }, + "rust-analyzer.checkSingleCrate.enable": { + "markdownDescription": "Only check the currently opened crate of a workspace.\n\nLets Rust analyzer perform less work by only checking the currently\nopened crate when a crate of a workspace is opened alone. This\nmeans you won't receive diagnostics about the entire workspace, but\ncan significantly improve performance when single crates are modified\nas part of a much larger workspace.\n\n Defaults to\n`#rust-analyzer.cargo.target#`.", + "default": false, + "type": "boolean" + }, "rust-analyzer.completion.autoimport.enable": { "markdownDescription": "Toggles the additional completions that automatically add imports when completed.\nNote that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.", "default": true,