1
1
use std:: sync:: Arc ;
2
2
3
- use ra_db:: { CrateGraph , SourceDatabase } ;
3
+ use ra_db:: SourceDatabase ;
4
4
use test_utils:: { assert_eq_text, covers} ;
5
5
6
6
use crate :: {
@@ -19,20 +19,6 @@ fn item_map(fixture: &str) -> (Arc<ItemMap>, ModuleId) {
19
19
( db. item_map ( krate) , module_id)
20
20
}
21
21
22
- /// Sets the crate root to the file of the cursor marker
23
- fn item_map_custom_crate_root ( fixture : & str ) -> ( Arc < ItemMap > , ModuleId ) {
24
- let ( mut db, pos) = MockDatabase :: with_position ( fixture) ;
25
-
26
- let mut crate_graph = CrateGraph :: default ( ) ;
27
- crate_graph. add_crate_root ( pos. file_id ) ;
28
- db. set_crate_graph ( Arc :: new ( crate_graph) ) ;
29
-
30
- let module = crate :: source_binder:: module_from_position ( & db, pos) . unwrap ( ) ;
31
- let krate = module. krate ( & db) . unwrap ( ) ;
32
- let module_id = module. module_id ;
33
- ( db. item_map ( krate) , module_id)
34
- }
35
-
36
22
fn check_module_item_map ( map : & ItemMap , module_id : ModuleId , expected : & str ) {
37
23
let mut lines = map[ module_id]
38
24
. items
@@ -258,17 +244,13 @@ fn glob_across_crates() {
258
244
259
245
//- /lib.rs
260
246
pub struct Baz;
261
- " ,
247
+ " ,
262
248
) ;
249
+ db. set_crate_graph_from_fixture ( crate_graph ! {
250
+ "main" : ( "/main.rs" , [ "test_crate" ] ) ,
251
+ "test_crate" : ( "/lib.rs" , [ ] ) ,
252
+ } ) ;
263
253
let main_id = db. file_id_of ( "/main.rs" ) ;
264
- let lib_id = db. file_id_of ( "/lib.rs" ) ;
265
-
266
- let mut crate_graph = CrateGraph :: default ( ) ;
267
- let main_crate = crate_graph. add_crate_root ( main_id) ;
268
- let lib_crate = crate_graph. add_crate_root ( lib_id) ;
269
- crate_graph. add_dep ( main_crate, "test_crate" . into ( ) , lib_crate) . unwrap ( ) ;
270
-
271
- db. set_crate_graph ( Arc :: new ( crate_graph) ) ;
272
254
273
255
let module = crate :: source_binder:: module_from_file_id ( & db, main_id) . unwrap ( ) ;
274
256
let krate = module. krate ( & db) . unwrap ( ) ;
@@ -285,22 +267,31 @@ fn glob_across_crates() {
285
267
286
268
#[ test]
287
269
fn module_resolution_works_for_non_standard_filenames ( ) {
288
- let ( item_map , module_id ) = item_map_custom_crate_root (
270
+ let mut db = MockDatabase :: with_files (
289
271
"
290
272
//- /my_library.rs
291
273
mod foo;
292
274
use self::foo::Bar;
293
- <|>
275
+
294
276
//- /foo/mod.rs
295
277
pub struct Bar;
296
- " ,
278
+ " ,
297
279
) ;
280
+ db. set_crate_graph_from_fixture ( crate_graph ! {
281
+ "my_library" : ( "/my_library.rs" , [ ] ) ,
282
+ } ) ;
283
+ let file_id = db. file_id_of ( "/my_library.rs" ) ;
284
+
285
+ let module = crate :: source_binder:: module_from_file_id ( & db, file_id) . unwrap ( ) ;
286
+ let krate = module. krate ( & db) . unwrap ( ) ;
287
+ let module_id = module. module_id ;
288
+ let item_map = db. item_map ( krate) ;
298
289
check_module_item_map (
299
290
& item_map,
300
291
module_id,
301
292
"
302
- Bar: t v
303
- foo: t
293
+ Bar: t v
294
+ foo: t
304
295
" ,
305
296
) ;
306
297
}
@@ -417,17 +408,13 @@ fn item_map_across_crates() {
417
408
418
409
//- /lib.rs
419
410
pub struct Baz;
420
- " ,
411
+ " ,
421
412
) ;
413
+ db. set_crate_graph_from_fixture ( crate_graph ! {
414
+ "main" : ( "/main.rs" , [ "test_crate" ] ) ,
415
+ "test_crate" : ( "/lib.rs" , [ ] ) ,
416
+ } ) ;
422
417
let main_id = db. file_id_of ( "/main.rs" ) ;
423
- let lib_id = db. file_id_of ( "/lib.rs" ) ;
424
-
425
- let mut crate_graph = CrateGraph :: default ( ) ;
426
- let main_crate = crate_graph. add_crate_root ( main_id) ;
427
- let lib_crate = crate_graph. add_crate_root ( lib_id) ;
428
- crate_graph. add_dep ( main_crate, "test_crate" . into ( ) , lib_crate) . unwrap ( ) ;
429
-
430
- db. set_crate_graph ( Arc :: new ( crate_graph) ) ;
431
418
432
419
let module = crate :: source_binder:: module_from_file_id ( & db, main_id) . unwrap ( ) ;
433
420
let krate = module. krate ( & db) . unwrap ( ) ;
@@ -437,7 +424,7 @@ fn item_map_across_crates() {
437
424
& item_map,
438
425
module. module_id ,
439
426
"
440
- Baz: t v
427
+ Baz: t v
441
428
" ,
442
429
) ;
443
430
}
@@ -457,18 +444,13 @@ fn extern_crate_rename() {
457
444
458
445
//- /lib.rs
459
446
struct Arc;
460
- " ,
447
+ " ,
461
448
) ;
462
- let main_id = db. file_id_of ( "/main.rs" ) ;
449
+ db. set_crate_graph_from_fixture ( crate_graph ! {
450
+ "main" : ( "/main.rs" , [ "alloc" ] ) ,
451
+ "alloc" : ( "/lib.rs" , [ ] ) ,
452
+ } ) ;
463
453
let sync_id = db. file_id_of ( "/sync.rs" ) ;
464
- let lib_id = db. file_id_of ( "/lib.rs" ) ;
465
-
466
- let mut crate_graph = CrateGraph :: default ( ) ;
467
- let main_crate = crate_graph. add_crate_root ( main_id) ;
468
- let lib_crate = crate_graph. add_crate_root ( lib_id) ;
469
- crate_graph. add_dep ( main_crate, "alloc" . into ( ) , lib_crate) . unwrap ( ) ;
470
-
471
- db. set_crate_graph ( Arc :: new ( crate_graph) ) ;
472
454
473
455
let module = crate :: source_binder:: module_from_file_id ( & db, sync_id) . unwrap ( ) ;
474
456
let krate = module. krate ( & db) . unwrap ( ) ;
@@ -478,7 +460,7 @@ fn extern_crate_rename() {
478
460
& item_map,
479
461
module. module_id ,
480
462
"
481
- Arc: t v
463
+ Arc: t v
482
464
" ,
483
465
) ;
484
466
}
@@ -494,21 +476,17 @@ fn import_across_source_roots() {
494
476
}
495
477
}
496
478
497
- //- root /test_crate /
479
+ //- root /main /
498
480
499
- //- /test_crate /main.rs
481
+ //- /main /main.rs
500
482
use test_crate::a::b::C;
501
483
" ,
502
484
) ;
503
- let lib_id = db. file_id_of ( "/lib.rs" ) ;
504
- let main_id = db. file_id_of ( "/test_crate/main.rs" ) ;
505
-
506
- let mut crate_graph = CrateGraph :: default ( ) ;
507
- let main_crate = crate_graph. add_crate_root ( main_id) ;
508
- let lib_crate = crate_graph. add_crate_root ( lib_id) ;
509
- crate_graph. add_dep ( main_crate, "test_crate" . into ( ) , lib_crate) . unwrap ( ) ;
510
-
511
- db. set_crate_graph ( Arc :: new ( crate_graph) ) ;
485
+ db. set_crate_graph_from_fixture ( crate_graph ! {
486
+ "main" : ( "/main/main.rs" , [ "test_crate" ] ) ,
487
+ "test_crate" : ( "/lib.rs" , [ ] ) ,
488
+ } ) ;
489
+ let main_id = db. file_id_of ( "/main/main.rs" ) ;
512
490
513
491
let module = crate :: source_binder:: module_from_file_id ( & db, main_id) . unwrap ( ) ;
514
492
let krate = module. krate ( & db) . unwrap ( ) ;
@@ -537,17 +515,13 @@ fn reexport_across_crates() {
537
515
538
516
//- /foo.rs
539
517
pub struct Baz;
540
- " ,
518
+ " ,
541
519
) ;
520
+ db. set_crate_graph_from_fixture ( crate_graph ! {
521
+ "main" : ( "/main.rs" , [ "test_crate" ] ) ,
522
+ "test_crate" : ( "/lib.rs" , [ ] ) ,
523
+ } ) ;
542
524
let main_id = db. file_id_of ( "/main.rs" ) ;
543
- let lib_id = db. file_id_of ( "/lib.rs" ) ;
544
-
545
- let mut crate_graph = CrateGraph :: default ( ) ;
546
- let main_crate = crate_graph. add_crate_root ( main_id) ;
547
- let lib_crate = crate_graph. add_crate_root ( lib_id) ;
548
- crate_graph. add_dep ( main_crate, "test_crate" . into ( ) , lib_crate) . unwrap ( ) ;
549
-
550
- db. set_crate_graph ( Arc :: new ( crate_graph) ) ;
551
525
552
526
let module = crate :: source_binder:: module_from_file_id ( & db, main_id) . unwrap ( ) ;
553
527
let krate = module. krate ( & db) . unwrap ( ) ;
@@ -557,7 +531,7 @@ fn reexport_across_crates() {
557
531
& item_map,
558
532
module. module_id ,
559
533
"
560
- Baz: t v
534
+ Baz: t v
561
535
" ,
562
536
) ;
563
537
}
0 commit comments