From f7a15b5cd1df58e46066bbd27c90cb1ad7f9c316 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 6 Jan 2021 13:54:28 +0300 Subject: More maintainable config Rather than eagerly converting JSON, we losslessly keep it as is, and change the shape of user-submitted data at the last moment. This also allows us to remove a bunch of wrong Defaults --- crates/ide/src/inlay_hints.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'crates/ide/src/inlay_hints.rs') diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs index 65df7979c..fe60abfc8 100644 --- a/crates/ide/src/inlay_hints.rs +++ b/crates/ide/src/inlay_hints.rs @@ -18,12 +18,6 @@ pub struct InlayHintsConfig { pub max_length: Option, } -impl Default for InlayHintsConfig { - fn default() -> Self { - Self { type_hints: true, parameter_hints: true, chaining_hints: true, max_length: None } - } -} - #[derive(Clone, Debug, PartialEq, Eq)] pub enum InlayKind { TypeHint, @@ -433,8 +427,15 @@ mod tests { use crate::{fixture, inlay_hints::InlayHintsConfig}; + const TEST_CONFIG: InlayHintsConfig = InlayHintsConfig { + type_hints: true, + parameter_hints: true, + chaining_hints: true, + max_length: None, + }; + fn check(ra_fixture: &str) { - check_with_config(InlayHintsConfig::default(), ra_fixture); + check_with_config(TEST_CONFIG, ra_fixture); } fn check_with_config(config: InlayHintsConfig, ra_fixture: &str) { @@ -748,7 +749,7 @@ fn main() { #[test] fn hint_truncation() { check_with_config( - InlayHintsConfig { max_length: Some(8), ..Default::default() }, + InlayHintsConfig { max_length: Some(8), ..TEST_CONFIG }, r#" struct Smol(T); @@ -831,7 +832,7 @@ fn main() { #[test] fn omitted_parameters_hints_heuristics() { check_with_config( - InlayHintsConfig { max_length: Some(8), ..Default::default() }, + InlayHintsConfig { max_length: Some(8), ..TEST_CONFIG }, r#" fn map(f: i32) {} fn filter(predicate: i32) {} @@ -924,7 +925,7 @@ fn main() { #[test] fn unit_structs_have_no_type_hints() { check_with_config( - InlayHintsConfig { max_length: Some(8), ..Default::default() }, + InlayHintsConfig { max_length: Some(8), ..TEST_CONFIG }, r#" enum Result { Ok(T), Err(E) } use Result::*; -- cgit v1.2.3