From 14930e85c8c8fa66c4d477ab41b95fd2d236e9b7 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Sun, 2 Oct 2022 16:16:08 -0700 Subject: [PATCH 1/2] feat: add a new command that limits workspace checks Allow RA to ignore checking workspaces when single subcrates are open. When the workspace is open, RA will still check the entire workspace. But, now when a single crate is open, RA won't check those. --- crates/flycheck/src/lib.rs | 26 ++++++++++++++++++++------ crates/rust-analyzer/src/config.rs | 11 +++++++++++ 2 files changed, 31 insertions(+), 6 deletions(-) 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..5a85ca8e10da 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -455,6 +455,9 @@ config_data! { workspace_symbol_search_limit: usize = "128", /// Workspace symbol search scope. workspace_symbol_search_scope: WorkspaceSymbolSearchScopeDef = "\"workspace\"", + + /// Only check the current crate + checkSingleCrate_enable: bool = "false", } } @@ -1116,11 +1119,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(), From 5ff0a656c8ba8e8090e928682c00f4879370a397 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Sun, 2 Oct 2022 16:34:35 -0700 Subject: [PATCH 2/2] chore: make PR pass CI --- crates/rust-analyzer/src/config.rs | 15 ++++++++++++--- docs/user/generated_config.adoc | 14 ++++++++++++++ editors/code/package.json | 5 +++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 5a85ca8e10da..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", @@ -455,9 +467,6 @@ config_data! { workspace_symbol_search_limit: usize = "128", /// Workspace symbol search scope. workspace_symbol_search_scope: WorkspaceSymbolSearchScopeDef = "\"workspace\"", - - /// Only check the current crate - checkSingleCrate_enable: bool = "false", } } 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,