diff --git a/crates/ra_ide/src/feature_flags.rs b/crates/ra_ide/src/feature_flags.rs index de4ae513d1..85617640d6 100644 --- a/crates/ra_ide/src/feature_flags.rs +++ b/crates/ra_ide/src/feature_flags.rs @@ -56,6 +56,7 @@ impl Default for FeatureFlags { ("completion.insertion.add-call-parenthesis", true), ("completion.enable-postfix", true), ("notifications.workspace-loaded", true), + ("notifications.cargo-toml-not-found", true), ]) } } diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 047c86a3b0..7a49cad866 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs @@ -62,6 +62,22 @@ pub fn main_loop( let mut loop_state = LoopState::default(); let mut world_state = { + let feature_flags = { + let mut ff = FeatureFlags::default(); + for (flag, value) in config.feature_flags { + if ff.set(flag.as_str(), value).is_err() { + log::error!("unknown feature flag: {:?}", flag); + show_message( + req::MessageType::Error, + format!("unknown feature flag: {:?}", flag), + &connection.sender, + ); + } + } + ff + }; + log::info!("feature_flags: {:#?}", feature_flags); + // FIXME: support dynamic workspace loading. let workspaces = { let mut loaded_workspaces = Vec::new(); @@ -75,7 +91,12 @@ pub fn main_loop( Ok(workspace) => loaded_workspaces.push(workspace), Err(e) => { log::error!("loading workspace failed: {}", e); - + if let Some(ra_project_model::CargoTomlNotFoundError(_)) = e.downcast_ref() + { + if !feature_flags.get("notifications.cargo-toml-not-found") { + continue; + } + } show_message( req::MessageType::Error, format!("rust-analyzer failed to load workspace: {}", e), @@ -136,22 +157,6 @@ pub fn main_loop( } }; - let feature_flags = { - let mut ff = FeatureFlags::default(); - for (flag, value) in config.feature_flags { - if ff.set(flag.as_str(), value).is_err() { - log::error!("unknown feature flag: {:?}", flag); - show_message( - req::MessageType::Error, - format!("unknown feature flag: {:?}", flag), - &connection.sender, - ); - } - } - ff - }; - log::info!("feature_flags: {:#?}", feature_flags); - WorldState::new( ws_roots, workspaces, diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index d71b7031a8..b7f6a9b572 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs @@ -23,9 +23,19 @@ pub use crate::{ sysroot::Sysroot, }; -// FIXME use proper error enum pub type Result = ::std::result::Result>; +#[derive(Clone, PartialEq, Eq, Hash, Debug)] +pub struct CargoTomlNotFoundError(pub PathBuf); + +impl std::fmt::Display for CargoTomlNotFoundError { + fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(fmt, "can't find Cargo.toml at {}", self.0.display()) + } +} + +impl Error for CargoTomlNotFoundError {} + #[derive(Debug, Clone)] pub enum ProjectWorkspace { /// Project workspace was discovered by running `cargo metadata` and `rustc --print sysroot`. @@ -362,7 +372,7 @@ fn find_cargo_toml(path: &Path) -> Result { } curr = path.parent(); } - Err(format!("can't find Cargo.toml at {}", path.display()))? + Err(CargoTomlNotFoundError(path.to_path_buf()))? } pub fn get_rustc_cfg_options() -> CfgOptions { diff --git a/docs/user/README.md b/docs/user/README.md index 2824457223..fa202f06cc 100644 --- a/docs/user/README.md +++ b/docs/user/README.md @@ -122,6 +122,8 @@ host. "completion.enable-postfix": true, // Show notification when workspace is fully loaded "notifications.workspace-loaded": true, + // Show error when no Cargo.toml was found + "notifications.cargo-toml-not-found": true, } ```