Skip to content

Commit d9c7d28

Browse files
committed
Report sysroot and rustc crate loading errors
1 parent e2ab0ff commit d9c7d28

File tree

11 files changed

+134
-139
lines changed

11 files changed

+134
-139
lines changed

crates/project-model/src/cargo_workspace.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl ops::Index<Target> for CargoWorkspace {
5050

5151
/// Describes how to set the rustc source directory.
5252
#[derive(Clone, Debug, PartialEq, Eq)]
53-
pub enum RustcSource {
53+
pub enum RustLibSource {
5454
/// Explicit path for the rustc source directory.
5555
Path(AbsPathBuf),
5656
/// Try to automatically detect where the rustc source directory is.
@@ -95,10 +95,10 @@ pub struct CargoConfig {
9595
/// rustc target
9696
pub target: Option<String>,
9797
/// Sysroot loading behavior
98-
pub sysroot: Option<RustcSource>,
98+
pub sysroot: Option<RustLibSource>,
9999
pub sysroot_src: Option<AbsPathBuf>,
100100
/// rustc private crate source
101-
pub rustc_source: Option<RustcSource>,
101+
pub rustc_source: Option<RustLibSource>,
102102
/// crates to disable `#[cfg(test)]` on
103103
pub unset_test_crates: UnsetTestCrates,
104104
/// Invoke `cargo check` through the RUSTC_WRAPPER.

crates/project-model/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub use crate::{
4444
build_scripts::WorkspaceBuildScripts,
4545
cargo_workspace::{
4646
CargoConfig, CargoFeatures, CargoWorkspace, Package, PackageData, PackageDependency,
47-
RustcSource, Target, TargetData, TargetKind, UnsetTestCrates,
47+
RustLibSource, Target, TargetData, TargetKind, UnsetTestCrates,
4848
},
4949
manifest_path::ManifestPath,
5050
project_json::{ProjectJson, ProjectJsonData},

crates/project-model/src/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ fn load_cargo_with_overrides(file: &str, cfg_overrides: CfgOverrides) -> CrateGr
2424
let project_workspace = ProjectWorkspace::Cargo {
2525
cargo: cargo_workspace,
2626
build_scripts: WorkspaceBuildScripts::default(),
27-
sysroot: None,
28-
rustc: None,
27+
sysroot: Err(None),
28+
rustc: Err(None),
2929
rustc_cfg: Vec::new(),
3030
cfg_overrides,
3131
toolchain: None,
@@ -37,7 +37,7 @@ fn load_cargo_with_overrides(file: &str, cfg_overrides: CfgOverrides) -> CrateGr
3737
fn load_rust_project(file: &str) -> CrateGraph {
3838
let data = get_test_json_file(file);
3939
let project = rooted_project_json(data);
40-
let sysroot = Some(get_fake_sysroot());
40+
let sysroot = Ok(get_fake_sysroot());
4141
let project_workspace = ProjectWorkspace::Json { project, sysroot, rustc_cfg: Vec::new() };
4242
to_crate_graph(project_workspace)
4343
}

crates/project-model/src/workspace.rs

Lines changed: 94 additions & 115 deletions
Large diffs are not rendered by default.

crates/rust-analyzer/src/cli/analysis_stats.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use ide_db::base_db::{
2424
use itertools::Itertools;
2525
use oorandom::Rand32;
2626
use profile::{Bytes, StopWatch};
27-
use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace, RustcSource};
27+
use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace, RustLibSource};
2828
use rayon::prelude::*;
2929
use rustc_hash::FxHashSet;
3030
use stdx::format_to;
@@ -57,7 +57,7 @@ impl flags::AnalysisStats {
5757
let mut cargo_config = CargoConfig::default();
5858
cargo_config.sysroot = match self.no_sysroot {
5959
true => None,
60-
false => Some(RustcSource::Discover),
60+
false => Some(RustLibSource::Discover),
6161
};
6262
let no_progress = &|_| ();
6363

crates/rust-analyzer/src/cli/diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Analyze all modules in a project for diagnostics. Exits with a non-zero
22
//! status code if any errors are found.
33
4-
use project_model::{CargoConfig, RustcSource};
4+
use project_model::{CargoConfig, RustLibSource};
55
use rustc_hash::FxHashSet;
66

77
use hir::{db::HirDatabase, Crate, Module};
@@ -16,7 +16,7 @@ use crate::cli::{
1616
impl flags::Diagnostics {
1717
pub fn run(self) -> anyhow::Result<()> {
1818
let mut cargo_config = CargoConfig::default();
19-
cargo_config.sysroot = Some(RustcSource::Discover);
19+
cargo_config.sysroot = Some(RustLibSource::Discover);
2020
let load_cargo_config = LoadCargoConfig {
2121
load_out_dirs_from_check: !self.disable_build_scripts,
2222
with_proc_macro_server: ProcMacroServerChoice::Sysroot,

crates/rust-analyzer/src/cli/lsif.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use ide_db::LineIndexDatabase;
1313
use ide_db::base_db::salsa::{self, ParallelDatabase};
1414
use ide_db::line_index::WideEncoding;
1515
use lsp_types::{self, lsif};
16-
use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace, RustcSource};
16+
use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace, RustLibSource};
1717
use vfs::{AbsPathBuf, Vfs};
1818

1919
use crate::cli::load_cargo::ProcMacroServerChoice;
@@ -290,7 +290,7 @@ impl flags::Lsif {
290290
eprintln!("Generating LSIF started...");
291291
let now = Instant::now();
292292
let mut cargo_config = CargoConfig::default();
293-
cargo_config.sysroot = Some(RustcSource::Discover);
293+
cargo_config.sysroot = Some(RustLibSource::Discover);
294294
let no_progress = &|_| ();
295295
let load_cargo_config = LoadCargoConfig {
296296
load_out_dirs_from_check: true,

crates/rust-analyzer/src/cli/scip.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use ide::{
1515
TokenStaticData,
1616
};
1717
use ide_db::LineIndexDatabase;
18-
use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace, RustcSource};
18+
use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace, RustLibSource};
1919
use scip::types as scip_types;
2020
use std::env;
2121

@@ -30,7 +30,7 @@ impl flags::Scip {
3030
eprintln!("Generating SCIP start...");
3131
let now = Instant::now();
3232
let mut cargo_config = CargoConfig::default();
33-
cargo_config.sysroot = Some(RustcSource::Discover);
33+
cargo_config.sysroot = Some(RustLibSource::Discover);
3434

3535
let no_progress = &|s| (eprintln!("rust-analyzer: Loading {s}"));
3636
let load_cargo_config = LoadCargoConfig {

crates/rust-analyzer/src/cli/ssr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Applies structured search replace rules from the command line.
22
33
use ide_ssr::MatchFinder;
4-
use project_model::{CargoConfig, RustcSource};
4+
use project_model::{CargoConfig, RustLibSource};
55

66
use crate::cli::{
77
flags,
@@ -13,7 +13,7 @@ impl flags::Ssr {
1313
pub fn run(self) -> Result<()> {
1414
use ide_db::base_db::SourceDatabaseExt;
1515
let mut cargo_config = CargoConfig::default();
16-
cargo_config.sysroot = Some(RustcSource::Discover);
16+
cargo_config.sysroot = Some(RustLibSource::Discover);
1717
let load_cargo_config = LoadCargoConfig {
1818
load_out_dirs_from_check: true,
1919
with_proc_macro_server: ProcMacroServerChoice::Sysroot,

crates/rust-analyzer/src/config.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use ide_db::{
2222
use itertools::Itertools;
2323
use lsp_types::{ClientCapabilities, MarkupKind};
2424
use project_model::{
25-
CargoConfig, CargoFeatures, ProjectJson, ProjectJsonData, ProjectManifest, RustcSource,
25+
CargoConfig, CargoFeatures, ProjectJson, ProjectJsonData, ProjectManifest, RustLibSource,
2626
UnsetTestCrates,
2727
};
2828
use rustc_hash::{FxHashMap, FxHashSet};
@@ -1129,16 +1129,16 @@ impl Config {
11291129
pub fn cargo(&self) -> CargoConfig {
11301130
let rustc_source = self.data.rustc_source.as_ref().map(|rustc_src| {
11311131
if rustc_src == "discover" {
1132-
RustcSource::Discover
1132+
RustLibSource::Discover
11331133
} else {
1134-
RustcSource::Path(self.root_path.join(rustc_src))
1134+
RustLibSource::Path(self.root_path.join(rustc_src))
11351135
}
11361136
});
11371137
let sysroot = self.data.cargo_sysroot.as_ref().map(|sysroot| {
11381138
if sysroot == "discover" {
1139-
RustcSource::Discover
1139+
RustLibSource::Discover
11401140
} else {
1141-
RustcSource::Path(self.root_path.join(sysroot))
1141+
RustLibSource::Path(self.root_path.join(sysroot))
11421142
}
11431143
});
11441144
let sysroot_src =

crates/rust-analyzer/src/reload.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl GlobalState {
105105
&& self.fetch_workspaces_queue.op_requested()
106106
{
107107
status.health = lsp_ext::Health::Warning;
108-
message.push_str("Auto-reloading is disabled, a workspace reload required.\n\n");
108+
message.push_str("Auto-reloading is disabled and the workspace has changed, a manual workspace reload is required.\n\n");
109109
}
110110
if self.config.linked_projects().is_empty()
111111
&& self.config.detached_files().is_empty()
@@ -115,9 +115,25 @@ impl GlobalState {
115115
message.push_str("Failed to discover workspace.\n\n");
116116
}
117117

118+
for ws in self.workspaces.iter() {
119+
let (ProjectWorkspace::Cargo { sysroot, .. }
120+
| ProjectWorkspace::Json { sysroot, .. }
121+
| ProjectWorkspace::DetachedFiles { sysroot, .. }) = ws;
122+
if let Err(Some(e)) = sysroot {
123+
status.health = lsp_ext::Health::Warning;
124+
message.push_str(e);
125+
message.push_str("\n\n");
126+
}
127+
if let ProjectWorkspace::Cargo { rustc: Err(Some(e)), .. } = ws {
128+
status.health = lsp_ext::Health::Warning;
129+
message.push_str(e);
130+
message.push_str("\n\n");
131+
}
132+
}
133+
118134
if let Err(_) = self.fetch_workspace_error() {
119135
status.health = lsp_ext::Health::Error;
120-
message.push_str("Failed to load workspaces\n\n");
136+
message.push_str("Failed to load workspaces.\n\n");
121137
}
122138

123139
if !message.is_empty() {

0 commit comments

Comments
 (0)