Skip to content

Commit 8f17f3d

Browse files
Deduplicate search_dependencies results
1 parent d54e115 commit 8f17f3d

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

crates/hir_def/src/import_map.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ pub fn search_dependencies<'a>(
388388
db: &'a dyn DefDatabase,
389389
krate: CrateId,
390390
query: Query,
391-
) -> Vec<ItemInNs> {
391+
) -> FxHashSet<ItemInNs> {
392392
let _p = profile::span("search_dependencies").detail(|| format!("{:?}", query));
393393

394394
let graph = db.crate_graph();
@@ -403,7 +403,7 @@ pub fn search_dependencies<'a>(
403403
}
404404

405405
let mut stream = op.union();
406-
let mut res = Vec::new();
406+
let mut res = FxHashSet::default();
407407
while let Some((_, indexed_values)) = stream.next() {
408408
for indexed_value in indexed_values {
409409
let import_map = &import_maps[indexed_value.index];
@@ -435,7 +435,6 @@ pub fn search_dependencies<'a>(
435435
res.extend(iter);
436436

437437
if res.len() >= query.limit {
438-
res.truncate(query.limit);
439438
return res;
440439
}
441440
}
@@ -821,10 +820,10 @@ mod tests {
821820
Query::new("fmt".to_string()).search_mode(SearchMode::Fuzzy),
822821
expect![[r#"
823822
dep::fmt (t)
823+
dep::fmt::Display::format_method (a)
824824
dep::fmt::Display (t)
825825
dep::fmt::Display::FMT_CONST (a)
826826
dep::fmt::Display::format_function (a)
827-
dep::fmt::Display::format_method (a)
828827
"#]],
829828
);
830829
}
@@ -850,9 +849,9 @@ mod tests {
850849
"main",
851850
Query::new("fmt".to_string()).search_mode(SearchMode::Fuzzy).assoc_items_only(),
852851
expect![[r#"
852+
dep::fmt::Display::format_method (a)
853853
dep::fmt::Display::FMT_CONST (a)
854854
dep::fmt::Display::format_function (a)
855-
dep::fmt::Display::format_method (a)
856855
"#]],
857856
);
858857

@@ -911,12 +910,12 @@ mod tests {
911910
Query::new("fmt".to_string()).search_mode(SearchMode::Fuzzy),
912911
expect![[r#"
913912
dep::fmt (t)
914-
dep::Fmt (t)
913+
dep::format (f)
915914
dep::Fmt (v)
916-
dep::Fmt (m)
917915
dep::fmt::Display (t)
916+
dep::Fmt (t)
918917
dep::fmt::Display::fmt (a)
919-
dep::format (f)
918+
dep::Fmt (m)
920919
"#]],
921920
);
922921

@@ -926,10 +925,10 @@ mod tests {
926925
Query::new("fmt".to_string()).search_mode(SearchMode::Equals),
927926
expect![[r#"
928927
dep::fmt (t)
929-
dep::Fmt (t)
930928
dep::Fmt (v)
931-
dep::Fmt (m)
929+
dep::Fmt (t)
932930
dep::fmt::Display::fmt (a)
931+
dep::Fmt (m)
933932
"#]],
934933
);
935934

@@ -939,11 +938,11 @@ mod tests {
939938
Query::new("fmt".to_string()).search_mode(SearchMode::Contains),
940939
expect![[r#"
941940
dep::fmt (t)
942-
dep::Fmt (t)
943941
dep::Fmt (v)
944-
dep::Fmt (m)
945942
dep::fmt::Display (t)
943+
dep::Fmt (t)
946944
dep::fmt::Display::fmt (a)
945+
dep::Fmt (m)
947946
"#]],
948947
);
949948
}
@@ -980,11 +979,11 @@ mod tests {
980979
Query::new("fmt".to_string()),
981980
expect![[r#"
982981
dep::fmt (t)
983-
dep::Fmt (t)
984982
dep::Fmt (v)
985-
dep::Fmt (m)
986983
dep::fmt::Display (t)
984+
dep::Fmt (t)
987985
dep::fmt::Display::fmt (a)
986+
dep::Fmt (m)
988987
"#]],
989988
);
990989

@@ -994,10 +993,10 @@ mod tests {
994993
Query::new("fmt".to_string()).name_only(),
995994
expect![[r#"
996995
dep::fmt (t)
997-
dep::Fmt (t)
998996
dep::Fmt (v)
999-
dep::Fmt (m)
997+
dep::Fmt (t)
1000998
dep::fmt::Display::fmt (a)
999+
dep::Fmt (m)
10011000
"#]],
10021001
);
10031002
}
@@ -1018,9 +1017,9 @@ mod tests {
10181017
Query::new("FMT".to_string()),
10191018
expect![[r#"
10201019
dep::fmt (t)
1020+
dep::FMT (v)
10211021
dep::fmt (v)
10221022
dep::FMT (t)
1023-
dep::FMT (v)
10241023
"#]],
10251024
);
10261025

@@ -1060,6 +1059,8 @@ mod tests {
10601059
expect![[r#"
10611060
dep::fmt (t)
10621061
dep::Fmt (t)
1062+
dep::Fmt (m)
1063+
dep::Fmt (v)
10631064
"#]],
10641065
);
10651066
}
@@ -1080,9 +1081,9 @@ mod tests {
10801081
Query::new("FMT".to_string()),
10811082
expect![[r#"
10821083
dep::fmt (t)
1084+
dep::FMT (v)
10831085
dep::fmt (v)
10841086
dep::FMT (t)
1085-
dep::FMT (v)
10861087
"#]],
10871088
);
10881089

0 commit comments

Comments
 (0)