@@ -8,7 +8,7 @@ use rustc_hash::FxHashMap;
8
8
9
9
use ra_syntax:: {
10
10
SmolStr , SyntaxKind :: { self , * } ,
11
- ast:: { self , NameOwner , AstNode , ModuleItemOwner }
11
+ ast:: { self , AstNode , ModuleItemOwner }
12
12
} ;
13
13
14
14
use crate :: {
@@ -26,13 +26,13 @@ use crate::{
26
26
/// module, the set of visible items.
27
27
#[ derive( Default , Debug , PartialEq , Eq ) ]
28
28
pub ( crate ) struct ItemMap {
29
- per_module : FxHashMap < ModuleId , ModuleItems > ,
29
+ pub ( crate ) per_module : FxHashMap < ModuleId , ModuleScope > ,
30
30
}
31
31
32
- #[ derive( Debug , Default , PartialEq , Eq ) ]
33
- struct ModuleItems {
34
- items : FxHashMap < SmolStr , Resolution > ,
35
- import_resolutions : FxHashMap < LocalSyntaxPtr , DefId > ,
32
+ #[ derive( Debug , Default , PartialEq , Eq , Clone ) ]
33
+ pub ( crate ) struct ModuleScope {
34
+ pub ( crate ) items : FxHashMap < SmolStr , Resolution > ,
35
+ pub ( crate ) import_resolutions : FxHashMap < LocalSyntaxPtr , DefId > ,
36
36
}
37
37
38
38
/// A set of items and imports declared inside a module, without relation to
@@ -117,22 +117,25 @@ pub(crate) fn item_map(
117
117
/// Resolution is basically `DefId` atm, but it should account for stuff like
118
118
/// multiple namespaces, ambiguity and errors.
119
119
#[ derive( Debug , Clone , PartialEq , Eq ) ]
120
- struct Resolution {
120
+ pub ( crate ) struct Resolution {
121
121
/// None for unresolved
122
- def_id : Option < DefId > ,
122
+ pub ( crate ) def_id : Option < DefId > ,
123
+ /// ident by whitch this is imported into local scope.
124
+ /// TODO: make this offset-independent.
125
+ pub ( crate ) import_name : Option < LocalSyntaxPtr > ,
123
126
}
124
127
125
- #[ derive( Clone , Copy , Debug , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
126
- enum Namespace {
127
- Types ,
128
- Values ,
129
- }
128
+ // #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
129
+ // enum Namespace {
130
+ // Types,
131
+ // Values,
132
+ // }
130
133
131
- #[ derive( Debug ) ]
132
- struct PerNs < T > {
133
- types : Option < T > ,
134
- values : Option < T > ,
135
- }
134
+ // #[derive(Debug)]
135
+ // struct PerNs<T> {
136
+ // types: Option<T>,
137
+ // values: Option<T>,
138
+ // }
136
139
137
140
#[ derive( Debug , PartialEq , Eq ) ]
138
141
struct ModuleItem {
@@ -144,7 +147,7 @@ struct ModuleItem {
144
147
145
148
#[ derive( Debug , PartialEq , Eq ) ]
146
149
enum Vis {
147
- Priv ,
150
+ // Priv,
148
151
Other ,
149
152
}
150
153
@@ -302,13 +305,17 @@ where
302
305
fn populate_module ( & mut self , module_id : ModuleId , input : & InputModuleItems ) {
303
306
let file_id = module_id. source ( & self . module_tree ) . file_id ( ) ;
304
307
305
- let mut module_items = ModuleItems :: default ( ) ;
308
+ let mut module_items = ModuleScope :: default ( ) ;
306
309
307
310
for import in input. imports . iter ( ) {
308
- if let Some ( ( _, name) ) = import. segments . last ( ) {
309
- module_items
310
- . items
311
- . insert ( name. clone ( ) , Resolution { def_id : None } ) ;
311
+ if let Some ( ( ptr, name) ) = import. segments . last ( ) {
312
+ module_items. items . insert (
313
+ name. clone ( ) ,
314
+ Resolution {
315
+ def_id : None ,
316
+ import_name : Some ( * ptr) ,
317
+ } ,
318
+ ) ;
312
319
}
313
320
}
314
321
@@ -322,6 +329,7 @@ where
322
329
let def_id = self . db . id_maps ( ) . def_id ( def_loc) ;
323
330
let resolution = Resolution {
324
331
def_id : Some ( def_id) ,
332
+ import_name : None ,
325
333
} ;
326
334
module_items. items . insert ( item. name . clone ( ) , resolution) ;
327
335
}
@@ -334,6 +342,7 @@ where
334
342
let def_id = self . db . id_maps ( ) . def_id ( def_loc) ;
335
343
let resolution = Resolution {
336
344
def_id : Some ( def_id) ,
345
+ import_name : None ,
337
346
} ;
338
347
module_items. items . insert ( name, resolution) ;
339
348
}
@@ -386,14 +395,15 @@ where
386
395
self . update ( module_id, |items| {
387
396
let res = Resolution {
388
397
def_id : Some ( def_id) ,
398
+ import_name : Some ( * ptr) ,
389
399
} ;
390
400
items. items . insert ( name. clone ( ) , res) ;
391
401
} )
392
402
}
393
403
}
394
404
}
395
405
396
- fn update ( & mut self , module_id : ModuleId , f : impl FnOnce ( & mut ModuleItems ) ) {
406
+ fn update ( & mut self , module_id : ModuleId , f : impl FnOnce ( & mut ModuleScope ) ) {
397
407
let module_items = self . result . per_module . get_mut ( & module_id) . unwrap ( ) ;
398
408
f ( module_items)
399
409
}
0 commit comments