Skip to content

Commit 93a788c

Browse files
committed
Auto merge of rust-lang#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+
2 parents 1fb5142 + 49318bb commit 93a788c

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

crates/project-model/src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub mod target_data_layout;
3131
mod tests;
3232

3333
use std::{
34+
fmt,
3435
fs::{self, read_dir, ReadDir},
3536
io,
3637
process::Command,
@@ -145,6 +146,16 @@ impl ProjectManifest {
145146
}
146147
}
147148

149+
impl fmt::Display for ProjectManifest {
150+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
151+
match self {
152+
ProjectManifest::ProjectJson(it) | ProjectManifest::CargoToml(it) => {
153+
fmt::Display::fmt(&it, f)
154+
}
155+
}
156+
}
157+
}
158+
148159
fn utf8_stdout(mut cmd: Command) -> Result<String> {
149160
let output = cmd.output().with_context(|| format!("{cmd:?} failed"))?;
150161
if !output.status.success() {

crates/project-model/src/manifest_path.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! See [`ManifestPath`].
2-
use std::{ops, path::Path};
2+
use std::{fmt, ops, path::Path};
33

44
use paths::{AbsPath, AbsPathBuf};
55

@@ -40,6 +40,12 @@ impl ManifestPath {
4040
}
4141
}
4242

43+
impl fmt::Display for ManifestPath {
44+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45+
fmt::Display::fmt(&self.file.display(), f)
46+
}
47+
}
48+
4349
impl ops::Deref for ManifestPath {
4450
type Target = AbsPath;
4551

crates/project-model/src/workspace.rs

+9
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ impl ProjectWorkspace {
151151
manifest: ProjectManifest,
152152
config: &CargoConfig,
153153
progress: &dyn Fn(String),
154+
) -> Result<ProjectWorkspace> {
155+
ProjectWorkspace::load_inner(&manifest, config, progress)
156+
.with_context(|| format!("Failed to load the project at {manifest}"))
157+
}
158+
159+
fn load_inner(
160+
manifest: &ProjectManifest,
161+
config: &CargoConfig,
162+
progress: &dyn Fn(String),
154163
) -> Result<ProjectWorkspace> {
155164
let version = |current_dir, cmd_path, prefix: &str| {
156165
let cargo_version = utf8_stdout({

crates/rust-analyzer/src/reload.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,9 @@ impl GlobalState {
534534
pub(super) fn fetch_workspace_error(&self) -> Result<(), String> {
535535
let mut buf = String::new();
536536

537-
let Some((last_op_result, _)) = self.fetch_workspaces_queue.last_op_result() else { return Ok(()) };
537+
let Some((last_op_result, _)) = self.fetch_workspaces_queue.last_op_result() else {
538+
return Ok(())
539+
};
538540
if last_op_result.is_empty() {
539541
stdx::format_to!(buf, "rust-analyzer failed to discover workspace");
540542
} else {

0 commit comments

Comments
 (0)