diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-03-10 17:56:44 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-10 17:56:44 +0000 |
commit | e5df8c402847d5bedb8ebcb621aac46dbe215cdd (patch) | |
tree | 87f12e2619ac0074134b758ddcc1f6c1ccef863a /crates/ra_ide_db/src/feature_flags.rs | |
parent | daf3609654b6e9b2ac2808a056c61438674a1dc9 (diff) | |
parent | 14094e44770559c13a1e8bdfcfb989d3bedd00d8 (diff) |
Merge #3551
3551: Move FeatureFlags r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide_db/src/feature_flags.rs')
-rw-r--r-- | crates/ra_ide_db/src/feature_flags.rs | 73 |
1 files changed, 0 insertions, 73 deletions
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 968415072..000000000 --- a/crates/ra_ide_db/src/feature_flags.rs +++ /dev/null | |||
@@ -1,73 +0,0 @@ | |||
1 | //! See docs for `FeatureFlags`. | ||
2 | |||
3 | use rustc_hash::FxHashMap; | ||
4 | |||
5 | /// Feature flags hold fine-grained toggles for all *user-visible* features of | ||
6 | /// rust-analyzer. | ||
7 | /// | ||
8 | /// The exists such that users are able to disable any annoying feature (and, | ||
9 | /// with many users and many features, some features are bound to be annoying | ||
10 | /// for some users) | ||
11 | /// | ||
12 | /// Note that we purposefully use run-time checked strings, and not something | ||
13 | /// checked at compile time, to keep things simple and flexible. | ||
14 | /// | ||
15 | /// Also note that, at the moment, `FeatureFlags` also store features for | ||
16 | /// `rust-analyzer`. This should be benign layering violation. | ||
17 | #[derive(Debug)] | ||
18 | pub struct FeatureFlags { | ||
19 | flags: FxHashMap<String, bool>, | ||
20 | } | ||
21 | |||
22 | impl FeatureFlags { | ||
23 | fn new(flags: &[(&str, bool)]) -> FeatureFlags { | ||
24 | let flags = flags | ||
25 | .iter() | ||
26 | .map(|&(name, value)| { | ||
27 | check_flag_name(name); | ||
28 | (name.to_string(), value) | ||
29 | }) | ||
30 | .collect(); | ||
31 | FeatureFlags { flags } | ||
32 | } | ||
33 | |||
34 | pub fn set(&mut self, flag: &str, value: bool) -> Result<(), ()> { | ||
35 | match self.flags.get_mut(flag) { | ||
36 | None => Err(()), | ||
37 | Some(slot) => { | ||
38 | *slot = value; | ||
39 | Ok(()) | ||
40 | } | ||
41 | } | ||
42 | } | ||
43 | |||
44 | pub fn get(&self, flag: &str) -> bool { | ||
45 | match self.flags.get(flag) { | ||
46 | None => panic!("unknown flag: {:?}", flag), | ||
47 | Some(value) => *value, | ||
48 | } | ||
49 | } | ||
50 | } | ||
51 | |||
52 | impl Default for FeatureFlags { | ||
53 | fn default() -> FeatureFlags { | ||
54 | FeatureFlags::new(&[ | ||
55 | ("lsp.diagnostics", true), | ||
56 | ("completion.insertion.add-call-parenthesis", true), | ||
57 | ("completion.insertion.add-argument-snippets", true), | ||
58 | ("completion.enable-postfix", true), | ||
59 | ("call-info.full", true), | ||
60 | ("notifications.workspace-loaded", true), | ||
61 | ("notifications.cargo-toml-not-found", true), | ||
62 | ]) | ||
63 | } | ||
64 | } | ||
65 | |||
66 | fn check_flag_name(flag: &str) { | ||
67 | for c in flag.bytes() { | ||
68 | match c { | ||
69 | b'a'..=b'z' | b'-' | b'.' => (), | ||
70 | _ => panic!("flag name does not match conventions: {:?}", flag), | ||
71 | } | ||
72 | } | ||
73 | } | ||