Merge pull request #2732 from detrumi/cargo-toml-not-found-message-toggle

Flag to hide cargo.toml not found error
This commit is contained in:
Aleksey Kladov 2020-01-09 15:16:39 +01:00 committed by GitHub
commit cf5bdf464c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 37 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

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

View file

@ -23,9 +23,19 @@ pub use crate::{
sysroot::Sysroot,
};
// FIXME use proper error enum
pub type Result<T> = ::std::result::Result<T, Box<dyn Error + Send + Sync>>;
#[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<PathBuf> {
}
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 {

View file

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