mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
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:
commit
cf5bdf464c
4 changed files with 37 additions and 19 deletions
|
@ -56,6 +56,7 @@ impl Default for FeatureFlags {
|
||||||
("completion.insertion.add-call-parenthesis", true),
|
("completion.insertion.add-call-parenthesis", true),
|
||||||
("completion.enable-postfix", true),
|
("completion.enable-postfix", true),
|
||||||
("notifications.workspace-loaded", true),
|
("notifications.workspace-loaded", true),
|
||||||
|
("notifications.cargo-toml-not-found", true),
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,22 @@ pub fn main_loop(
|
||||||
|
|
||||||
let mut loop_state = LoopState::default();
|
let mut loop_state = LoopState::default();
|
||||||
let mut world_state = {
|
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.
|
// FIXME: support dynamic workspace loading.
|
||||||
let workspaces = {
|
let workspaces = {
|
||||||
let mut loaded_workspaces = Vec::new();
|
let mut loaded_workspaces = Vec::new();
|
||||||
|
@ -75,7 +91,12 @@ pub fn main_loop(
|
||||||
Ok(workspace) => loaded_workspaces.push(workspace),
|
Ok(workspace) => loaded_workspaces.push(workspace),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("loading workspace failed: {}", 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(
|
show_message(
|
||||||
req::MessageType::Error,
|
req::MessageType::Error,
|
||||||
format!("rust-analyzer failed to load workspace: {}", e),
|
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(
|
WorldState::new(
|
||||||
ws_roots,
|
ws_roots,
|
||||||
workspaces,
|
workspaces,
|
||||||
|
|
|
@ -23,9 +23,19 @@ pub use crate::{
|
||||||
sysroot::Sysroot,
|
sysroot::Sysroot,
|
||||||
};
|
};
|
||||||
|
|
||||||
// FIXME use proper error enum
|
|
||||||
pub type Result<T> = ::std::result::Result<T, Box<dyn Error + Send + Sync>>;
|
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)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum ProjectWorkspace {
|
pub enum ProjectWorkspace {
|
||||||
/// Project workspace was discovered by running `cargo metadata` and `rustc --print sysroot`.
|
/// 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();
|
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 {
|
pub fn get_rustc_cfg_options() -> CfgOptions {
|
||||||
|
|
|
@ -122,6 +122,8 @@ host.
|
||||||
"completion.enable-postfix": true,
|
"completion.enable-postfix": true,
|
||||||
// Show notification when workspace is fully loaded
|
// Show notification when workspace is fully loaded
|
||||||
"notifications.workspace-loaded": true,
|
"notifications.workspace-loaded": true,
|
||||||
|
// Show error when no Cargo.toml was found
|
||||||
|
"notifications.cargo-toml-not-found": true,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue