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