Report sysroot and rustc crate loading errors

This commit is contained in:
Lukas Wirth 2023-03-15 11:35:34 +01:00
parent e2ab0ff124
commit d9c7d28e0d
11 changed files with 134 additions and 139 deletions

View File

@ -50,7 +50,7 @@ impl ops::Index<Target> for CargoWorkspace {
/// Describes how to set the rustc source directory. /// Describes how to set the rustc source directory.
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub enum RustcSource { pub enum RustLibSource {
/// Explicit path for the rustc source directory. /// Explicit path for the rustc source directory.
Path(AbsPathBuf), Path(AbsPathBuf),
/// Try to automatically detect where the rustc source directory is. /// Try to automatically detect where the rustc source directory is.
@ -95,10 +95,10 @@ pub struct CargoConfig {
/// rustc target /// rustc target
pub target: Option<String>, pub target: Option<String>,
/// Sysroot loading behavior /// Sysroot loading behavior
pub sysroot: Option<RustcSource>, pub sysroot: Option<RustLibSource>,
pub sysroot_src: Option<AbsPathBuf>, pub sysroot_src: Option<AbsPathBuf>,
/// rustc private crate source /// rustc private crate source
pub rustc_source: Option<RustcSource>, pub rustc_source: Option<RustLibSource>,
/// crates to disable `#[cfg(test)]` on /// crates to disable `#[cfg(test)]` on
pub unset_test_crates: UnsetTestCrates, pub unset_test_crates: UnsetTestCrates,
/// Invoke `cargo check` through the RUSTC_WRAPPER. /// Invoke `cargo check` through the RUSTC_WRAPPER.

View File

@ -44,7 +44,7 @@ pub use crate::{
build_scripts::WorkspaceBuildScripts, build_scripts::WorkspaceBuildScripts,
cargo_workspace::{ cargo_workspace::{
CargoConfig, CargoFeatures, CargoWorkspace, Package, PackageData, PackageDependency, CargoConfig, CargoFeatures, CargoWorkspace, Package, PackageData, PackageDependency,
RustcSource, Target, TargetData, TargetKind, UnsetTestCrates, RustLibSource, Target, TargetData, TargetKind, UnsetTestCrates,
}, },
manifest_path::ManifestPath, manifest_path::ManifestPath,
project_json::{ProjectJson, ProjectJsonData}, project_json::{ProjectJson, ProjectJsonData},

View File

@ -24,8 +24,8 @@ fn load_cargo_with_overrides(file: &str, cfg_overrides: CfgOverrides) -> CrateGr
let project_workspace = ProjectWorkspace::Cargo { let project_workspace = ProjectWorkspace::Cargo {
cargo: cargo_workspace, cargo: cargo_workspace,
build_scripts: WorkspaceBuildScripts::default(), build_scripts: WorkspaceBuildScripts::default(),
sysroot: None, sysroot: Err(None),
rustc: None, rustc: Err(None),
rustc_cfg: Vec::new(), rustc_cfg: Vec::new(),
cfg_overrides, cfg_overrides,
toolchain: None, toolchain: None,
@ -37,7 +37,7 @@ fn load_cargo_with_overrides(file: &str, cfg_overrides: CfgOverrides) -> CrateGr
fn load_rust_project(file: &str) -> CrateGraph { fn load_rust_project(file: &str) -> CrateGraph {
let data = get_test_json_file(file); let data = get_test_json_file(file);
let project = rooted_project_json(data); let project = rooted_project_json(data);
let sysroot = Some(get_fake_sysroot()); let sysroot = Ok(get_fake_sysroot());
let project_workspace = ProjectWorkspace::Json { project, sysroot, rustc_cfg: Vec::new() }; let project_workspace = ProjectWorkspace::Json { project, sysroot, rustc_cfg: Vec::new() };
to_crate_graph(project_workspace) to_crate_graph(project_workspace)
} }

View File

@ -17,7 +17,7 @@ use stdx::{always, hash::NoHashHashMap};
use crate::{ use crate::{
build_scripts::BuildScriptOutput, build_scripts::BuildScriptOutput,
cargo_workspace::{DepKind, PackageData, RustcSource}, cargo_workspace::{DepKind, PackageData, RustLibSource},
cfg_flag::CfgFlag, cfg_flag::CfgFlag,
rustc_cfg, rustc_cfg,
sysroot::SysrootCrate, sysroot::SysrootCrate,
@ -69,8 +69,8 @@ pub enum ProjectWorkspace {
Cargo { Cargo {
cargo: CargoWorkspace, cargo: CargoWorkspace,
build_scripts: WorkspaceBuildScripts, build_scripts: WorkspaceBuildScripts,
sysroot: Option<Sysroot>, sysroot: Result<Sysroot, Option<String>>,
rustc: Option<(CargoWorkspace, WorkspaceBuildScripts)>, rustc: Result<(CargoWorkspace, WorkspaceBuildScripts), Option<String>>,
/// Holds cfg flags for the current target. We get those by running /// Holds cfg flags for the current target. We get those by running
/// `rustc --print cfg`. /// `rustc --print cfg`.
/// ///
@ -82,7 +82,7 @@ pub enum ProjectWorkspace {
target_layout: Result<String, String>, target_layout: Result<String, String>,
}, },
/// Project workspace was manually specified using a `rust-project.json` file. /// Project workspace was manually specified using a `rust-project.json` file.
Json { project: ProjectJson, sysroot: Option<Sysroot>, rustc_cfg: Vec<CfgFlag> }, Json { project: ProjectJson, sysroot: Result<Sysroot, Option<String>>, rustc_cfg: Vec<CfgFlag> },
// FIXME: The primary limitation of this approach is that the set of detached files needs to be fixed at the beginning. // FIXME: The primary limitation of this approach is that the set of detached files needs to be fixed at the beginning.
// That's not the end user experience we should strive for. // That's not the end user experience we should strive for.
// Ideally, you should be able to just open a random detached file in existing cargo projects, and get the basic features working. // Ideally, you should be able to just open a random detached file in existing cargo projects, and get the basic features working.
@ -93,7 +93,11 @@ pub enum ProjectWorkspace {
// // // //
/// Project with a set of disjoint files, not belonging to any particular workspace. /// Project with a set of disjoint files, not belonging to any particular workspace.
/// Backed by basic sysroot crates for basic completion and highlighting. /// Backed by basic sysroot crates for basic completion and highlighting.
DetachedFiles { files: Vec<AbsPathBuf>, sysroot: Option<Sysroot>, rustc_cfg: Vec<CfgFlag> }, DetachedFiles {
files: Vec<AbsPathBuf>,
sysroot: Result<Sysroot, Option<String>>,
rustc_cfg: Vec<CfgFlag>,
},
} }
impl fmt::Debug for ProjectWorkspace { impl fmt::Debug for ProjectWorkspace {
@ -113,7 +117,7 @@ impl fmt::Debug for ProjectWorkspace {
.debug_struct("Cargo") .debug_struct("Cargo")
.field("root", &cargo.workspace_root().file_name()) .field("root", &cargo.workspace_root().file_name())
.field("n_packages", &cargo.packages().len()) .field("n_packages", &cargo.packages().len())
.field("sysroot", &sysroot.is_some()) .field("sysroot", &sysroot.is_ok())
.field( .field(
"n_rustc_compiler_crates", "n_rustc_compiler_crates",
&rustc.as_ref().map_or(0, |(rc, _)| rc.packages().len()), &rustc.as_ref().map_or(0, |(rc, _)| rc.packages().len()),
@ -126,7 +130,7 @@ impl fmt::Debug for ProjectWorkspace {
ProjectWorkspace::Json { project, sysroot, rustc_cfg } => { ProjectWorkspace::Json { project, sysroot, rustc_cfg } => {
let mut debug_struct = f.debug_struct("Json"); let mut debug_struct = f.debug_struct("Json");
debug_struct.field("n_crates", &project.n_crates()); debug_struct.field("n_crates", &project.n_crates());
if let Some(sysroot) = sysroot { if let Ok(sysroot) = sysroot {
debug_struct.field("n_sysroot_crates", &sysroot.crates().len()); debug_struct.field("n_sysroot_crates", &sysroot.crates().len());
} }
debug_struct.field("n_rustc_cfg", &rustc_cfg.len()); debug_struct.field("n_rustc_cfg", &rustc_cfg.len());
@ -135,7 +139,7 @@ impl fmt::Debug for ProjectWorkspace {
ProjectWorkspace::DetachedFiles { files, sysroot, rustc_cfg } => f ProjectWorkspace::DetachedFiles { files, sysroot, rustc_cfg } => f
.debug_struct("DetachedFiles") .debug_struct("DetachedFiles")
.field("n_files", &files.len()) .field("n_files", &files.len())
.field("sysroot", &sysroot.is_some()) .field("sysroot", &sysroot.is_ok())
.field("n_rustc_cfg", &rustc_cfg.len()) .field("n_rustc_cfg", &rustc_cfg.len())
.finish(), .finish(),
} }
@ -191,96 +195,81 @@ impl ProjectWorkspace {
let cargo = CargoWorkspace::new(meta); let cargo = CargoWorkspace::new(meta);
let sysroot = match (&config.sysroot, &config.sysroot_src) { let sysroot = match (&config.sysroot, &config.sysroot_src) {
(Some(RustcSource::Path(path)), None) => { (Some(RustLibSource::Path(path)), None) => {
match Sysroot::with_sysroot_dir(path.clone()) { Sysroot::with_sysroot_dir(path.clone()).map_err(|e| {
Ok(it) => Some(it), Some(format!("Failed to find sysroot at {}:{e}", path.display()))
Err(e) => { })
tracing::error!(%e, "Failed to find sysroot at {}.", path.display());
None
}
}
} }
(Some(RustcSource::Discover), None) => { (Some(RustLibSource::Discover), None) => {
match Sysroot::discover(cargo_toml.parent(), &config.extra_env) { Sysroot::discover(cargo_toml.parent(), &config.extra_env).map_err(|e| {
Ok(it) => Some(it), Some(format!("Failed to find sysroot for Cargo.toml file {}. Is rust-src installed? {e}", cargo_toml.display()))
Err(e) => { })
tracing::error!(
%e,
"Failed to find sysroot for Cargo.toml file {}. Is rust-src installed?",
cargo_toml.display()
);
None
}
}
} }
(Some(RustcSource::Path(sysroot)), Some(sysroot_src)) => { (Some(RustLibSource::Path(sysroot)), Some(sysroot_src)) => {
Some(Sysroot::load(sysroot.clone(), sysroot_src.clone())) Ok(Sysroot::load(sysroot.clone(), sysroot_src.clone()))
} }
(Some(RustcSource::Discover), Some(sysroot_src)) => { (Some(RustLibSource::Discover), Some(sysroot_src)) => {
match Sysroot::discover_with_src_override( Sysroot::discover_with_src_override(
cargo_toml.parent(), cargo_toml.parent(),
&config.extra_env, &config.extra_env,
sysroot_src.clone(), sysroot_src.clone(),
) { ).map_err(|e| {
Ok(it) => Some(it), Some(format!("Failed to find sysroot for Cargo.toml file {}. Is rust-src installed? {e}", cargo_toml.display()))
Err(e) => { })
tracing::error!(
%e,
"Failed to find sysroot for Cargo.toml file {}. Is rust-src installed?",
cargo_toml.display()
);
None
}
}
} }
(None, _) => None, (None, _) => Err(None),
}; };
if let Some(sysroot) = &sysroot { if let Ok(sysroot) = &sysroot {
tracing::info!(workspace = %cargo_toml.display(), src_root = %sysroot.src_root().display(), root = %sysroot.root().display(), "Using sysroot"); tracing::info!(workspace = %cargo_toml.display(), src_root = %sysroot.src_root().display(), root = %sysroot.root().display(), "Using sysroot");
} }
let rustc_dir = match &config.rustc_source { let rustc_dir = match &config.rustc_source {
Some(RustcSource::Path(path)) => ManifestPath::try_from(path.clone()).ok(), Some(RustLibSource::Path(path)) => ManifestPath::try_from(path.clone())
Some(RustcSource::Discover) => { .map_err(|p| {
sysroot.as_ref().and_then(Sysroot::discover_rustc) Some(format!("rustc source path is not absolute: {}", p.display()))
}),
Some(RustLibSource::Discover) => {
sysroot.as_ref().ok().and_then(Sysroot::discover_rustc).ok_or_else(|| {
Some(format!("Failed to discover rustc source for sysroot."))
})
} }
None => None, None => Err(None),
}; };
let rustc = match rustc_dir { let rustc = rustc_dir.and_then(|rustc_dir| {
Some(rustc_dir) => { tracing::info!(workspace = %cargo_toml.display(), rustc_dir = %rustc_dir.display(), "Using rustc source");
tracing::info!(workspace = %cargo_toml.display(), rustc_dir = %rustc_dir.display(), "Using rustc source"); match CargoWorkspace::fetch_metadata(
match CargoWorkspace::fetch_metadata( &rustc_dir,
&rustc_dir, cargo_toml.parent(),
cargo_toml.parent(), &CargoConfig {
&CargoConfig { features: crate::CargoFeatures::default(),
features: crate::CargoFeatures::default(), ..config.clone()
..config.clone() },
}, progress,
progress, ) {
) { Ok(meta) => {
Ok(meta) => { let workspace = CargoWorkspace::new(meta);
let workspace = CargoWorkspace::new(meta); let buildscripts = WorkspaceBuildScripts::rustc_crates(
let buildscripts = WorkspaceBuildScripts::rustc_crates( &workspace,
&workspace, cargo_toml.parent(),
cargo_toml.parent(), &config.extra_env,
&config.extra_env, );
); Ok((workspace, buildscripts))
Some((workspace, buildscripts)) }
} Err(e) => {
Err(e) => { tracing::error!(
tracing::error!( %e,
%e, "Failed to read Cargo metadata from rustc source at {}",
"Failed to read Cargo metadata from rustc source at {}", rustc_dir.display()
rustc_dir.display() );
); Err(Some(format!(
None "Failed to read Cargo metadata from rustc source at {}: {e}",
} rustc_dir.display())
))
} }
} }
None => None, });
};
let rustc_cfg = let rustc_cfg =
rustc_cfg::get(Some(&cargo_toml), config.target.as_deref(), &config.extra_env); rustc_cfg::get(Some(&cargo_toml), config.target.as_deref(), &config.extra_env);
@ -316,12 +305,12 @@ impl ProjectWorkspace {
extra_env: &FxHashMap<String, String>, extra_env: &FxHashMap<String, String>,
) -> ProjectWorkspace { ) -> ProjectWorkspace {
let sysroot = match (project_json.sysroot.clone(), project_json.sysroot_src.clone()) { let sysroot = match (project_json.sysroot.clone(), project_json.sysroot_src.clone()) {
(Some(sysroot), Some(sysroot_src)) => Some(Sysroot::load(sysroot, sysroot_src)), (Some(sysroot), Some(sysroot_src)) => Ok(Sysroot::load(sysroot, sysroot_src)),
(Some(sysroot), None) => { (Some(sysroot), None) => {
// assume sysroot is structured like rustup's and guess `sysroot_src` // assume sysroot is structured like rustup's and guess `sysroot_src`
let sysroot_src = let sysroot_src =
sysroot.join("lib").join("rustlib").join("src").join("rust").join("library"); sysroot.join("lib").join("rustlib").join("src").join("rust").join("library");
Some(Sysroot::load(sysroot, sysroot_src)) Ok(Sysroot::load(sysroot, sysroot_src))
} }
(None, Some(sysroot_src)) => { (None, Some(sysroot_src)) => {
// assume sysroot is structured like rustup's and guess `sysroot` // assume sysroot is structured like rustup's and guess `sysroot`
@ -329,11 +318,11 @@ impl ProjectWorkspace {
for _ in 0..5 { for _ in 0..5 {
sysroot.pop(); sysroot.pop();
} }
Some(Sysroot::load(sysroot, sysroot_src)) Ok(Sysroot::load(sysroot, sysroot_src))
} }
(None, None) => None, (None, None) => Err(None),
}; };
if let Some(sysroot) = &sysroot { if let Ok(sysroot) = &sysroot {
tracing::info!(src_root = %sysroot.src_root().display(), root = %sysroot.root().display(), "Using sysroot"); tracing::info!(src_root = %sysroot.src_root().display(), root = %sysroot.root().display(), "Using sysroot");
} }
@ -346,33 +335,23 @@ impl ProjectWorkspace {
config: &CargoConfig, config: &CargoConfig,
) -> Result<ProjectWorkspace> { ) -> Result<ProjectWorkspace> {
let sysroot = match &config.sysroot { let sysroot = match &config.sysroot {
Some(RustcSource::Path(path)) => match Sysroot::with_sysroot_dir(path.clone()) { Some(RustLibSource::Path(path)) => Sysroot::with_sysroot_dir(path.clone())
Ok(it) => Some(it), .map_err(|e| Some(format!("Failed to find sysroot at {}:{e}", path.display()))),
Err(e) => { Some(RustLibSource::Discover) => {
tracing::error!(%e, "Failed to find sysroot at {}.", path.display());
None
}
},
Some(RustcSource::Discover) => {
let dir = &detached_files let dir = &detached_files
.first() .first()
.and_then(|it| it.parent()) .and_then(|it| it.parent())
.ok_or_else(|| format_err!("No detached files to load"))?; .ok_or_else(|| format_err!("No detached files to load"))?;
match Sysroot::discover(dir, &config.extra_env) { Sysroot::discover(dir, &config.extra_env).map_err(|e| {
Ok(it) => Some(it), Some(format!(
Err(e) => { "Failed to find sysroot for {}. Is rust-src installed? {e}",
tracing::error!( dir.display()
%e, ))
"Failed to find sysroot for {}. Is rust-src installed?", })
dir.display()
);
None
}
}
} }
None => None, None => Err(None),
}; };
if let Some(sysroot) = &sysroot { if let Ok(sysroot) = &sysroot {
tracing::info!(src_root = %sysroot.src_root().display(), root = %sysroot.root().display(), "Using sysroot"); tracing::info!(src_root = %sysroot.src_root().display(), root = %sysroot.root().display(), "Using sysroot");
} }
let rustc_cfg = rustc_cfg::get(None, None, &Default::default()); let rustc_cfg = rustc_cfg::get(None, None, &Default::default());
@ -463,8 +442,8 @@ impl ProjectWorkspace {
pub fn find_sysroot_proc_macro_srv(&self) -> Option<AbsPathBuf> { pub fn find_sysroot_proc_macro_srv(&self) -> Option<AbsPathBuf> {
match self { match self {
ProjectWorkspace::Cargo { sysroot: Some(sysroot), .. } ProjectWorkspace::Cargo { sysroot: Ok(sysroot), .. }
| ProjectWorkspace::Json { sysroot: Some(sysroot), .. } => { | ProjectWorkspace::Json { sysroot: Ok(sysroot), .. } => {
let standalone_server_name = let standalone_server_name =
format!("rust-analyzer-proc-macro-srv{}", std::env::consts::EXE_SUFFIX); format!("rust-analyzer-proc-macro-srv{}", std::env::consts::EXE_SUFFIX);
["libexec", "lib"] ["libexec", "lib"]
@ -480,7 +459,7 @@ impl ProjectWorkspace {
/// The return type contains the path and whether or not /// The return type contains the path and whether or not
/// the root is a member of the current workspace /// the root is a member of the current workspace
pub fn to_roots(&self) -> Vec<PackageRoot> { pub fn to_roots(&self) -> Vec<PackageRoot> {
let mk_sysroot = |sysroot: Option<&Sysroot>, project_root: Option<&AbsPath>| { let mk_sysroot = |sysroot: Result<&Sysroot, _>, project_root: Option<&AbsPath>| {
sysroot.map(|sysroot| PackageRoot { sysroot.map(|sysroot| PackageRoot {
// mark the sysroot as mutable if it is located inside of the project // mark the sysroot as mutable if it is located inside of the project
is_local: project_root is_local: project_root
@ -603,7 +582,7 @@ impl ProjectWorkspace {
load_proc_macro, load_proc_macro,
load, load,
project, project,
sysroot.as_ref(), sysroot.as_ref().ok(),
extra_env, extra_env,
Err("rust-project.json projects have no target layout set".into()), Err("rust-project.json projects have no target layout set".into()),
), ),
@ -619,9 +598,9 @@ impl ProjectWorkspace {
} => cargo_to_crate_graph( } => cargo_to_crate_graph(
load_proc_macro, load_proc_macro,
load, load,
rustc, rustc.as_ref().ok(),
cargo, cargo,
sysroot.as_ref(), sysroot.as_ref().ok(),
rustc_cfg.clone(), rustc_cfg.clone(),
cfg_overrides, cfg_overrides,
build_scripts, build_scripts,
@ -635,7 +614,7 @@ impl ProjectWorkspace {
rustc_cfg.clone(), rustc_cfg.clone(),
load, load,
files, files,
sysroot, sysroot.as_ref().ok(),
Err("detached file projects have no target layout set".into()), Err("detached file projects have no target layout set".into()),
) )
} }
@ -797,7 +776,7 @@ fn project_json_to_crate_graph(
fn cargo_to_crate_graph( fn cargo_to_crate_graph(
load_proc_macro: &mut dyn FnMut(&str, &AbsPath) -> ProcMacroLoadResult, load_proc_macro: &mut dyn FnMut(&str, &AbsPath) -> ProcMacroLoadResult,
load: &mut dyn FnMut(&AbsPath) -> Option<FileId>, load: &mut dyn FnMut(&AbsPath) -> Option<FileId>,
rustc: &Option<(CargoWorkspace, WorkspaceBuildScripts)>, rustc: Option<&(CargoWorkspace, WorkspaceBuildScripts)>,
cargo: &CargoWorkspace, cargo: &CargoWorkspace,
sysroot: Option<&Sysroot>, sysroot: Option<&Sysroot>,
rustc_cfg: Vec<CfgFlag>, rustc_cfg: Vec<CfgFlag>,
@ -974,7 +953,7 @@ fn detached_files_to_crate_graph(
rustc_cfg: Vec<CfgFlag>, rustc_cfg: Vec<CfgFlag>,
load: &mut dyn FnMut(&AbsPath) -> Option<FileId>, load: &mut dyn FnMut(&AbsPath) -> Option<FileId>,
detached_files: &[AbsPathBuf], detached_files: &[AbsPathBuf],
sysroot: &Option<Sysroot>, sysroot: Option<&Sysroot>,
target_layout: TargetLayoutLoadResult, target_layout: TargetLayoutLoadResult,
) -> CrateGraph { ) -> CrateGraph {
let _p = profile::span("detached_files_to_crate_graph"); let _p = profile::span("detached_files_to_crate_graph");

View File

@ -24,7 +24,7 @@ use ide_db::base_db::{
use itertools::Itertools; use itertools::Itertools;
use oorandom::Rand32; use oorandom::Rand32;
use profile::{Bytes, StopWatch}; use profile::{Bytes, StopWatch};
use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace, RustcSource}; use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace, RustLibSource};
use rayon::prelude::*; use rayon::prelude::*;
use rustc_hash::FxHashSet; use rustc_hash::FxHashSet;
use stdx::format_to; use stdx::format_to;
@ -57,7 +57,7 @@ impl flags::AnalysisStats {
let mut cargo_config = CargoConfig::default(); let mut cargo_config = CargoConfig::default();
cargo_config.sysroot = match self.no_sysroot { cargo_config.sysroot = match self.no_sysroot {
true => None, true => None,
false => Some(RustcSource::Discover), false => Some(RustLibSource::Discover),
}; };
let no_progress = &|_| (); let no_progress = &|_| ();

View File

@ -1,7 +1,7 @@
//! Analyze all modules in a project for diagnostics. Exits with a non-zero //! Analyze all modules in a project for diagnostics. Exits with a non-zero
//! status code if any errors are found. //! status code if any errors are found.
use project_model::{CargoConfig, RustcSource}; use project_model::{CargoConfig, RustLibSource};
use rustc_hash::FxHashSet; use rustc_hash::FxHashSet;
use hir::{db::HirDatabase, Crate, Module}; use hir::{db::HirDatabase, Crate, Module};
@ -16,7 +16,7 @@ use crate::cli::{
impl flags::Diagnostics { impl flags::Diagnostics {
pub fn run(self) -> anyhow::Result<()> { pub fn run(self) -> anyhow::Result<()> {
let mut cargo_config = CargoConfig::default(); let mut cargo_config = CargoConfig::default();
cargo_config.sysroot = Some(RustcSource::Discover); cargo_config.sysroot = Some(RustLibSource::Discover);
let load_cargo_config = LoadCargoConfig { let load_cargo_config = LoadCargoConfig {
load_out_dirs_from_check: !self.disable_build_scripts, load_out_dirs_from_check: !self.disable_build_scripts,
with_proc_macro_server: ProcMacroServerChoice::Sysroot, with_proc_macro_server: ProcMacroServerChoice::Sysroot,

View File

@ -13,7 +13,7 @@ use ide_db::LineIndexDatabase;
use ide_db::base_db::salsa::{self, ParallelDatabase}; use ide_db::base_db::salsa::{self, ParallelDatabase};
use ide_db::line_index::WideEncoding; use ide_db::line_index::WideEncoding;
use lsp_types::{self, lsif}; use lsp_types::{self, lsif};
use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace, RustcSource}; use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace, RustLibSource};
use vfs::{AbsPathBuf, Vfs}; use vfs::{AbsPathBuf, Vfs};
use crate::cli::load_cargo::ProcMacroServerChoice; use crate::cli::load_cargo::ProcMacroServerChoice;
@ -290,7 +290,7 @@ impl flags::Lsif {
eprintln!("Generating LSIF started..."); eprintln!("Generating LSIF started...");
let now = Instant::now(); let now = Instant::now();
let mut cargo_config = CargoConfig::default(); let mut cargo_config = CargoConfig::default();
cargo_config.sysroot = Some(RustcSource::Discover); cargo_config.sysroot = Some(RustLibSource::Discover);
let no_progress = &|_| (); let no_progress = &|_| ();
let load_cargo_config = LoadCargoConfig { let load_cargo_config = LoadCargoConfig {
load_out_dirs_from_check: true, load_out_dirs_from_check: true,

View File

@ -15,7 +15,7 @@ use ide::{
TokenStaticData, TokenStaticData,
}; };
use ide_db::LineIndexDatabase; use ide_db::LineIndexDatabase;
use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace, RustcSource}; use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace, RustLibSource};
use scip::types as scip_types; use scip::types as scip_types;
use std::env; use std::env;
@ -30,7 +30,7 @@ impl flags::Scip {
eprintln!("Generating SCIP start..."); eprintln!("Generating SCIP start...");
let now = Instant::now(); let now = Instant::now();
let mut cargo_config = CargoConfig::default(); let mut cargo_config = CargoConfig::default();
cargo_config.sysroot = Some(RustcSource::Discover); cargo_config.sysroot = Some(RustLibSource::Discover);
let no_progress = &|s| (eprintln!("rust-analyzer: Loading {s}")); let no_progress = &|s| (eprintln!("rust-analyzer: Loading {s}"));
let load_cargo_config = LoadCargoConfig { let load_cargo_config = LoadCargoConfig {

View File

@ -1,7 +1,7 @@
//! Applies structured search replace rules from the command line. //! Applies structured search replace rules from the command line.
use ide_ssr::MatchFinder; use ide_ssr::MatchFinder;
use project_model::{CargoConfig, RustcSource}; use project_model::{CargoConfig, RustLibSource};
use crate::cli::{ use crate::cli::{
flags, flags,
@ -13,7 +13,7 @@ impl flags::Ssr {
pub fn run(self) -> Result<()> { pub fn run(self) -> Result<()> {
use ide_db::base_db::SourceDatabaseExt; use ide_db::base_db::SourceDatabaseExt;
let mut cargo_config = CargoConfig::default(); let mut cargo_config = CargoConfig::default();
cargo_config.sysroot = Some(RustcSource::Discover); cargo_config.sysroot = Some(RustLibSource::Discover);
let load_cargo_config = LoadCargoConfig { let load_cargo_config = LoadCargoConfig {
load_out_dirs_from_check: true, load_out_dirs_from_check: true,
with_proc_macro_server: ProcMacroServerChoice::Sysroot, with_proc_macro_server: ProcMacroServerChoice::Sysroot,

View File

@ -22,7 +22,7 @@ use ide_db::{
use itertools::Itertools; use itertools::Itertools;
use lsp_types::{ClientCapabilities, MarkupKind}; use lsp_types::{ClientCapabilities, MarkupKind};
use project_model::{ use project_model::{
CargoConfig, CargoFeatures, ProjectJson, ProjectJsonData, ProjectManifest, RustcSource, CargoConfig, CargoFeatures, ProjectJson, ProjectJsonData, ProjectManifest, RustLibSource,
UnsetTestCrates, UnsetTestCrates,
}; };
use rustc_hash::{FxHashMap, FxHashSet}; use rustc_hash::{FxHashMap, FxHashSet};
@ -1129,16 +1129,16 @@ impl Config {
pub fn cargo(&self) -> CargoConfig { pub fn cargo(&self) -> CargoConfig {
let rustc_source = self.data.rustc_source.as_ref().map(|rustc_src| { let rustc_source = self.data.rustc_source.as_ref().map(|rustc_src| {
if rustc_src == "discover" { if rustc_src == "discover" {
RustcSource::Discover RustLibSource::Discover
} else { } else {
RustcSource::Path(self.root_path.join(rustc_src)) RustLibSource::Path(self.root_path.join(rustc_src))
} }
}); });
let sysroot = self.data.cargo_sysroot.as_ref().map(|sysroot| { let sysroot = self.data.cargo_sysroot.as_ref().map(|sysroot| {
if sysroot == "discover" { if sysroot == "discover" {
RustcSource::Discover RustLibSource::Discover
} else { } else {
RustcSource::Path(self.root_path.join(sysroot)) RustLibSource::Path(self.root_path.join(sysroot))
} }
}); });
let sysroot_src = let sysroot_src =

View File

@ -105,7 +105,7 @@ impl GlobalState {
&& self.fetch_workspaces_queue.op_requested() && self.fetch_workspaces_queue.op_requested()
{ {
status.health = lsp_ext::Health::Warning; status.health = lsp_ext::Health::Warning;
message.push_str("Auto-reloading is disabled, a workspace reload required.\n\n"); message.push_str("Auto-reloading is disabled and the workspace has changed, a manual workspace reload is required.\n\n");
} }
if self.config.linked_projects().is_empty() if self.config.linked_projects().is_empty()
&& self.config.detached_files().is_empty() && self.config.detached_files().is_empty()
@ -115,9 +115,25 @@ impl GlobalState {
message.push_str("Failed to discover workspace.\n\n"); message.push_str("Failed to discover workspace.\n\n");
} }
for ws in self.workspaces.iter() {
let (ProjectWorkspace::Cargo { sysroot, .. }
| ProjectWorkspace::Json { sysroot, .. }
| ProjectWorkspace::DetachedFiles { sysroot, .. }) = ws;
if let Err(Some(e)) = sysroot {
status.health = lsp_ext::Health::Warning;
message.push_str(e);
message.push_str("\n\n");
}
if let ProjectWorkspace::Cargo { rustc: Err(Some(e)), .. } = ws {
status.health = lsp_ext::Health::Warning;
message.push_str(e);
message.push_str("\n\n");
}
}
if let Err(_) = self.fetch_workspace_error() { if let Err(_) = self.fetch_workspace_error() {
status.health = lsp_ext::Health::Error; status.health = lsp_ext::Health::Error;
message.push_str("Failed to load workspaces\n\n"); message.push_str("Failed to load workspaces.\n\n");
} }
if !message.is_empty() { if !message.is_empty() {