@@ -60,7 +60,7 @@ mod tests;
60
60
use std:: { cmp:: Ord , ops:: Deref } ;
61
61
62
62
use base_db:: { CrateId , Edition , FileId , ProcMacroKind } ;
63
- use hir_expand:: { name:: Name , HirFileId , InFile , MacroCallId , MacroDefId } ;
63
+ use hir_expand:: { ast_id_map :: FileAstId , name:: Name , HirFileId , InFile , MacroCallId , MacroDefId } ;
64
64
use itertools:: Itertools ;
65
65
use la_arena:: Arena ;
66
66
use profile:: Count ;
@@ -217,25 +217,30 @@ pub enum ModuleOrigin {
217
217
/// Note that non-inline modules, by definition, live inside non-macro file.
218
218
File {
219
219
is_mod_rs : bool ,
220
- declaration : AstId < ast:: Module > ,
220
+ declaration : FileAstId < ast:: Module > ,
221
221
declaration_tree_id : ItemTreeId < Mod > ,
222
222
definition : FileId ,
223
223
} ,
224
224
Inline {
225
225
definition_tree_id : ItemTreeId < Mod > ,
226
- definition : AstId < ast:: Module > ,
226
+ definition : FileAstId < ast:: Module > ,
227
227
} ,
228
228
/// Pseudo-module introduced by a block scope (contains only inner items).
229
229
BlockExpr {
230
+ id : BlockId ,
230
231
block : AstId < ast:: BlockExpr > ,
231
232
} ,
232
233
}
233
234
234
235
impl ModuleOrigin {
235
236
pub fn declaration ( & self ) -> Option < AstId < ast:: Module > > {
236
237
match self {
237
- ModuleOrigin :: File { declaration : module, .. }
238
- | ModuleOrigin :: Inline { definition : module, .. } => Some ( * module) ,
238
+ & ModuleOrigin :: File { declaration, declaration_tree_id, .. } => {
239
+ Some ( AstId :: new ( declaration_tree_id. file_id ( ) , declaration) )
240
+ }
241
+ & ModuleOrigin :: Inline { definition, definition_tree_id } => {
242
+ Some ( AstId :: new ( definition_tree_id. file_id ( ) , definition) )
243
+ }
239
244
ModuleOrigin :: CrateRoot { .. } | ModuleOrigin :: BlockExpr { .. } => None ,
240
245
}
241
246
}
@@ -260,16 +265,17 @@ impl ModuleOrigin {
260
265
/// That is, a file or a `mod foo {}` with items.
261
266
fn definition_source ( & self , db : & dyn DefDatabase ) -> InFile < ModuleSource > {
262
267
match self {
263
- ModuleOrigin :: File { definition, .. } | ModuleOrigin :: CrateRoot { definition } => {
264
- let file_id = * definition;
265
- let sf = db. parse ( file_id) . tree ( ) ;
266
- InFile :: new ( file_id. into ( ) , ModuleSource :: SourceFile ( sf) )
268
+ & ModuleOrigin :: File { definition, .. } | & ModuleOrigin :: CrateRoot { definition } => {
269
+ let sf = db. parse ( definition) . tree ( ) ;
270
+ InFile :: new ( definition. into ( ) , ModuleSource :: SourceFile ( sf) )
267
271
}
268
- ModuleOrigin :: Inline { definition, .. } => InFile :: new (
269
- definition. file_id ,
270
- ModuleSource :: Module ( definition. to_node ( db. upcast ( ) ) ) ,
272
+ & ModuleOrigin :: Inline { definition, definition_tree_id } => InFile :: new (
273
+ definition_tree_id. file_id ( ) ,
274
+ ModuleSource :: Module (
275
+ AstId :: new ( definition_tree_id. file_id ( ) , definition) . to_node ( db. upcast ( ) ) ,
276
+ ) ,
271
277
) ,
272
- ModuleOrigin :: BlockExpr { block } => {
278
+ ModuleOrigin :: BlockExpr { block, .. } => {
273
279
InFile :: new ( block. file_id , ModuleSource :: BlockExpr ( block. to_node ( db. upcast ( ) ) ) )
274
280
}
275
281
}
@@ -314,9 +320,7 @@ impl DefMap {
314
320
}
315
321
316
322
pub ( crate ) fn block_def_map_query ( db : & dyn DefDatabase , block_id : BlockId ) -> Arc < DefMap > {
317
- let block: BlockLoc = db. lookup_intern_block ( block_id) ;
318
-
319
- let tree_id = TreeId :: new ( block. ast_id . file_id , Some ( block_id) ) ;
323
+ let block: BlockLoc = block_id. lookup ( db) ;
320
324
321
325
let parent_map = block. module . def_map ( db) ;
322
326
let krate = block. module . krate ;
@@ -325,8 +329,10 @@ impl DefMap {
325
329
// modules declared by blocks with items. At the moment, we don't use
326
330
// this visibility for anything outside IDE, so that's probably OK.
327
331
let visibility = Visibility :: Module ( ModuleId { krate, local_id, block : None } ) ;
328
- let module_data =
329
- ModuleData :: new ( ModuleOrigin :: BlockExpr { block : block. ast_id } , visibility) ;
332
+ let module_data = ModuleData :: new (
333
+ ModuleOrigin :: BlockExpr { block : block. ast_id , id : block_id } ,
334
+ visibility,
335
+ ) ;
330
336
331
337
let mut def_map = DefMap :: empty ( krate, parent_map. data . edition , module_data) ;
332
338
def_map. data = parent_map. data . clone ( ) ;
@@ -338,7 +344,8 @@ impl DefMap {
338
344
} ,
339
345
} ) ;
340
346
341
- let def_map = collector:: collect_defs ( db, def_map, tree_id) ;
347
+ let def_map =
348
+ collector:: collect_defs ( db, def_map, TreeId :: new ( block. ast_id . file_id , Some ( block_id) ) ) ;
342
349
Arc :: new ( def_map)
343
350
}
344
351
@@ -642,8 +649,8 @@ impl ModuleData {
642
649
ModuleOrigin :: File { definition, .. } | ModuleOrigin :: CrateRoot { definition } => {
643
650
definition. into ( )
644
651
}
645
- ModuleOrigin :: Inline { definition , .. } => definition . file_id ,
646
- ModuleOrigin :: BlockExpr { block } => block. file_id ,
652
+ ModuleOrigin :: Inline { definition_tree_id , .. } => definition_tree_id . file_id ( ) ,
653
+ ModuleOrigin :: BlockExpr { block, .. } => block. file_id ,
647
654
}
648
655
}
649
656
0 commit comments