From e7bb82c3a494e08cbcd283b8292579a9cf0bb1a3 Mon Sep 17 00:00:00 2001 From: Wilco Kusee Date: Fri, 3 Jan 2020 15:04:54 +0100 Subject: [PATCH] Allow disabling Cargo.toml not found error --- crates/ra_ide/src/feature_flags.rs | 1 + crates/ra_lsp_server/src/main_loop.rs | 39 +++++++++++++++------------ crates/ra_project_model/src/lib.rs | 3 +-- docs/user/README.md | 2 ++ 4 files changed, 26 insertions(+), 19 deletions(-) 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 4336583fee..5ca37981ed 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs @@ -13,6 +13,7 @@ use lsp_types::{ClientCapabilities, NumberOrString}; use ra_cargo_watch::{CheckOptions, CheckTask}; use ra_ide::{Canceled, FeatureFlags, FileId, LibraryData, SourceRootId}; use ra_prof::profile; +use ra_project_model::WorkspaceError; use ra_vfs::{VfsTask, Watch}; use relative_path::RelativePathBuf; use rustc_hash::FxHashSet; @@ -62,6 +63,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 +92,11 @@ pub fn main_loop( Ok(workspace) => loaded_workspaces.push(workspace), Err(e) => { log::error!("loading workspace failed: {}", e); - + if let WorkspaceError::CargoTomlNotFound(_) = e { + 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 c07c54936f..2aa9270c80 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs @@ -17,12 +17,11 @@ use ra_db::{CrateGraph, CrateId, Edition, Env, FileId}; use rustc_hash::FxHashMap; use serde_json::from_reader; -use crate::workspace_error::WorkspaceError; - pub use crate::{ cargo_workspace::{CargoFeatures, CargoWorkspace, Package, Target, TargetKind}, json_project::JsonProject, sysroot::Sysroot, + workspace_error::WorkspaceError, }; #[derive(Debug, Clone)] diff --git a/docs/user/README.md b/docs/user/README.md index a4b081dbb3..8cf4b68fd8 100644 --- a/docs/user/README.md +++ b/docs/user/README.md @@ -118,6 +118,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, } ```