aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-04-11 12:41:40 +0100
committerGitHub <[email protected]>2020-04-11 12:41:40 +0100
commit54bdb9c78b012c560efc142971dc3e724989e807 (patch)
treed24668768ab0a9232c19878703a6c5bd94eb40d4
parentbeb755caa2b1d7265da7d3367af3b49039dfe00e (diff)
parent73e512215afada62316a7b057bd78d8c9727adca (diff)
Merge #3939
3939: Fix non canonicallized path from metadata r=matklad a=edwin0cheng Crate root path obtained from cargo-metadata may contains non-canonicalized path (e.g. `/foo/../libcore/tests/lib.rs`), such that `vfs::load` will find a incorrect root. This PR try to fix that by canonicalize it before passing to vfs. Co-authored-by: Edwin Cheng <[email protected]>
-rw-r--r--crates/rust-analyzer/src/cli/load_cargo.rs4
-rw-r--r--crates/rust-analyzer/src/world.rs4
2 files changed, 6 insertions, 2 deletions
diff --git a/crates/rust-analyzer/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs
index 69133e4e4..43062ea10 100644
--- a/crates/rust-analyzer/src/cli/load_cargo.rs
+++ b/crates/rust-analyzer/src/cli/load_cargo.rs
@@ -152,7 +152,9 @@ pub(crate) fn load(
152 &extern_source_roots, 152 &extern_source_roots,
153 proc_macro_client, 153 proc_macro_client,
154 &mut |path: &Path| { 154 &mut |path: &Path| {
155 let vfs_file = vfs.load(path); 155 // Some path from metadata will be non canonicalized, e.g. /foo/../bar/lib.rs
156 let path = path.canonicalize().ok()?;
157 let vfs_file = vfs.load(&path);
156 log::debug!("vfs file {:?} -> {:?}", path, vfs_file); 158 log::debug!("vfs file {:?} -> {:?}", path, vfs_file);
157 vfs_file.map(vfs_file_to_id) 159 vfs_file.map(vfs_file_to_id)
158 }, 160 },
diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs
index 365f57d8c..6c42e1d76 100644
--- a/crates/rust-analyzer/src/world.rs
+++ b/crates/rust-analyzer/src/world.rs
@@ -139,7 +139,9 @@ impl WorldState {
139 // Create crate graph from all the workspaces 139 // Create crate graph from all the workspaces
140 let mut crate_graph = CrateGraph::default(); 140 let mut crate_graph = CrateGraph::default();
141 let mut load = |path: &std::path::Path| { 141 let mut load = |path: &std::path::Path| {
142 let vfs_file = vfs.load(path); 142 // Some path from metadata will be non canonicalized, e.g. /foo/../bar/lib.rs
143 let path = path.canonicalize().ok()?;
144 let vfs_file = vfs.load(&path);
143 vfs_file.map(|f| FileId(f.0)) 145 vfs_file.map(|f| FileId(f.0))
144 }; 146 };
145 147