mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
Auto merge of #16971 - HKalbasi:test-explorer, r=HKalbasi
Resolve tests per file instead of per crate in test explorer Fix part of #16827
This commit is contained in:
commit
a8b7acf22f
8 changed files with 143 additions and 41 deletions
|
@ -238,9 +238,12 @@ pub(crate) fn handle_discover_test(
|
|||
let (tests, scope) = match params.test_id {
|
||||
Some(id) => {
|
||||
let crate_id = id.split_once("::").map(|it| it.0).unwrap_or(&id);
|
||||
(snap.analysis.discover_tests_in_crate_by_test_id(crate_id)?, vec![crate_id.to_owned()])
|
||||
(
|
||||
snap.analysis.discover_tests_in_crate_by_test_id(crate_id)?,
|
||||
Some(vec![crate_id.to_owned()]),
|
||||
)
|
||||
}
|
||||
None => (snap.analysis.discover_test_roots()?, vec![]),
|
||||
None => (snap.analysis.discover_test_roots()?, None),
|
||||
};
|
||||
for t in &tests {
|
||||
hack_recover_crate_name::insert_name(t.id.clone());
|
||||
|
@ -254,6 +257,7 @@ pub(crate) fn handle_discover_test(
|
|||
})
|
||||
.collect(),
|
||||
scope,
|
||||
scope_file: None,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -194,7 +194,8 @@ pub struct TestItem {
|
|||
#[serde(rename_all = "camelCase")]
|
||||
pub struct DiscoverTestResults {
|
||||
pub tests: Vec<TestItem>,
|
||||
pub scope: Vec<String>,
|
||||
pub scope: Option<Vec<String>>,
|
||||
pub scope_file: Option<Vec<TextDocumentIdentifier>>,
|
||||
}
|
||||
|
||||
pub enum DiscoverTest {}
|
||||
|
|
|
@ -9,9 +9,8 @@ use std::{
|
|||
use always_assert::always;
|
||||
use crossbeam_channel::{never, select, Receiver};
|
||||
use ide_db::base_db::{SourceDatabase, SourceDatabaseExt, VfsPath};
|
||||
use itertools::Itertools;
|
||||
use lsp_server::{Connection, Notification, Request};
|
||||
use lsp_types::notification::Notification as _;
|
||||
use lsp_types::{notification::Notification as _, TextDocumentIdentifier};
|
||||
use stdx::thread::ThreadIntent;
|
||||
use vfs::FileId;
|
||||
|
||||
|
@ -533,22 +532,14 @@ impl GlobalState {
|
|||
let snapshot = self.snapshot();
|
||||
move || {
|
||||
let tests = subscriptions
|
||||
.into_iter()
|
||||
.filter_map(|f| snapshot.analysis.crates_for(f).ok())
|
||||
.flatten()
|
||||
.unique()
|
||||
.filter_map(|c| snapshot.analysis.discover_tests_in_crate(c).ok())
|
||||
.iter()
|
||||
.copied()
|
||||
.filter_map(|f| snapshot.analysis.discover_tests_in_file(f).ok())
|
||||
.flatten()
|
||||
.collect::<Vec<_>>();
|
||||
for t in &tests {
|
||||
hack_recover_crate_name::insert_name(t.id.clone());
|
||||
}
|
||||
let scope = tests
|
||||
.iter()
|
||||
.filter_map(|t| Some(t.id.split_once("::")?.0))
|
||||
.unique()
|
||||
.map(|it| it.to_owned())
|
||||
.collect();
|
||||
Task::DiscoverTest(lsp_ext::DiscoverTestResults {
|
||||
tests: tests
|
||||
.into_iter()
|
||||
|
@ -557,7 +548,13 @@ impl GlobalState {
|
|||
to_proto::test_item(&snapshot, t, line_index.as_ref())
|
||||
})
|
||||
.collect(),
|
||||
scope,
|
||||
scope: None,
|
||||
scope_file: Some(
|
||||
subscriptions
|
||||
.into_iter()
|
||||
.map(|f| TextDocumentIdentifier { uri: to_proto::url(&snapshot, f) })
|
||||
.collect(),
|
||||
),
|
||||
})
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue