@@ -578,22 +578,26 @@ fn racer_match_to_def(ctx: &InitActionContext, m: &racer::Match) -> Option<Def>
578
578
let home = home:: home_dir ( ) . unwrap_or_default ( ) ;
579
579
let cargo_home =
580
580
env:: var ( "CARGO_HOME" ) . map ( PathBuf :: from) . unwrap_or_else ( |_| home. join ( ".cargo" ) ) ;
581
- let cargo_registry_src = cargo_home. join ( "registry" ) . join ( "src" ) . join ( "github.com-1ecc6299db9ec823" ) ;
581
+ let cargo_registry_src =
582
+ cargo_home. join ( "registry" ) . join ( "src" ) . join ( "github.com-1ecc6299db9ec823" ) ;
582
583
let rust_src_path = racer:: get_rust_src_path ( ) . ok ( ) ;
583
584
584
585
let contextstr = m. contextstr . replacen ( "\\ \\ ?\\ " , "" , 1 ) ;
585
586
let contextstr_path = PathBuf :: from ( & contextstr) ;
586
587
let contextstr_path = collapse_parents ( contextstr_path) ;
587
588
588
-
589
- // Tidy up the module path.
590
- // Try to display the path relative to libstd src root if possible.
589
+ // Attempt to tidy up the module path
591
590
rust_src_path
592
- . and_then ( |path| contextstr_path. strip_prefix ( path) . ok ( ) . map ( ToOwned :: to_owned) )
593
- // Make the path relative to the package root cached in Cargo registry
594
- . or_else ( || contextstr_path. strip_prefix ( cargo_registry_src) . ok ( ) . map ( ToOwned :: to_owned) )
595
- // Make the path relative to the root of the project, if possible.
591
+ . and_then ( |rust_src_path| {
592
+ // Make the path relative to Rust src root
593
+ contextstr_path. strip_prefix ( rust_src_path) . ok ( ) . map ( ToOwned :: to_owned)
594
+ } )
595
+ . or_else ( || {
596
+ // Make the path relative to the package root cached in Cargo registry
597
+ contextstr_path. strip_prefix ( cargo_registry_src) . ok ( ) . map ( ToOwned :: to_owned)
598
+ } )
596
599
. or_else ( || {
600
+ // Make the path relative to the root of the project
597
601
contextstr_path. strip_prefix ( & ctx. current_project ) . ok ( ) . map ( ToOwned :: to_owned)
598
602
} )
599
603
. and_then ( |path| path. to_str ( ) . map ( ToOwned :: to_owned) )
0 commit comments