Skip to content

Commit cf5bdf4

Browse files
authored
Merge pull request #2732 from detrumi/cargo-toml-not-found-message-toggle
Flag to hide cargo.toml not found error
2 parents 3263c70 + 11caebe commit cf5bdf4

File tree

4 files changed

+37
-19
lines changed

4 files changed

+37
-19
lines changed

crates/ra_ide/src/feature_flags.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ impl Default for FeatureFlags {
5656
("completion.insertion.add-call-parenthesis", true),
5757
("completion.enable-postfix", true),
5858
("notifications.workspace-loaded", true),
59+
("notifications.cargo-toml-not-found", true),
5960
])
6061
}
6162
}

crates/ra_lsp_server/src/main_loop.rs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,22 @@ pub fn main_loop(
6262

6363
let mut loop_state = LoopState::default();
6464
let mut world_state = {
65+
let feature_flags = {
66+
let mut ff = FeatureFlags::default();
67+
for (flag, value) in config.feature_flags {
68+
if ff.set(flag.as_str(), value).is_err() {
69+
log::error!("unknown feature flag: {:?}", flag);
70+
show_message(
71+
req::MessageType::Error,
72+
format!("unknown feature flag: {:?}", flag),
73+
&connection.sender,
74+
);
75+
}
76+
}
77+
ff
78+
};
79+
log::info!("feature_flags: {:#?}", feature_flags);
80+
6581
// FIXME: support dynamic workspace loading.
6682
let workspaces = {
6783
let mut loaded_workspaces = Vec::new();
@@ -75,7 +91,12 @@ pub fn main_loop(
7591
Ok(workspace) => loaded_workspaces.push(workspace),
7692
Err(e) => {
7793
log::error!("loading workspace failed: {}", e);
78-
94+
if let Some(ra_project_model::CargoTomlNotFoundError(_)) = e.downcast_ref()
95+
{
96+
if !feature_flags.get("notifications.cargo-toml-not-found") {
97+
continue;
98+
}
99+
}
79100
show_message(
80101
req::MessageType::Error,
81102
format!("rust-analyzer failed to load workspace: {}", e),
@@ -136,22 +157,6 @@ pub fn main_loop(
136157
}
137158
};
138159

139-
let feature_flags = {
140-
let mut ff = FeatureFlags::default();
141-
for (flag, value) in config.feature_flags {
142-
if ff.set(flag.as_str(), value).is_err() {
143-
log::error!("unknown feature flag: {:?}", flag);
144-
show_message(
145-
req::MessageType::Error,
146-
format!("unknown feature flag: {:?}", flag),
147-
&connection.sender,
148-
);
149-
}
150-
}
151-
ff
152-
};
153-
log::info!("feature_flags: {:#?}", feature_flags);
154-
155160
WorldState::new(
156161
ws_roots,
157162
workspaces,

crates/ra_project_model/src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,19 @@ pub use crate::{
2323
sysroot::Sysroot,
2424
};
2525

26-
// FIXME use proper error enum
2726
pub type Result<T> = ::std::result::Result<T, Box<dyn Error + Send + Sync>>;
2827

28+
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
29+
pub struct CargoTomlNotFoundError(pub PathBuf);
30+
31+
impl std::fmt::Display for CargoTomlNotFoundError {
32+
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33+
write!(fmt, "can't find Cargo.toml at {}", self.0.display())
34+
}
35+
}
36+
37+
impl Error for CargoTomlNotFoundError {}
38+
2939
#[derive(Debug, Clone)]
3040
pub enum ProjectWorkspace {
3141
/// Project workspace was discovered by running `cargo metadata` and `rustc --print sysroot`.
@@ -362,7 +372,7 @@ fn find_cargo_toml(path: &Path) -> Result<PathBuf> {
362372
}
363373
curr = path.parent();
364374
}
365-
Err(format!("can't find Cargo.toml at {}", path.display()))?
375+
Err(CargoTomlNotFoundError(path.to_path_buf()))?
366376
}
367377

368378
pub fn get_rustc_cfg_options() -> CfgOptions {

docs/user/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ host.
122122
"completion.enable-postfix": true,
123123
// Show notification when workspace is fully loaded
124124
"notifications.workspace-loaded": true,
125+
// Show error when no Cargo.toml was found
126+
"notifications.cargo-toml-not-found": true,
125127
}
126128
```
127129

0 commit comments

Comments
 (0)