diff --git a/crates/project-model/src/lib.rs b/crates/project-model/src/lib.rs index 61acc646f81..9685fb3f975 100644 --- a/crates/project-model/src/lib.rs +++ b/crates/project-model/src/lib.rs @@ -31,6 +31,7 @@ mod tests; use std::{ + fmt, fs::{self, read_dir, ReadDir}, io, process::Command, @@ -145,6 +146,16 @@ pub fn discover_all(paths: &[AbsPathBuf]) -> Vec { } } +impl fmt::Display for ProjectManifest { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + ProjectManifest::ProjectJson(it) | ProjectManifest::CargoToml(it) => { + fmt::Display::fmt(&it, f) + } + } + } +} + fn utf8_stdout(mut cmd: Command) -> Result { let output = cmd.output().with_context(|| format!("{cmd:?} failed"))?; if !output.status.success() { diff --git a/crates/project-model/src/manifest_path.rs b/crates/project-model/src/manifest_path.rs index 3f60e4dd92f..5ef2086fdad 100644 --- a/crates/project-model/src/manifest_path.rs +++ b/crates/project-model/src/manifest_path.rs @@ -1,5 +1,5 @@ //! See [`ManifestPath`]. -use std::{ops, path::Path}; +use std::{fmt, ops, path::Path}; use paths::{AbsPath, AbsPathBuf}; @@ -40,6 +40,12 @@ pub fn canonicalize(&self) -> ! { } } +impl fmt::Display for ManifestPath { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Display::fmt(&self.file.display(), f) + } +} + impl ops::Deref for ManifestPath { type Target = AbsPath; diff --git a/crates/project-model/src/workspace.rs b/crates/project-model/src/workspace.rs index b5fe237fc4c..34e5c1a9e24 100644 --- a/crates/project-model/src/workspace.rs +++ b/crates/project-model/src/workspace.rs @@ -151,6 +151,15 @@ pub fn load( manifest: ProjectManifest, config: &CargoConfig, progress: &dyn Fn(String), + ) -> Result { + ProjectWorkspace::load_inner(&manifest, config, progress) + .with_context(|| format!("Failed to load the project at {manifest}")) + } + + fn load_inner( + manifest: &ProjectManifest, + config: &CargoConfig, + progress: &dyn Fn(String), ) -> Result { let version = |current_dir, cmd_path, prefix: &str| { let cargo_version = utf8_stdout({ diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index 310c6b076c0..07e284e3463 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs @@ -534,7 +534,9 @@ fn recreate_crate_graph(&mut self, cause: String) { pub(super) fn fetch_workspace_error(&self) -> Result<(), String> { let mut buf = String::new(); - let Some((last_op_result, _)) = self.fetch_workspaces_queue.last_op_result() else { return Ok(()) }; + let Some((last_op_result, _)) = self.fetch_workspaces_queue.last_op_result() else { + return Ok(()) + }; if last_op_result.is_empty() { stdx::format_to!(buf, "rust-analyzer failed to discover workspace"); } else {