Auto merge of #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 https://github.com/rust-lang/rust-analyzer/pull/14168 https://github.com/rust-lang/rust-analyzer/pull/14402#issuecomment-1487257246
This commit is contained in:
commit
0d1ed56bb3
@ -166,6 +166,11 @@ pub fn to_path_buf(&self) -> AbsPathBuf {
|
|||||||
AbsPathBuf::try_from(self.0.to_path_buf()).unwrap()
|
AbsPathBuf::try_from(self.0.to_path_buf()).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Equivalent of [`Path::canonicalize`] for `AbsPath`.
|
||||||
|
pub fn canonicalize(&self) -> Result<AbsPathBuf, std::io::Error> {
|
||||||
|
Ok(self.as_ref().canonicalize()?.try_into().unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
/// Equivalent of [`Path::strip_prefix`] for `AbsPath`.
|
/// Equivalent of [`Path::strip_prefix`] for `AbsPath`.
|
||||||
///
|
///
|
||||||
/// Returns a relative path.
|
/// Returns a relative path.
|
||||||
|
@ -34,6 +34,11 @@ impl ManifestPath {
|
|||||||
pub fn parent(&self) -> &AbsPath {
|
pub fn parent(&self) -> &AbsPath {
|
||||||
self.file.parent().unwrap()
|
self.file.parent().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Equivalent of [`Path::canonicalize`] for `ManifestPath`.
|
||||||
|
pub fn canonicalize(&self) -> Result<ManifestPath, std::io::Error> {
|
||||||
|
Ok((&**self).canonicalize()?.try_into().unwrap())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ops::Deref for ManifestPath {
|
impl ops::Deref for ManifestPath {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
use std::{collections::VecDeque, fmt, fs, process::Command, sync::Arc};
|
use std::{collections::VecDeque, fmt, fs, process::Command, sync::Arc};
|
||||||
|
|
||||||
use anyhow::{bail, format_err, Context, Result};
|
use anyhow::{format_err, Context, Result};
|
||||||
use base_db::{
|
use base_db::{
|
||||||
CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, Edition, Env,
|
CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, Edition, Env,
|
||||||
FileId, LangCrateOrigin, ProcMacroPaths, TargetLayoutLoadResult,
|
FileId, LangCrateOrigin, ProcMacroPaths, TargetLayoutLoadResult,
|
||||||
@ -154,12 +154,7 @@ pub fn load(
|
|||||||
) -> Result<ProjectWorkspace> {
|
) -> Result<ProjectWorkspace> {
|
||||||
let res = match manifest {
|
let res = match manifest {
|
||||||
ProjectManifest::ProjectJson(project_json) => {
|
ProjectManifest::ProjectJson(project_json) => {
|
||||||
let metadata = fs::symlink_metadata(&project_json).with_context(|| {
|
let project_json = project_json.canonicalize()?;
|
||||||
format!("Failed to read json file {}", project_json.display())
|
|
||||||
})?;
|
|
||||||
if metadata.is_symlink() {
|
|
||||||
bail!("The project-json may not currently point to a symlink");
|
|
||||||
}
|
|
||||||
let file = fs::read_to_string(&project_json).with_context(|| {
|
let file = fs::read_to_string(&project_json).with_context(|| {
|
||||||
format!("Failed to read json file {}", project_json.display())
|
format!("Failed to read json file {}", project_json.display())
|
||||||
})?;
|
})?;
|
||||||
|
Loading…
Reference in New Issue
Block a user