Auto merge of #15085 - matklad:ws-error, r=matklad

fix: ensure that ws loading error includes path to ws

Should help with https://old.reddit.com/r/rust/comments/14cw5ts/newbie_confused_about_rustanalyzer/

`@bors` r+
This commit is contained in:
bors 2023-06-19 11:57:18 +00:00
commit 93a788cde8
4 changed files with 30 additions and 2 deletions

View File

@ -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<ProjectManifest> {
}
}
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<String> {
let output = cmd.output().with_context(|| format!("{cmd:?} failed"))?;
if !output.status.success() {

View File

@ -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;

View File

@ -151,6 +151,15 @@ pub fn load(
manifest: ProjectManifest,
config: &CargoConfig,
progress: &dyn Fn(String),
) -> Result<ProjectWorkspace> {
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<ProjectWorkspace> {
let version = |current_dir, cmd_path, prefix: &str| {
let cargo_version = utf8_stdout({

View File

@ -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 {