@@ -9,17 +9,24 @@ use crate::{
9
9
} ;
10
10
use hir_expand:: name:: Name ;
11
11
12
+ const MAX_PATH_LEN : usize = 15 ;
13
+
12
14
pub fn find_path ( db : & impl DefDatabase , item : ItemInNs , from : ModuleId ) -> Option < ModPath > {
13
- find_path_inner ( db, item, from, 15 )
15
+ find_path_inner ( db, item, from, MAX_PATH_LEN )
14
16
}
15
17
16
- fn find_path_inner ( db : & impl DefDatabase , item : ItemInNs , from : ModuleId , max_len : usize ) -> Option < ModPath > {
17
- // Base cases:
18
-
18
+ fn find_path_inner (
19
+ db : & impl DefDatabase ,
20
+ item : ItemInNs ,
21
+ from : ModuleId ,
22
+ max_len : usize ,
23
+ ) -> Option < ModPath > {
19
24
if max_len == 0 {
20
25
return None ;
21
26
}
22
27
28
+ // Base cases:
29
+
23
30
// - if the item is already in scope, return the name under which it is
24
31
let def_map = db. crate_def_map ( from. krate ) ;
25
32
let from_scope: & crate :: item_scope:: ItemScope = & def_map. modules [ from. local_id ] . scope ;
@@ -86,8 +93,12 @@ fn find_path_inner(db: &impl DefDatabase, item: ItemInNs, from: ModuleId, max_le
86
93
let mut best_path = None ;
87
94
let mut best_path_len = max_len;
88
95
for ( module_id, name) in importable_locations {
89
- let mut path = match find_path_inner ( db, ItemInNs :: Types ( ModuleDefId :: ModuleId ( module_id) ) , from, best_path_len - 1 )
90
- {
96
+ let mut path = match find_path_inner (
97
+ db,
98
+ ItemInNs :: Types ( ModuleDefId :: ModuleId ( module_id) ) ,
99
+ from,
100
+ best_path_len - 1 ,
101
+ ) {
91
102
None => continue ,
92
103
Some ( path) => path,
93
104
} ;
@@ -101,13 +112,14 @@ fn find_path_inner(db: &impl DefDatabase, item: ItemInNs, from: ModuleId, max_le
101
112
}
102
113
103
114
fn path_len ( path : & ModPath ) -> usize {
104
- path. segments . len ( ) + match path. kind {
105
- PathKind :: Plain => 0 ,
106
- PathKind :: Super ( i) => i as usize ,
107
- PathKind :: Crate => 1 ,
108
- PathKind :: Abs => 0 ,
109
- PathKind :: DollarCrate ( _) => 1 ,
110
- }
115
+ path. segments . len ( )
116
+ + match path. kind {
117
+ PathKind :: Plain => 0 ,
118
+ PathKind :: Super ( i) => i as usize ,
119
+ PathKind :: Crate => 1 ,
120
+ PathKind :: Abs => 0 ,
121
+ PathKind :: DollarCrate ( _) => 1 ,
122
+ }
111
123
}
112
124
113
125
fn find_importable_locations (
0 commit comments