Skip to content

Commit d7ec7a5

Browse files
committed
Auto merge of #16847 - HKalbasi:test-explorer, r=HKalbasi
Distinguish integration tests from crates in test explorer Fix part of #16827
2 parents f9a4d05 + dcfc9cc commit d7ec7a5

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

crates/ide/src/test_explorer.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{navigation_target::ToNav, runnables::runnable_fn, Runnable, TryToNav
1111

1212
#[derive(Debug)]
1313
pub enum TestItemKind {
14-
Crate,
14+
Crate(CrateId),
1515
Module,
1616
Function,
1717
}
@@ -32,15 +32,17 @@ pub(crate) fn discover_test_roots(db: &RootDatabase) -> Vec<TestItem> {
3232
crate_graph
3333
.iter()
3434
.filter(|&id| crate_graph[id].origin.is_local())
35-
.filter_map(|id| Some(crate_graph[id].display_name.as_ref()?.to_string()))
36-
.map(|id| TestItem {
37-
kind: TestItemKind::Crate,
38-
label: id.clone(),
39-
id,
40-
parent: None,
41-
file: None,
42-
text_range: None,
43-
runnable: None,
35+
.filter_map(|id| {
36+
let test_id = crate_graph[id].display_name.as_ref()?.to_string();
37+
Some(TestItem {
38+
kind: TestItemKind::Crate(id),
39+
label: test_id.clone(),
40+
id: test_id,
41+
parent: None,
42+
file: None,
43+
text_range: None,
44+
runnable: None,
45+
})
4446
})
4547
.collect()
4648
}
@@ -118,12 +120,13 @@ pub(crate) fn discover_tests_in_crate(db: &RootDatabase, crate_id: CrateId) -> V
118120
let Some(crate_test_id) = &crate_graph[crate_id].display_name else {
119121
return vec![];
120122
};
123+
let kind = TestItemKind::Crate(crate_id);
121124
let crate_test_id = crate_test_id.to_string();
122125
let crate_id: Crate = crate_id.into();
123126
let module = crate_id.root_module();
124127
let mut r = vec![TestItem {
125128
id: crate_test_id.clone(),
126-
kind: TestItemKind::Crate,
129+
kind,
127130
label: crate_test_id.clone(),
128131
parent: None,
129132
file: None,

crates/rust-analyzer/src/lsp/to_proto.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -1519,13 +1519,28 @@ pub(crate) fn test_item(
15191519
id: test_item.id,
15201520
label: test_item.label,
15211521
kind: match test_item.kind {
1522-
ide::TestItemKind::Crate => lsp_ext::TestItemKind::Package,
1522+
ide::TestItemKind::Crate(id) => 'b: {
1523+
let Some((cargo_ws, target)) = snap.cargo_target_for_crate_root(id) else {
1524+
break 'b lsp_ext::TestItemKind::Package;
1525+
};
1526+
let target = &cargo_ws[target];
1527+
match target.kind {
1528+
project_model::TargetKind::Bin
1529+
| project_model::TargetKind::Lib { .. }
1530+
| project_model::TargetKind::Example
1531+
| project_model::TargetKind::BuildScript
1532+
| project_model::TargetKind::Other => lsp_ext::TestItemKind::Package,
1533+
project_model::TargetKind::Test | project_model::TargetKind::Bench => {
1534+
lsp_ext::TestItemKind::Test
1535+
}
1536+
}
1537+
}
15231538
ide::TestItemKind::Module => lsp_ext::TestItemKind::Module,
15241539
ide::TestItemKind::Function => lsp_ext::TestItemKind::Test,
15251540
},
15261541
can_resolve_children: matches!(
15271542
test_item.kind,
1528-
ide::TestItemKind::Crate | ide::TestItemKind::Module
1543+
ide::TestItemKind::Crate(_) | ide::TestItemKind::Module
15291544
),
15301545
parent: test_item.parent,
15311546
text_document: test_item

0 commit comments

Comments
 (0)