Skip to content

Commit e7bb82c

Browse files
committed
Allow disabling Cargo.toml not found error
1 parent 6c321d7 commit e7bb82c

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-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
@@ -13,6 +13,7 @@ use lsp_types::{ClientCapabilities, NumberOrString};
1313
use ra_cargo_watch::{CheckOptions, CheckTask};
1414
use ra_ide::{Canceled, FeatureFlags, FileId, LibraryData, SourceRootId};
1515
use ra_prof::profile;
16+
use ra_project_model::WorkspaceError;
1617
use ra_vfs::{VfsTask, Watch};
1718
use relative_path::RelativePathBuf;
1819
use rustc_hash::FxHashSet;
@@ -62,6 +63,22 @@ pub fn main_loop(
6263

6364
let mut loop_state = LoopState::default();
6465
let mut world_state = {
66+
let feature_flags = {
67+
let mut ff = FeatureFlags::default();
68+
for (flag, value) in config.feature_flags {
69+
if ff.set(flag.as_str(), value).is_err() {
70+
log::error!("unknown feature flag: {:?}", flag);
71+
show_message(
72+
req::MessageType::Error,
73+
format!("unknown feature flag: {:?}", flag),
74+
&connection.sender,
75+
);
76+
}
77+
}
78+
ff
79+
};
80+
log::info!("feature_flags: {:#?}", feature_flags);
81+
6582
// FIXME: support dynamic workspace loading.
6683
let workspaces = {
6784
let mut loaded_workspaces = Vec::new();
@@ -75,7 +92,11 @@ pub fn main_loop(
7592
Ok(workspace) => loaded_workspaces.push(workspace),
7693
Err(e) => {
7794
log::error!("loading workspace failed: {}", e);
78-
95+
if let WorkspaceError::CargoTomlNotFound(_) = e {
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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ use ra_db::{CrateGraph, CrateId, Edition, Env, FileId};
1717
use rustc_hash::FxHashMap;
1818
use serde_json::from_reader;
1919

20-
use crate::workspace_error::WorkspaceError;
21-
2220
pub use crate::{
2321
cargo_workspace::{CargoFeatures, CargoWorkspace, Package, Target, TargetKind},
2422
json_project::JsonProject,
2523
sysroot::Sysroot,
24+
workspace_error::WorkspaceError,
2625
};
2726

2827
#[derive(Debug, Clone)]

docs/user/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ host.
118118
"completion.enable-postfix": true,
119119
// Show notification when workspace is fully loaded
120120
"notifications.workspace-loaded": true,
121+
// Show error when no Cargo.toml was found
122+
"notifications.cargo-toml-not-found": true,
121123
}
122124
```
123125

0 commit comments

Comments
 (0)