Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a new config that limits workspace checks to single crates #13336

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions crates/flycheck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub enum FlycheckConfig {
features: Vec<String>,
extra_args: Vec<String>,
extra_env: FxHashMap<String, String>,
single_crate: Option<AbsPathBuf>,
},
CustomCommand {
command: String,
Expand Down Expand Up @@ -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,
Expand All @@ -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()]);
Expand All @@ -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) {
Expand Down
20 changes: 20 additions & 0 deletions crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,18 @@ config_data! {
/// `#rust-analyzer.cargo.target#`.
checkOnSave_target: Option<String> = "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",
Expand Down Expand Up @@ -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<AbsPathBuf> {
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(),
Expand Down
14 changes: 14 additions & 0 deletions docs/user/generated_config.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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`)::
+
--
Expand Down
5 changes: 5 additions & 0 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down