@@ -367,39 +367,39 @@ fn parse_toml(
367
367
368
368
#[ cfg( test) ]
369
369
mod tests {
370
- use std:: path:: { Path , PathBuf } ;
370
+ use std:: path:: PathBuf ;
371
371
372
372
use vfs:: { AbsPath , AbsPathBuf , VfsPath } ;
373
373
374
374
fn alloc_file_id ( vfs : & mut Vfs , s : & str ) -> FileId {
375
- let abs_path = AbsPathBuf :: try_from ( PathBuf :: new ( ) . join ( s) ) . unwrap ( ) ;
376
-
375
+ let abs_path = AbsPath :: assert ( s) . to_path_buf ( ) ;
377
376
let vfs_path = VfsPath :: from ( abs_path) ;
378
377
let file_id = vfs. alloc_file_id ( vfs_path) ;
379
378
vfs. set_file_id_contents ( file_id, None ) ;
380
379
file_id
381
380
}
382
381
383
382
fn alloc_config ( vfs : & mut Vfs , s : & str , config : & str ) -> FileId {
384
- let abs_path = AbsPathBuf :: try_from ( PathBuf :: new ( ) . join ( s) ) . unwrap ( ) ;
385
-
383
+ let abs_path = AbsPath :: assert ( s) . to_path_buf ( ) ;
386
384
let vfs_path = VfsPath :: from ( abs_path) ;
387
385
let file_id = vfs. alloc_file_id ( vfs_path) ;
388
386
vfs. set_file_id_contents ( file_id, Some ( config. to_string ( ) . into_bytes ( ) ) ) ;
389
387
file_id
390
388
}
391
389
390
+ const XDG_CONFIG_HOME_RATOML : & ' static str =
391
+ "/home/username/.config/rust-analyzer/rust-analyzer.toml" ;
392
+
392
393
use super :: * ;
393
394
#[ test]
394
395
fn basic ( ) {
395
396
tracing_subscriber:: fmt ( ) . try_init ( ) . ok ( ) ;
396
397
let mut vfs = Vfs :: default ( ) ;
397
- let project_root = AbsPath :: assert ( Path :: new ( "/root" ) ) ;
398
- let xdg_config_file_id =
399
- alloc_file_id ( & mut vfs, "/home/username/.config/rust-analyzer/rust-analyzer.toml" ) ;
398
+ let project_root = AbsPath :: assert ( "/root" ) ;
399
+ let xdg_config_file_id = alloc_file_id ( & mut vfs, XDG_CONFIG_HOME_RATOML ) ;
400
400
let mut config_tree = ConfigDb :: new ( xdg_config_file_id, project_root. to_path_buf ( ) ) ;
401
401
402
- let source_roots = [ "/root/crate_a" ] . map ( Path :: new ) . map ( AbsPath :: assert) ;
402
+ let source_roots = [ "/root/crate_a" ] . map ( AbsPath :: assert) ;
403
403
404
404
let _root = alloc_config (
405
405
& mut vfs,
@@ -501,13 +501,11 @@ mod tests {
501
501
tracing_subscriber:: fmt ( ) . try_init ( ) . ok ( ) ;
502
502
let mut vfs = Vfs :: default ( ) ;
503
503
504
- let project_root = AbsPath :: assert ( Path :: new ( "/root" ) ) ;
505
- let xdg =
506
- alloc_file_id ( & mut vfs, "/home/username/.config/rust-analyzer/rust-analyzer.toml" ) ;
504
+ let project_root = AbsPath :: assert ( "/root" ) ;
505
+ let xdg = alloc_file_id ( & mut vfs, XDG_CONFIG_HOME_RATOML ) ;
507
506
let mut config_tree = ConfigDb :: new ( xdg, project_root. to_path_buf ( ) ) ;
508
507
509
- let source_roots =
510
- [ "/root/crate_a" , "/root/crate_a/crate_b" ] . map ( Path :: new) . map ( AbsPath :: assert) ;
508
+ let source_roots = [ "/root/crate_a" , "/root/crate_a/crate_b" ] . map ( AbsPath :: assert) ;
511
509
let [ crate_a, crate_b] = source_roots
512
510
. map ( |dir| dir. join ( "rust-analyzer.toml" ) )
513
511
. map ( |path| vfs. alloc_file_id ( path. into ( ) ) ) ;
@@ -539,7 +537,7 @@ mod tests {
539
537
// ----
540
538
541
539
// Now move crate b to the root. This gives a new FileId for crate_b/ra.toml.
542
- let source_roots = [ "/root/crate_a" , "/root/crate_b" ] . map ( Path :: new ) . map ( AbsPath :: assert) ;
540
+ let source_roots = [ "/root/crate_a" , "/root/crate_b" ] . map ( AbsPath :: assert) ;
543
541
let [ _crate_a, crate_b] = source_roots
544
542
. map ( |dir| dir. join ( "rust-analyzer.toml" ) )
545
543
. map ( |path| vfs. alloc_file_id ( path. into ( ) ) ) ;
@@ -568,12 +566,11 @@ mod tests {
568
566
tracing_subscriber:: fmt ( ) . try_init ( ) . ok ( ) ;
569
567
let mut vfs = Vfs :: default ( ) ;
570
568
571
- let project_root = AbsPath :: assert ( Path :: new ( "/root" ) ) ;
572
- let xdg =
573
- alloc_file_id ( & mut vfs, "/home/username/.config/rust-analyzer/rust-analyzer.toml" ) ;
569
+ let project_root = AbsPath :: assert ( "/root" ) ;
570
+ let xdg = alloc_file_id ( & mut vfs, XDG_CONFIG_HOME_RATOML ) ;
574
571
let mut config_tree = ConfigDb :: new ( xdg, project_root. to_path_buf ( ) ) ;
575
572
576
- let source_roots = [ "/root/crate_a" ] . map ( Path :: new ) . map ( AbsPath :: assert) ;
573
+ let source_roots = [ "/root/crate_a" ] . map ( AbsPath :: assert) ;
577
574
let crate_a = vfs. alloc_file_id ( source_roots[ 0 ] . join ( "rust-analyzer.toml" ) . into ( ) ) ;
578
575
579
576
let _root = alloc_config (
@@ -601,7 +598,7 @@ mod tests {
601
598
// change project root
602
599
let changes = ConfigChanges {
603
600
client_change : None ,
604
- set_project_root : Some ( AbsPath :: assert ( Path :: new ( "/ro" ) ) . to_path_buf ( ) ) ,
601
+ set_project_root : Some ( AbsPath :: assert ( "/ro" ) . to_path_buf ( ) ) ,
605
602
set_source_roots : None ,
606
603
ra_toml_changes : dbg ! ( vfs. take_changes( ) ) ,
607
604
} ;
@@ -617,12 +614,11 @@ mod tests {
617
614
tracing_subscriber:: fmt ( ) . try_init ( ) . ok ( ) ;
618
615
let mut vfs = Vfs :: default ( ) ;
619
616
620
- let project_root = AbsPath :: assert ( Path :: new ( "/root" ) ) ;
621
- let xdg =
622
- alloc_file_id ( & mut vfs, "/home/username/.config/rust-analyzer/rust-analyzer.toml" ) ;
617
+ let project_root = AbsPath :: assert ( "/root" ) ;
618
+ let xdg = alloc_file_id ( & mut vfs, XDG_CONFIG_HOME_RATOML ) ;
623
619
let mut config_tree = ConfigDb :: new ( xdg, project_root. to_path_buf ( ) ) ;
624
620
625
- let source_roots = [ "/root/crate_a" ] . map ( Path :: new ) . map ( AbsPath :: assert) ;
621
+ let source_roots = [ "/root/crate_a" ] . map ( AbsPath :: assert) ;
626
622
let crate_a = vfs. alloc_file_id ( source_roots[ 0 ] . join ( "rust-analyzer.toml" ) . into ( ) ) ;
627
623
628
624
let _root = alloc_config (
0 commit comments