Allow disabling Cargo.toml not found error

This commit is contained in:
Wilco Kusee 2020-01-03 15:04:54 +01:00
parent 6c321d7318
commit e7bb82c3a4
No known key found for this signature in database
GPG key ID: D5B2BB5CDC3334BC
4 changed files with 26 additions and 19 deletions

View file

@ -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),
])
}
}

View file

@ -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,

View file

@ -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)]

View file

@ -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,
}
```