Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 1c5c4f5

Browse files
committed
Format
1 parent 33904cd commit 1c5c4f5

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

rls/src/actions/hover.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -578,22 +578,26 @@ fn racer_match_to_def(ctx: &InitActionContext, m: &racer::Match) -> Option<Def>
578578
let home = home::home_dir().unwrap_or_default();
579579
let cargo_home =
580580
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");
582583
let rust_src_path = racer::get_rust_src_path().ok();
583584

584585
let contextstr = m.contextstr.replacen("\\\\?\\", "", 1);
585586
let contextstr_path = PathBuf::from(&contextstr);
586587
let contextstr_path = collapse_parents(contextstr_path);
587588

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
591590
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+
})
596599
.or_else(|| {
600+
// Make the path relative to the root of the project
597601
contextstr_path.strip_prefix(&ctx.current_project).ok().map(ToOwned::to_owned)
598602
})
599603
.and_then(|path| path.to_str().map(ToOwned::to_owned))

0 commit comments

Comments
 (0)