aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r--crates/ra_hir_def/src/import_map.rs21
1 files changed, 12 insertions, 9 deletions
diff --git a/crates/ra_hir_def/src/import_map.rs b/crates/ra_hir_def/src/import_map.rs
index a55d7d83b..36b4fdd81 100644
--- a/crates/ra_hir_def/src/import_map.rs
+++ b/crates/ra_hir_def/src/import_map.rs
@@ -1,10 +1,11 @@
1//! A map of all publicly exported items in a crate. 1//! A map of all publicly exported items in a crate.
2 2
3use std::{cmp::Ordering, collections::hash_map::Entry, fmt, sync::Arc}; 3use std::{cmp::Ordering, fmt, hash::BuildHasherDefault, sync::Arc};
4 4
5use fst::{self, Streamer}; 5use fst::{self, Streamer};
6use indexmap::{map::Entry, IndexMap};
6use ra_db::CrateId; 7use ra_db::CrateId;
7use rustc_hash::FxHashMap; 8use rustc_hash::FxHasher;
8 9
9use crate::{ 10use crate::{
10 db::DefDatabase, 11 db::DefDatabase,
@@ -14,6 +15,8 @@ use crate::{
14 ModuleDefId, ModuleId, 15 ModuleDefId, ModuleId,
15}; 16};
16 17
18type FxIndexMap<K, V> = IndexMap<K, V, BuildHasherDefault<FxHasher>>;
19
17/// A map from publicly exported items to the path needed to import/name them from a downstream 20/// A map from publicly exported items to the path needed to import/name them from a downstream
18/// crate. 21/// crate.
19/// 22///
@@ -23,7 +26,7 @@ use crate::{
23/// Note that all paths are relative to the containing crate's root, so the crate name still needs 26/// Note that all paths are relative to the containing crate's root, so the crate name still needs
24/// to be prepended to the `ModPath` before the path is valid. 27/// to be prepended to the `ModPath` before the path is valid.
25pub struct ImportMap { 28pub struct ImportMap {
26 map: FxHashMap<ItemInNs, ModPath>, 29 map: FxIndexMap<ItemInNs, ModPath>,
27 30
28 /// List of keys stored in `map`, sorted lexicographically by their `ModPath`. Indexed by the 31 /// List of keys stored in `map`, sorted lexicographically by their `ModPath`. Indexed by the
29 /// values returned by running `fst`. 32 /// values returned by running `fst`.
@@ -39,7 +42,7 @@ impl ImportMap {
39 pub fn import_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<Self> { 42 pub fn import_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<Self> {
40 let _p = ra_prof::profile("import_map_query"); 43 let _p = ra_prof::profile("import_map_query");
41 let def_map = db.crate_def_map(krate); 44 let def_map = db.crate_def_map(krate);
42 let mut import_map = FxHashMap::with_capacity_and_hasher(64, Default::default()); 45 let mut import_map = FxIndexMap::with_capacity_and_hasher(64, Default::default());
43 46
44 // We look only into modules that are public(ly reexported), starting with the crate root. 47 // We look only into modules that are public(ly reexported), starting with the crate root.
45 let empty = ModPath { kind: PathKind::Plain, segments: vec![] }; 48 let empty = ModPath { kind: PathKind::Plain, segments: vec![] };
@@ -588,9 +591,9 @@ mod tests {
588 591
589 let res = search_dependencies_of(ra_fixture, "main", Query::new("fmt")); 592 let res = search_dependencies_of(ra_fixture, "main", Query::new("fmt"));
590 assert_snapshot!(res, @r###" 593 assert_snapshot!(res, @r###"
591 dep::Fmt (v)
592 dep::fmt (t) 594 dep::fmt (t)
593 dep::Fmt (t) 595 dep::Fmt (t)
596 dep::Fmt (v)
594 dep::Fmt (m) 597 dep::Fmt (m)
595 dep::fmt::Display (t) 598 dep::fmt::Display (t)
596 dep::format (v) 599 dep::format (v)
@@ -598,9 +601,9 @@ mod tests {
598 601
599 let res = search_dependencies_of(ra_fixture, "main", Query::new("fmt").anchor_end()); 602 let res = search_dependencies_of(ra_fixture, "main", Query::new("fmt").anchor_end());
600 assert_snapshot!(res, @r###" 603 assert_snapshot!(res, @r###"
601 dep::Fmt (v)
602 dep::fmt (t) 604 dep::fmt (t)
603 dep::Fmt (t) 605 dep::Fmt (t)
606 dep::Fmt (v)
604 dep::Fmt (m) 607 dep::Fmt (m)
605 "###); 608 "###);
606 } 609 }
@@ -618,17 +621,17 @@ mod tests {
618 let res = search_dependencies_of(ra_fixture, "main", Query::new("FMT")); 621 let res = search_dependencies_of(ra_fixture, "main", Query::new("FMT"));
619 622
620 assert_snapshot!(res, @r###" 623 assert_snapshot!(res, @r###"
621 dep::FMT (v)
622 dep::FMT (t)
623 dep::fmt (t) 624 dep::fmt (t)
624 dep::fmt (v) 625 dep::fmt (v)
626 dep::FMT (t)
627 dep::FMT (v)
625 "###); 628 "###);
626 629
627 let res = search_dependencies_of(ra_fixture, "main", Query::new("FMT").case_sensitive()); 630 let res = search_dependencies_of(ra_fixture, "main", Query::new("FMT").case_sensitive());
628 631
629 assert_snapshot!(res, @r###" 632 assert_snapshot!(res, @r###"
630 dep::FMT (v)
631 dep::FMT (t) 633 dep::FMT (t)
634 dep::FMT (v)
632 "###); 635 "###);
633 } 636 }
634 637