From bf582e77d6e5603149b355a5650cd4d15318f776 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 10 Mar 2020 18:47:09 +0100 Subject: Pull completion options up to the rust-analyzer --- crates/ra_ide_db/src/feature_flags.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'crates/ra_ide_db/src') diff --git a/crates/ra_ide_db/src/feature_flags.rs b/crates/ra_ide_db/src/feature_flags.rs index 968415072..dbb3f50a0 100644 --- a/crates/ra_ide_db/src/feature_flags.rs +++ b/crates/ra_ide_db/src/feature_flags.rs @@ -2,6 +2,10 @@ use rustc_hash::FxHashMap; +// FIXME: looks like a much better design is to pass options to each call, +// rather than to have a global ambient feature flags -- that way, the clients +// can issue two successive calls with different options. + /// Feature flags hold fine-grained toggles for all *user-visible* features of /// rust-analyzer. /// -- cgit v1.2.3 From 14094e44770559c13a1e8bdfcfb989d3bedd00d8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 10 Mar 2020 18:56:15 +0100 Subject: Move FeatureFlags --- crates/ra_ide_db/src/feature_flags.rs | 77 ----------------------------------- crates/ra_ide_db/src/lib.rs | 10 ++--- 2 files changed, 3 insertions(+), 84 deletions(-) delete mode 100644 crates/ra_ide_db/src/feature_flags.rs (limited to 'crates/ra_ide_db/src') diff --git a/crates/ra_ide_db/src/feature_flags.rs b/crates/ra_ide_db/src/feature_flags.rs deleted file mode 100644 index dbb3f50a0..000000000 --- a/crates/ra_ide_db/src/feature_flags.rs +++ /dev/null @@ -1,77 +0,0 @@ -//! See docs for `FeatureFlags`. - -use rustc_hash::FxHashMap; - -// FIXME: looks like a much better design is to pass options to each call, -// rather than to have a global ambient feature flags -- that way, the clients -// can issue two successive calls with different options. - -/// Feature flags hold fine-grained toggles for all *user-visible* features of -/// rust-analyzer. -/// -/// The exists such that users are able to disable any annoying feature (and, -/// with many users and many features, some features are bound to be annoying -/// for some users) -/// -/// Note that we purposefully use run-time checked strings, and not something -/// checked at compile time, to keep things simple and flexible. -/// -/// Also note that, at the moment, `FeatureFlags` also store features for -/// `rust-analyzer`. This should be benign layering violation. -#[derive(Debug)] -pub struct FeatureFlags { - flags: FxHashMap, -} - -impl FeatureFlags { - fn new(flags: &[(&str, bool)]) -> FeatureFlags { - let flags = flags - .iter() - .map(|&(name, value)| { - check_flag_name(name); - (name.to_string(), value) - }) - .collect(); - FeatureFlags { flags } - } - - pub fn set(&mut self, flag: &str, value: bool) -> Result<(), ()> { - match self.flags.get_mut(flag) { - None => Err(()), - Some(slot) => { - *slot = value; - Ok(()) - } - } - } - - pub fn get(&self, flag: &str) -> bool { - match self.flags.get(flag) { - None => panic!("unknown flag: {:?}", flag), - Some(value) => *value, - } - } -} - -impl Default for FeatureFlags { - fn default() -> FeatureFlags { - FeatureFlags::new(&[ - ("lsp.diagnostics", true), - ("completion.insertion.add-call-parenthesis", true), - ("completion.insertion.add-argument-snippets", true), - ("completion.enable-postfix", true), - ("call-info.full", true), - ("notifications.workspace-loaded", true), - ("notifications.cargo-toml-not-found", true), - ]) - } -} - -fn check_flag_name(flag: &str) { - for c in flag.bytes() { - match c { - b'a'..=b'z' | b'-' | b'.' => (), - _ => panic!("flag name does not match conventions: {:?}", flag), - } - } -} diff --git a/crates/ra_ide_db/src/lib.rs b/crates/ra_ide_db/src/lib.rs index a105c7556..6bcccc848 100644 --- a/crates/ra_ide_db/src/lib.rs +++ b/crates/ra_ide_db/src/lib.rs @@ -5,7 +5,6 @@ pub mod marks; pub mod line_index; pub mod line_index_utils; -pub mod feature_flags; pub mod symbol_index; pub mod change; pub mod defs; @@ -22,7 +21,7 @@ use ra_db::{ }; use rustc_hash::FxHashMap; -use crate::{feature_flags::FeatureFlags, line_index::LineIndex, symbol_index::SymbolsDatabase}; +use crate::{line_index::LineIndex, symbol_index::SymbolsDatabase}; #[salsa::database( ra_db::SourceDatabaseStorage, @@ -37,7 +36,6 @@ use crate::{feature_flags::FeatureFlags, line_index::LineIndex, symbol_index::Sy #[derive(Debug)] pub struct RootDatabase { runtime: salsa::Runtime, - pub feature_flags: Arc, pub(crate) debug_data: Arc, pub last_gc: crate::wasm_shims::Instant, pub last_gc_check: crate::wasm_shims::Instant, @@ -82,17 +80,16 @@ impl salsa::Database for RootDatabase { impl Default for RootDatabase { fn default() -> RootDatabase { - RootDatabase::new(None, FeatureFlags::default()) + RootDatabase::new(None) } } impl RootDatabase { - pub fn new(lru_capacity: Option, feature_flags: FeatureFlags) -> RootDatabase { + pub fn new(lru_capacity: Option) -> RootDatabase { let mut db = RootDatabase { runtime: salsa::Runtime::default(), last_gc: crate::wasm_shims::Instant::now(), last_gc_check: crate::wasm_shims::Instant::now(), - feature_flags: Arc::new(feature_flags), debug_data: Default::default(), }; db.set_crate_graph_with_durability(Default::default(), Durability::HIGH); @@ -112,7 +109,6 @@ impl salsa::ParallelDatabase for RootDatabase { runtime: self.runtime.snapshot(self), last_gc: self.last_gc, last_gc_check: self.last_gc_check, - feature_flags: Arc::clone(&self.feature_flags), debug_data: Arc::clone(&self.debug_data), }) } -- cgit v1.2.3