Unnamed repository; edit this file 'description' to name the repository.
Support more runnable kinds for project json
Allows project JSON users to run a whole module of tests, benchmarks, doctests.
Cormac Relf 4 months ago
parent 5ef0f51 · commit 7657739
-rw-r--r--crates/project-model/src/project_json.rs21
-rw-r--r--crates/rust-analyzer/src/target_spec.rs17
2 files changed, 35 insertions, 3 deletions
diff --git a/crates/project-model/src/project_json.rs b/crates/project-model/src/project_json.rs
index cbbb95cc46..201c59039b 100644
--- a/crates/project-model/src/project_json.rs
+++ b/crates/project-model/src/project_json.rs
@@ -365,6 +365,21 @@ pub enum RunnableKind {
/// May include {test_id} which will get the test clicked on by the user.
TestOne,
+ /// Run tests matching a pattern (in RA, usually a path::to::module::of::tests)
+ /// May include {label} which will get the label from the `build` section of a crate.
+ /// May include {test_pattern} which will get the test module clicked on by the user.
+ TestMod,
+
+ /// Run a single doctest
+ /// May include {label} which will get the label from the `build` section of a crate.
+ /// May include {test_id} which will get the doctest clicked on by the user.
+ DocTestOne,
+
+ /// Run a single benchmark
+ /// May include {label} which will get the label from the `build` section of a crate.
+ /// May include {bench_id} which will get the benchmark clicked on by the user.
+ BenchOne,
+
/// Template for checking a target, emitting rustc JSON diagnostics.
/// May include {label} which will get the label from the `build` section of a crate.
Flycheck,
@@ -481,6 +496,9 @@ pub enum RunnableKindData {
Check,
Run,
TestOne,
+ TestMod,
+ DocTestOne,
+ BenchOne,
/// For forwards-compatibility, i.e. old rust-analyzer binary with newer workspace discovery tools
#[allow(unused)]
@@ -553,6 +571,9 @@ impl From<RunnableKindData> for RunnableKind {
RunnableKindData::Check => RunnableKind::Check,
RunnableKindData::Run => RunnableKind::Run,
RunnableKindData::TestOne => RunnableKind::TestOne,
+ RunnableKindData::TestMod => RunnableKind::TestMod,
+ RunnableKindData::DocTestOne => RunnableKind::DocTestOne,
+ RunnableKindData::BenchOne => RunnableKind::BenchOne,
RunnableKindData::Flycheck => RunnableKind::Flycheck,
RunnableKindData::Unknown => RunnableKind::Unknown,
}
diff --git a/crates/rust-analyzer/src/target_spec.rs b/crates/rust-analyzer/src/target_spec.rs
index c87eefc695..b96786cae9 100644
--- a/crates/rust-analyzer/src/target_spec.rs
+++ b/crates/rust-analyzer/src/target_spec.rs
@@ -103,9 +103,20 @@ impl ProjectJsonTargetSpec {
arg.replace("{label}", &this.label).replace("{test_id}", &test_id.to_string())
})
}
- RunnableKind::TestMod { .. } => None,
- RunnableKind::Bench { .. } => None,
- RunnableKind::DocTest { .. } => None,
+ RunnableKind::TestMod { path } => self
+ .find_replace_runnable(project_json::RunnableKind::TestMod, &|this, arg| {
+ arg.replace("{label}", &this.label).replace("{test_pattern}", path)
+ }),
+ RunnableKind::Bench { test_id } => {
+ self.find_replace_runnable(project_json::RunnableKind::BenchOne, &|this, arg| {
+ arg.replace("{label}", &this.label).replace("{bench_id}", &test_id.to_string())
+ })
+ }
+ RunnableKind::DocTest { test_id } => {
+ self.find_replace_runnable(project_json::RunnableKind::DocTestOne, &|this, arg| {
+ arg.replace("{label}", &this.label).replace("{test_id}", &test_id.to_string())
+ })
+ }
}
}
}