Skip to content

Commit 0d1ed56

Browse files
committed
Auto merge of rust-lang#14430 - Veykril:canonicalize-project-manifest, r=Veykril
fix: Canonicalize rust-project.json manifest path Looked a bit more into this and I think we can do this after all, I don't see any place where this should break things cc rust-lang/rust-analyzer#14168 rust-lang/rust-analyzer#14402 (comment)
2 parents e7337fc + f1de133 commit 0d1ed56

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

crates/paths/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ impl AbsPath {
166166
AbsPathBuf::try_from(self.0.to_path_buf()).unwrap()
167167
}
168168

169+
/// Equivalent of [`Path::canonicalize`] for `AbsPath`.
170+
pub fn canonicalize(&self) -> Result<AbsPathBuf, std::io::Error> {
171+
Ok(self.as_ref().canonicalize()?.try_into().unwrap())
172+
}
173+
169174
/// Equivalent of [`Path::strip_prefix`] for `AbsPath`.
170175
///
171176
/// Returns a relative path.

crates/project-model/src/manifest_path.rs

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ impl ManifestPath {
3434
pub fn parent(&self) -> &AbsPath {
3535
self.file.parent().unwrap()
3636
}
37+
38+
/// Equivalent of [`Path::canonicalize`] for `ManifestPath`.
39+
pub fn canonicalize(&self) -> Result<ManifestPath, std::io::Error> {
40+
Ok((&**self).canonicalize()?.try_into().unwrap())
41+
}
3742
}
3843

3944
impl ops::Deref for ManifestPath {

crates/project-model/src/workspace.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
use std::{collections::VecDeque, fmt, fs, process::Command, sync::Arc};
66

7-
use anyhow::{bail, format_err, Context, Result};
7+
use anyhow::{format_err, Context, Result};
88
use base_db::{
99
CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, Edition, Env,
1010
FileId, LangCrateOrigin, ProcMacroPaths, TargetLayoutLoadResult,
@@ -154,12 +154,7 @@ impl ProjectWorkspace {
154154
) -> Result<ProjectWorkspace> {
155155
let res = match manifest {
156156
ProjectManifest::ProjectJson(project_json) => {
157-
let metadata = fs::symlink_metadata(&project_json).with_context(|| {
158-
format!("Failed to read json file {}", project_json.display())
159-
})?;
160-
if metadata.is_symlink() {
161-
bail!("The project-json may not currently point to a symlink");
162-
}
157+
let project_json = project_json.canonicalize()?;
163158
let file = fs::read_to_string(&project_json).with_context(|| {
164159
format!("Failed to read json file {}", project_json.display())
165160
})?;

0 commit comments

Comments
 (0)