Unnamed repository; edit this file 'description' to name the repository.
flycheck: Support {label} in check_overrideCommand as well as $saved_file
Cormac Relf 4 months ago
parent 95b5dc0 · commit 210aff3
-rw-r--r--crates/rust-analyzer/src/flycheck.rs38
1 files changed, 16 insertions, 22 deletions
diff --git a/crates/rust-analyzer/src/flycheck.rs b/crates/rust-analyzer/src/flycheck.rs
index 1b1e3344e2..cf4ab29b86 100644
--- a/crates/rust-analyzer/src/flycheck.rs
+++ b/crates/rust-analyzer/src/flycheck.rs
@@ -872,29 +872,23 @@ impl FlycheckActor {
&*self.root
}
};
- let mut cmd = toolchain::command(command, root, extra_env);
-
- // If the custom command has a $saved_file placeholder, and
- // we're saving a file, replace the placeholder in the arguments.
- if let Some(saved_file) = saved_file {
- for arg in args {
- if arg == SAVED_FILE_PLACEHOLDER_DOLLAR {
- cmd.arg(saved_file);
- } else {
- cmd.arg(arg);
- }
- }
- } else {
- for arg in args {
- if arg == SAVED_FILE_PLACEHOLDER_DOLLAR {
- // The custom command has a $saved_file placeholder,
- // but we had an IDE event that wasn't a file save. Do nothing.
- return None;
- }
+ let runnable = project_json::Runnable {
+ program: command.clone(),
+ cwd: Utf8Path::to_owned(root.as_ref()),
+ args: args.clone(),
+ kind: project_json::RunnableKind::Flycheck,
+ };
- cmd.arg(arg);
- }
- }
+ let label = match scope {
+ FlycheckScope::Workspace => None,
+ // We support substituting both build labels (e.g. buck, bazel) and cargo package ids.
+ // With cargo package ids, you get `cargo check -p path+file:///path/to/rust-analyzer/crates/hir#0.0.0`.
+ // That does work!
+ FlycheckScope::Package { package, .. } => Some(package.as_str()),
+ };
+
+ let subs = Substitutions { label, saved_file: saved_file.map(|x| x.as_str()) };
+ let cmd = subs.substitute(&runnable, extra_env)?;
Some(cmd)
}