diff options
Diffstat (limited to 'crates/hir_def/src/import_map.rs')
-rw-r--r-- | crates/hir_def/src/import_map.rs | 101 |
1 files changed, 51 insertions, 50 deletions
diff --git a/crates/hir_def/src/import_map.rs b/crates/hir_def/src/import_map.rs index 0a3dc7956..369bc3350 100644 --- a/crates/hir_def/src/import_map.rs +++ b/crates/hir_def/src/import_map.rs | |||
@@ -8,7 +8,6 @@ use hir_expand::name::Name; | |||
8 | use indexmap::{map::Entry, IndexMap}; | 8 | use indexmap::{map::Entry, IndexMap}; |
9 | use itertools::Itertools; | 9 | use itertools::Itertools; |
10 | use rustc_hash::{FxHashSet, FxHasher}; | 10 | use rustc_hash::{FxHashSet, FxHasher}; |
11 | use test_utils::mark; | ||
12 | 11 | ||
13 | use crate::{ | 12 | use crate::{ |
14 | db::DefDatabase, item_scope::ItemInNs, visibility::Visibility, AssocItemId, ModuleDefId, | 13 | db::DefDatabase, item_scope::ItemInNs, visibility::Visibility, AssocItemId, ModuleDefId, |
@@ -193,7 +192,7 @@ impl ImportMap { | |||
193 | // cannot use associated type aliases directly: need a `<Struct as Trait>::TypeAlias` | 192 | // cannot use associated type aliases directly: need a `<Struct as Trait>::TypeAlias` |
194 | // qualifier, ergo no need to store it for imports in import_map | 193 | // qualifier, ergo no need to store it for imports in import_map |
195 | AssocItemId::TypeAliasId(_) => { | 194 | AssocItemId::TypeAliasId(_) => { |
196 | mark::hit!(type_aliases_ignored); | 195 | cov_mark::hit!(type_aliases_ignored); |
197 | continue; | 196 | continue; |
198 | } | 197 | } |
199 | }; | 198 | }; |
@@ -388,7 +387,7 @@ pub fn search_dependencies<'a>( | |||
388 | db: &'a dyn DefDatabase, | 387 | db: &'a dyn DefDatabase, |
389 | krate: CrateId, | 388 | krate: CrateId, |
390 | query: Query, | 389 | query: Query, |
391 | ) -> Vec<ItemInNs> { | 390 | ) -> FxHashSet<ItemInNs> { |
392 | let _p = profile::span("search_dependencies").detail(|| format!("{:?}", query)); | 391 | let _p = profile::span("search_dependencies").detail(|| format!("{:?}", query)); |
393 | 392 | ||
394 | let graph = db.crate_graph(); | 393 | let graph = db.crate_graph(); |
@@ -403,41 +402,42 @@ pub fn search_dependencies<'a>( | |||
403 | } | 402 | } |
404 | 403 | ||
405 | let mut stream = op.union(); | 404 | let mut stream = op.union(); |
406 | let mut res = Vec::new(); | 405 | |
406 | let mut all_indexed_values = FxHashSet::default(); | ||
407 | while let Some((_, indexed_values)) = stream.next() { | 407 | while let Some((_, indexed_values)) = stream.next() { |
408 | for indexed_value in indexed_values { | 408 | all_indexed_values.extend(indexed_values.iter().copied()); |
409 | let import_map = &import_maps[indexed_value.index]; | 409 | } |
410 | let importables = &import_map.importables[indexed_value.value as usize..]; | ||
411 | 410 | ||
412 | let common_importable_data = &import_map.map[&importables[0]]; | 411 | let mut res = FxHashSet::default(); |
413 | if !query.import_matches(common_importable_data, true) { | 412 | for indexed_value in all_indexed_values { |
414 | continue; | 413 | let import_map = &import_maps[indexed_value.index]; |
415 | } | 414 | let importables = &import_map.importables[indexed_value.value as usize..]; |
416 | 415 | ||
417 | // Path shared by the importable items in this group. | 416 | let common_importable_data = &import_map.map[&importables[0]]; |
418 | let common_importables_path_fst = fst_path(&common_importable_data.path); | 417 | if !query.import_matches(common_importable_data, true) { |
419 | // Add the items from this `ModPath` group. Those are all subsequent items in | 418 | continue; |
420 | // `importables` whose paths match `path`. | 419 | } |
421 | let iter = importables | 420 | |
422 | .iter() | 421 | // Path shared by the importable items in this group. |
423 | .copied() | 422 | let common_importables_path_fst = fst_path(&common_importable_data.path); |
424 | .take_while(|item| { | 423 | // Add the items from this `ModPath` group. Those are all subsequent items in |
425 | common_importables_path_fst == fst_path(&import_map.map[item].path) | 424 | // `importables` whose paths match `path`. |
426 | }) | 425 | let iter = importables |
427 | .filter(|&item| match item_import_kind(item) { | 426 | .iter() |
428 | Some(import_kind) => !query.exclude_import_kinds.contains(&import_kind), | 427 | .copied() |
429 | None => true, | 428 | .take_while(|item| common_importables_path_fst == fst_path(&import_map.map[item].path)) |
430 | }) | 429 | .filter(|&item| match item_import_kind(item) { |
431 | .filter(|item| { | 430 | Some(import_kind) => !query.exclude_import_kinds.contains(&import_kind), |
432 | !query.case_sensitive // we've already checked the common importables path case-insensitively | 431 | None => true, |
432 | }) | ||
433 | .filter(|item| { | ||
434 | !query.case_sensitive // we've already checked the common importables path case-insensitively | ||
433 | || query.import_matches(&import_map.map[item], false) | 435 | || query.import_matches(&import_map.map[item], false) |
434 | }); | 436 | }); |
435 | res.extend(iter); | 437 | res.extend(iter); |
436 | 438 | ||
437 | if res.len() >= query.limit { | 439 | if res.len() >= query.limit { |
438 | res.truncate(query.limit); | 440 | return res; |
439 | return res; | ||
440 | } | ||
441 | } | 441 | } |
442 | } | 442 | } |
443 | 443 | ||
@@ -462,7 +462,6 @@ fn item_import_kind(item: ItemInNs) -> Option<ImportKind> { | |||
462 | mod tests { | 462 | mod tests { |
463 | use base_db::{fixture::WithFixture, SourceDatabase, Upcast}; | 463 | use base_db::{fixture::WithFixture, SourceDatabase, Upcast}; |
464 | use expect_test::{expect, Expect}; | 464 | use expect_test::{expect, Expect}; |
465 | use test_utils::mark; | ||
466 | 465 | ||
467 | use crate::{test_db::TestDB, AssocContainerId, Lookup}; | 466 | use crate::{test_db::TestDB, AssocContainerId, Lookup}; |
468 | 467 | ||
@@ -800,7 +799,7 @@ mod tests { | |||
800 | 799 | ||
801 | #[test] | 800 | #[test] |
802 | fn fuzzy_import_trait_and_assoc_items() { | 801 | fn fuzzy_import_trait_and_assoc_items() { |
803 | mark::check!(type_aliases_ignored); | 802 | cov_mark::check!(type_aliases_ignored); |
804 | let ra_fixture = r#" | 803 | let ra_fixture = r#" |
805 | //- /main.rs crate:main deps:dep | 804 | //- /main.rs crate:main deps:dep |
806 | //- /dep.rs crate:dep | 805 | //- /dep.rs crate:dep |
@@ -821,10 +820,10 @@ mod tests { | |||
821 | Query::new("fmt".to_string()).search_mode(SearchMode::Fuzzy), | 820 | Query::new("fmt".to_string()).search_mode(SearchMode::Fuzzy), |
822 | expect![[r#" | 821 | expect![[r#" |
823 | dep::fmt (t) | 822 | dep::fmt (t) |
823 | dep::fmt::Display::format_method (a) | ||
824 | dep::fmt::Display (t) | 824 | dep::fmt::Display (t) |
825 | dep::fmt::Display::FMT_CONST (a) | 825 | dep::fmt::Display::FMT_CONST (a) |
826 | dep::fmt::Display::format_function (a) | 826 | dep::fmt::Display::format_function (a) |
827 | dep::fmt::Display::format_method (a) | ||
828 | "#]], | 827 | "#]], |
829 | ); | 828 | ); |
830 | } | 829 | } |
@@ -850,9 +849,9 @@ mod tests { | |||
850 | "main", | 849 | "main", |
851 | Query::new("fmt".to_string()).search_mode(SearchMode::Fuzzy).assoc_items_only(), | 850 | Query::new("fmt".to_string()).search_mode(SearchMode::Fuzzy).assoc_items_only(), |
852 | expect![[r#" | 851 | expect![[r#" |
852 | dep::fmt::Display::format_method (a) | ||
853 | dep::fmt::Display::FMT_CONST (a) | 853 | dep::fmt::Display::FMT_CONST (a) |
854 | dep::fmt::Display::format_function (a) | 854 | dep::fmt::Display::format_function (a) |
855 | dep::fmt::Display::format_method (a) | ||
856 | "#]], | 855 | "#]], |
857 | ); | 856 | ); |
858 | 857 | ||
@@ -911,12 +910,12 @@ mod tests { | |||
911 | Query::new("fmt".to_string()).search_mode(SearchMode::Fuzzy), | 910 | Query::new("fmt".to_string()).search_mode(SearchMode::Fuzzy), |
912 | expect![[r#" | 911 | expect![[r#" |
913 | dep::fmt (t) | 912 | dep::fmt (t) |
914 | dep::Fmt (t) | 913 | dep::format (f) |
915 | dep::Fmt (v) | 914 | dep::Fmt (v) |
916 | dep::Fmt (m) | ||
917 | dep::fmt::Display (t) | 915 | dep::fmt::Display (t) |
916 | dep::Fmt (t) | ||
918 | dep::fmt::Display::fmt (a) | 917 | dep::fmt::Display::fmt (a) |
919 | dep::format (f) | 918 | dep::Fmt (m) |
920 | "#]], | 919 | "#]], |
921 | ); | 920 | ); |
922 | 921 | ||
@@ -926,10 +925,10 @@ mod tests { | |||
926 | Query::new("fmt".to_string()).search_mode(SearchMode::Equals), | 925 | Query::new("fmt".to_string()).search_mode(SearchMode::Equals), |
927 | expect![[r#" | 926 | expect![[r#" |
928 | dep::fmt (t) | 927 | dep::fmt (t) |
929 | dep::Fmt (t) | ||
930 | dep::Fmt (v) | 928 | dep::Fmt (v) |
931 | dep::Fmt (m) | 929 | dep::Fmt (t) |
932 | dep::fmt::Display::fmt (a) | 930 | dep::fmt::Display::fmt (a) |
931 | dep::Fmt (m) | ||
933 | "#]], | 932 | "#]], |
934 | ); | 933 | ); |
935 | 934 | ||
@@ -939,11 +938,11 @@ mod tests { | |||
939 | Query::new("fmt".to_string()).search_mode(SearchMode::Contains), | 938 | Query::new("fmt".to_string()).search_mode(SearchMode::Contains), |
940 | expect![[r#" | 939 | expect![[r#" |
941 | dep::fmt (t) | 940 | dep::fmt (t) |
942 | dep::Fmt (t) | ||
943 | dep::Fmt (v) | 941 | dep::Fmt (v) |
944 | dep::Fmt (m) | ||
945 | dep::fmt::Display (t) | 942 | dep::fmt::Display (t) |
943 | dep::Fmt (t) | ||
946 | dep::fmt::Display::fmt (a) | 944 | dep::fmt::Display::fmt (a) |
945 | dep::Fmt (m) | ||
947 | "#]], | 946 | "#]], |
948 | ); | 947 | ); |
949 | } | 948 | } |
@@ -980,11 +979,11 @@ mod tests { | |||
980 | Query::new("fmt".to_string()), | 979 | Query::new("fmt".to_string()), |
981 | expect![[r#" | 980 | expect![[r#" |
982 | dep::fmt (t) | 981 | dep::fmt (t) |
983 | dep::Fmt (t) | ||
984 | dep::Fmt (v) | 982 | dep::Fmt (v) |
985 | dep::Fmt (m) | ||
986 | dep::fmt::Display (t) | 983 | dep::fmt::Display (t) |
984 | dep::Fmt (t) | ||
987 | dep::fmt::Display::fmt (a) | 985 | dep::fmt::Display::fmt (a) |
986 | dep::Fmt (m) | ||
988 | "#]], | 987 | "#]], |
989 | ); | 988 | ); |
990 | 989 | ||
@@ -994,10 +993,10 @@ mod tests { | |||
994 | Query::new("fmt".to_string()).name_only(), | 993 | Query::new("fmt".to_string()).name_only(), |
995 | expect![[r#" | 994 | expect![[r#" |
996 | dep::fmt (t) | 995 | dep::fmt (t) |
997 | dep::Fmt (t) | ||
998 | dep::Fmt (v) | 996 | dep::Fmt (v) |
999 | dep::Fmt (m) | 997 | dep::Fmt (t) |
1000 | dep::fmt::Display::fmt (a) | 998 | dep::fmt::Display::fmt (a) |
999 | dep::Fmt (m) | ||
1001 | "#]], | 1000 | "#]], |
1002 | ); | 1001 | ); |
1003 | } | 1002 | } |
@@ -1018,9 +1017,9 @@ mod tests { | |||
1018 | Query::new("FMT".to_string()), | 1017 | Query::new("FMT".to_string()), |
1019 | expect![[r#" | 1018 | expect![[r#" |
1020 | dep::fmt (t) | 1019 | dep::fmt (t) |
1020 | dep::FMT (v) | ||
1021 | dep::fmt (v) | 1021 | dep::fmt (v) |
1022 | dep::FMT (t) | 1022 | dep::FMT (t) |
1023 | dep::FMT (v) | ||
1024 | "#]], | 1023 | "#]], |
1025 | ); | 1024 | ); |
1026 | 1025 | ||
@@ -1060,6 +1059,8 @@ mod tests { | |||
1060 | expect![[r#" | 1059 | expect![[r#" |
1061 | dep::fmt (t) | 1060 | dep::fmt (t) |
1062 | dep::Fmt (t) | 1061 | dep::Fmt (t) |
1062 | dep::Fmt (m) | ||
1063 | dep::Fmt (v) | ||
1063 | "#]], | 1064 | "#]], |
1064 | ); | 1065 | ); |
1065 | } | 1066 | } |
@@ -1080,9 +1081,9 @@ mod tests { | |||
1080 | Query::new("FMT".to_string()), | 1081 | Query::new("FMT".to_string()), |
1081 | expect![[r#" | 1082 | expect![[r#" |
1082 | dep::fmt (t) | 1083 | dep::fmt (t) |
1084 | dep::FMT (v) | ||
1083 | dep::fmt (v) | 1085 | dep::fmt (v) |
1084 | dep::FMT (t) | 1086 | dep::FMT (t) |
1085 | dep::FMT (v) | ||
1086 | "#]], | 1087 | "#]], |
1087 | ); | 1088 | ); |
1088 | 1089 | ||