@@ -249,85 +249,74 @@ impl<'a> SymbolCollector<'a> {
249
249
<L as Lookup >:: Data : HasSource ,
250
250
<<L as Lookup >:: Data as HasSource >:: Value : HasName ,
251
251
{
252
- self . push_file_symbol ( |s| {
253
- let mut symbols = Vec :: new ( ) ;
254
- let loc = id. lookup ( s. db . upcast ( ) ) ;
255
- let source = loc. source ( s. db . upcast ( ) ) ;
256
- let name_node = source. value . name ( ) ?;
257
- let def = ModuleDef :: from ( id. into ( ) ) ;
258
- let dec_loc = DeclarationLocation {
259
- hir_file_id : source. file_id ,
260
- ptr : SyntaxNodePtr :: new ( source. value . syntax ( ) ) ,
261
- name_ptr : SyntaxNodePtr :: new ( name_node. syntax ( ) ) ,
262
- } ;
263
-
264
- if let Some ( attrs) = def. attrs ( s. db ) {
265
- for alias in attrs. doc_aliases ( ) {
266
- eprintln ! ( "Adding alias {}" , alias) ;
267
- symbols. push ( FileSymbol {
268
- name : alias,
269
- def : def. clone ( ) ,
270
- loc : dec_loc. clone ( ) ,
271
- container_name : s. current_container_name . clone ( ) ,
272
- } ) ;
273
- }
252
+ let loc = id. lookup ( self . db . upcast ( ) ) ;
253
+ let source = loc. source ( self . db . upcast ( ) ) ;
254
+ let name_node = match source. value . name ( ) {
255
+ Some ( n) => n,
256
+ None => return ,
257
+ } ;
258
+ let def = ModuleDef :: from ( id. into ( ) ) ;
259
+ let dec_loc = DeclarationLocation {
260
+ hir_file_id : source. file_id ,
261
+ ptr : SyntaxNodePtr :: new ( source. value . syntax ( ) ) ,
262
+ name_ptr : SyntaxNodePtr :: new ( name_node. syntax ( ) ) ,
263
+ } ;
264
+
265
+ if let Some ( attrs) = def. attrs ( self . db ) {
266
+ for alias in attrs. doc_aliases ( ) {
267
+ self . symbols . push ( FileSymbol {
268
+ name : alias,
269
+ def,
270
+ loc : dec_loc. clone ( ) ,
271
+ container_name : self . current_container_name . clone ( ) ,
272
+ } ) ;
274
273
}
274
+ }
275
275
276
- symbols. push ( FileSymbol {
277
- name : name_node. text ( ) . into ( ) ,
278
- def,
279
- container_name : s. current_container_name . clone ( ) ,
280
- loc : dec_loc,
281
- } ) ;
282
-
283
- Some ( symbols)
284
- } )
276
+ self . symbols . push ( FileSymbol {
277
+ name : name_node. text ( ) . into ( ) ,
278
+ def,
279
+ container_name : self . current_container_name . clone ( ) ,
280
+ loc : dec_loc,
281
+ } ) ;
285
282
}
286
283
287
284
fn push_module ( & mut self , module_id : ModuleId ) {
288
- self . push_file_symbol ( |s| {
289
- let mut symbols = Vec :: new ( ) ;
290
- let def_map = module_id. def_map ( s. db . upcast ( ) ) ;
291
- let module_data = & def_map[ module_id. local_id ] ;
292
- let declaration = module_data. origin . declaration ( ) ?;
293
- let module = declaration. to_node ( s. db . upcast ( ) ) ;
294
- let name_node = module. name ( ) ?;
295
- let dec_loc = DeclarationLocation {
296
- hir_file_id : declaration. file_id ,
297
- ptr : SyntaxNodePtr :: new ( module. syntax ( ) ) ,
298
- name_ptr : SyntaxNodePtr :: new ( name_node. syntax ( ) ) ,
299
- } ;
300
-
301
- let def = ModuleDef :: Module ( module_id. into ( ) ) ;
302
-
303
- if let Some ( attrs) = def. attrs ( s. db ) {
304
- for alias in attrs. doc_aliases ( ) {
305
- eprintln ! ( "Adding alias for module. {}" , alias) ;
306
- symbols. push ( FileSymbol {
307
- name : alias,
308
- def : def. clone ( ) ,
309
- loc : dec_loc. clone ( ) ,
310
- container_name : s. current_container_name . clone ( ) ,
311
- } ) ;
312
- }
313
- }
314
-
315
- symbols. push ( FileSymbol {
316
- name : name_node. text ( ) . into ( ) ,
317
- def : ModuleDef :: Module ( module_id. into ( ) ) ,
318
- container_name : s. current_container_name . clone ( ) ,
319
- loc : dec_loc,
320
- } ) ;
321
-
322
- Some ( symbols)
323
- } )
324
- }
325
-
326
- fn push_file_symbol ( & mut self , f : impl FnOnce ( & Self ) -> Option < Vec < FileSymbol > > ) {
327
- if let Some ( file_symbols) = f ( self ) {
328
- for file_symbol in file_symbols {
329
- self . symbols . push ( file_symbol) ;
285
+ let def_map = module_id. def_map ( self . db . upcast ( ) ) ;
286
+ let module_data = & def_map[ module_id. local_id ] ;
287
+ let declaration = match module_data. origin . declaration ( ) {
288
+ Some ( d) => d,
289
+ None => return ,
290
+ } ;
291
+ let module = declaration. to_node ( self . db . upcast ( ) ) ;
292
+ let name_node = match module. name ( ) {
293
+ Some ( n) => n,
294
+ None => return ,
295
+ } ;
296
+ let dec_loc = DeclarationLocation {
297
+ hir_file_id : declaration. file_id ,
298
+ ptr : SyntaxNodePtr :: new ( module. syntax ( ) ) ,
299
+ name_ptr : SyntaxNodePtr :: new ( name_node. syntax ( ) ) ,
300
+ } ;
301
+
302
+ let def = ModuleDef :: Module ( module_id. into ( ) ) ;
303
+
304
+ if let Some ( attrs) = def. attrs ( self . db ) {
305
+ for alias in attrs. doc_aliases ( ) {
306
+ self . symbols . push ( FileSymbol {
307
+ name : alias,
308
+ def,
309
+ loc : dec_loc. clone ( ) ,
310
+ container_name : self . current_container_name . clone ( ) ,
311
+ } ) ;
330
312
}
331
313
}
314
+
315
+ self . symbols . push ( FileSymbol {
316
+ name : name_node. text ( ) . into ( ) ,
317
+ def : ModuleDef :: Module ( module_id. into ( ) ) ,
318
+ container_name : self . current_container_name . clone ( ) ,
319
+ loc : dec_loc,
320
+ } ) ;
332
321
}
333
322
}
0 commit comments