From e33e1766ae4b7db006270cdf00afe111c20f5682 Mon Sep 17 00:00:00 2001 From: Troy Benson Date: Wed, 6 Aug 2025 14:02:31 -0400 Subject: [PATCH 1/3] fix: project json runnable kind bin substitution fixes a bug related to substitution in project json bin not correctly replacing the `{label}` tag with the label of the current item. --- crates/ide/src/runnables.rs | 14 +++++-- crates/rust-analyzer/src/target_spec.rs | 54 ++++++++++++------------- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index 83e5c5ab1dfe..32e6fb6079ad 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -43,15 +43,21 @@ pub enum TestId { Path(String), } -impl fmt::Display for TestId { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { +impl AsRef for TestId { + fn as_ref(&self) -> &str { match self { - TestId::Name(name) => name.fmt(f), - TestId::Path(path) => path.fmt(f), + Self::Name(n) => &n, + Self::Path(p) => &p, } } } +impl fmt::Display for TestId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(self.as_ref()) + } +} + #[derive(Debug, Clone, Hash, PartialEq, Eq)] pub enum RunnableKind { TestMod { path: String }, diff --git a/crates/rust-analyzer/src/target_spec.rs b/crates/rust-analyzer/src/target_spec.rs index 7132e09146eb..b16d57b6ea9d 100644 --- a/crates/rust-analyzer/src/target_spec.rs +++ b/crates/rust-analyzer/src/target_spec.rs @@ -70,34 +70,32 @@ pub(crate) struct ProjectJsonTargetSpec { impl ProjectJsonTargetSpec { pub(crate) fn runnable_args(&self, kind: &RunnableKind) -> Option { match kind { - RunnableKind::Bin => { - for runnable in &self.shell_runnables { - if matches!(runnable.kind, project_model::project_json::RunnableKind::Run) { - return Some(runnable.clone()); - } - } - - None - } - RunnableKind::Test { test_id, .. } => { - for runnable in &self.shell_runnables { - if matches!(runnable.kind, project_model::project_json::RunnableKind::TestOne) { - let mut runnable = runnable.clone(); - - let replaced_args: Vec<_> = runnable - .args - .iter() - .map(|arg| arg.replace("{test_id}", &test_id.to_string())) - .map(|arg| arg.replace("{label}", &self.label)) - .collect(); - runnable.args = replaced_args; - - return Some(runnable); - } - } - - None - } + RunnableKind::Bin => self + .shell_runnables + .iter() + .find(|r| matches!(r.kind, project_model::project_json::RunnableKind::Run)) + .cloned() + .map(|mut runnable| { + runnable.args.iter_mut().for_each(|arg| { + *arg = arg.replace("{label}", &self.label); + }); + + runnable + }), + RunnableKind::Test { test_id, .. } => self + .shell_runnables + .iter() + .find(|r| matches!(r.kind, project_model::project_json::RunnableKind::TestOne)) + .cloned() + .map(|mut runnable| { + runnable.args.iter_mut().for_each(|arg| { + *arg = arg + .replace("{label}", &self.label) + .replace("{test_id}", test_id.as_ref()); + }); + + runnable + }), RunnableKind::TestMod { .. } => None, RunnableKind::Bench { .. } => None, RunnableKind::DocTest { .. } => None, From 80975b845fba6e90aed21a19e8ecb74a3e051382 Mon Sep 17 00:00:00 2001 From: Troy Benson Date: Wed, 6 Aug 2025 14:11:57 -0400 Subject: [PATCH 2/3] fix clippy --- crates/ide/src/runnables.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index 32e6fb6079ad..ba34b0c34e54 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -46,8 +46,8 @@ pub enum TestId { impl AsRef for TestId { fn as_ref(&self) -> &str { match self { - Self::Name(n) => &n, - Self::Path(p) => &p, + Self::Name(n) => n, + Self::Path(p) => p, } } } From 2f064dd63c53609d0d7c50c75aa007c58aa864b9 Mon Sep 17 00:00:00 2001 From: Troy Benson Date: Fri, 8 Aug 2025 13:15:28 -0400 Subject: [PATCH 3/3] dont use as_ref --- crates/ide/src/runnables.rs | 6 +++--- crates/rust-analyzer/src/target_spec.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index ba34b0c34e54..707b1c8bdbf0 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -43,8 +43,8 @@ pub enum TestId { Path(String), } -impl AsRef for TestId { - fn as_ref(&self) -> &str { +impl TestId { + pub fn as_str(&self) -> &str { match self { Self::Name(n) => n, Self::Path(p) => p, @@ -54,7 +54,7 @@ impl AsRef for TestId { impl fmt::Display for TestId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str(self.as_ref()) + f.write_str(self.as_str()) } } diff --git a/crates/rust-analyzer/src/target_spec.rs b/crates/rust-analyzer/src/target_spec.rs index b16d57b6ea9d..cba06d41109a 100644 --- a/crates/rust-analyzer/src/target_spec.rs +++ b/crates/rust-analyzer/src/target_spec.rs @@ -91,7 +91,7 @@ impl ProjectJsonTargetSpec { runnable.args.iter_mut().for_each(|arg| { *arg = arg .replace("{label}", &self.label) - .replace("{test_id}", test_id.as_ref()); + .replace("{test_id}", test_id.as_str()); }); runnable