From ec95152a4ec1ed617452c8578df128a117ab0b5d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 6 Feb 2020 12:18:52 +0100 Subject: Move FeatureFlags --- crates/ra_ide/src/feature_flags.rs | 71 ------------------------------- crates/ra_ide/src/ide_db/feature_flags.rs | 71 +++++++++++++++++++++++++++++++ crates/ra_ide/src/ide_db/mod.rs | 4 +- crates/ra_ide/src/lib.rs | 3 +- 4 files changed, 74 insertions(+), 75 deletions(-) delete mode 100644 crates/ra_ide/src/feature_flags.rs create mode 100644 crates/ra_ide/src/ide_db/feature_flags.rs diff --git a/crates/ra_ide/src/feature_flags.rs b/crates/ra_ide/src/feature_flags.rs deleted file mode 100644 index 85617640d..000000000 --- a/crates/ra_ide/src/feature_flags.rs +++ /dev/null @@ -1,71 +0,0 @@ -//! FIXME: write short doc here - -use rustc_hash::FxHashMap; - -/// 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 -/// `ra_lsp_server`. 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.enable-postfix", 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/src/ide_db/feature_flags.rs b/crates/ra_ide/src/ide_db/feature_flags.rs new file mode 100644 index 000000000..85617640d --- /dev/null +++ b/crates/ra_ide/src/ide_db/feature_flags.rs @@ -0,0 +1,71 @@ +//! FIXME: write short doc here + +use rustc_hash::FxHashMap; + +/// 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 +/// `ra_lsp_server`. 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.enable-postfix", 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/src/ide_db/mod.rs b/crates/ra_ide/src/ide_db/mod.rs index cd47132ce..834ad0135 100644 --- a/crates/ra_ide/src/ide_db/mod.rs +++ b/crates/ra_ide/src/ide_db/mod.rs @@ -2,6 +2,7 @@ pub mod line_index; pub mod line_index_utils; +pub mod feature_flags; use std::sync::Arc; @@ -13,9 +14,8 @@ use ra_db::{ use rustc_hash::FxHashMap; use crate::{ - ide_db::line_index::LineIndex, + ide_db::{feature_flags::FeatureFlags, line_index::LineIndex}, symbol_index::{self, SymbolsDatabase}, - FeatureFlags, }; #[salsa::database( diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 00d608269..003a5e528 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs @@ -17,7 +17,6 @@ pub mod mock_analysis; mod symbol_index; mod change; mod source_change; -mod feature_flags; mod status; mod completion; @@ -70,10 +69,10 @@ pub use crate::{ diagnostics::Severity, display::{file_structure, FunctionSignature, NavigationTarget, StructureNode}, expand_macro::ExpandedMacro, - feature_flags::FeatureFlags, folding_ranges::{Fold, FoldKind}, hover::HoverResult, ide_db::{ + feature_flags::FeatureFlags, line_index::{LineCol, LineIndex}, line_index_utils::translate_offset_with_edit, }, -- cgit v1.2.3