From 65d9966a4f6c35b63f97c16f5f62f83a04574f3e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 9 Jul 2020 16:12:53 +0200 Subject: Always put config first --- crates/ra_ide/src/completion/presentation.rs | 4 +- crates/ra_ide/src/completion/test_utils.rs | 22 +++--- crates/ra_ide/src/inlay_hints.rs | 94 ++++++++++++------------ crates/rust-analyzer/src/diagnostics/to_proto.rs | 1 - 4 files changed, 60 insertions(+), 61 deletions(-) diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index e4c57e41a..48afee5fb 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs @@ -491,7 +491,7 @@ mod tests { } } - let mut completions = get_all_completion_items(ra_fixture, &CompletionConfig::default()); + let mut completions = get_all_completion_items(CompletionConfig::default(), ra_fixture); completions.sort_by_key(|it| (Reverse(it.score()), it.label().to_string())); let actual = completions .into_iter() @@ -835,6 +835,7 @@ fn bar(s: &S) { fn suppress_arg_snippets() { mark::check!(suppress_arg_snippets); check_edit_with_config( + CompletionConfig { add_call_argument_snippets: false, ..CompletionConfig::default() }, "with_args", r#" fn with_args(x: i32, y: String) {} @@ -844,7 +845,6 @@ fn main() { with_<|> } fn with_args(x: i32, y: String) {} fn main() { with_args($0) } "#, - &CompletionConfig { add_call_argument_snippets: false, ..CompletionConfig::default() }, ); } diff --git a/crates/ra_ide/src/completion/test_utils.rs b/crates/ra_ide/src/completion/test_utils.rs index c2be23697..919177745 100644 --- a/crates/ra_ide/src/completion/test_utils.rs +++ b/crates/ra_ide/src/completion/test_utils.rs @@ -13,15 +13,15 @@ use crate::{ }; pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec { - do_completion_with_config(code, kind, &CompletionConfig::default()) + do_completion_with_config(CompletionConfig::default(), code, kind) } pub(crate) fn do_completion_with_config( + config: CompletionConfig, code: &str, kind: CompletionKind, - config: &CompletionConfig, ) -> Vec { - let mut kind_completions: Vec = get_all_completion_items(code, config) + let mut kind_completions: Vec = get_all_completion_items(config, code) .into_iter() .filter(|c| c.completion_kind == kind) .collect(); @@ -30,15 +30,15 @@ pub(crate) fn do_completion_with_config( } pub(crate) fn completion_list(code: &str, kind: CompletionKind) -> String { - completion_list_with_config(code, kind, &CompletionConfig::default()) + completion_list_with_config(CompletionConfig::default(), code, kind) } pub(crate) fn completion_list_with_config( + config: CompletionConfig, code: &str, kind: CompletionKind, - config: &CompletionConfig, ) -> String { - let mut kind_completions: Vec = get_all_completion_items(code, config) + let mut kind_completions: Vec = get_all_completion_items(config, code) .into_iter() .filter(|c| c.completion_kind == kind) .collect(); @@ -70,19 +70,19 @@ fn monospace_width(s: &str) -> usize { } pub(crate) fn check_edit(what: &str, ra_fixture_before: &str, ra_fixture_after: &str) { - check_edit_with_config(what, ra_fixture_before, ra_fixture_after, &CompletionConfig::default()) + check_edit_with_config(CompletionConfig::default(), what, ra_fixture_before, ra_fixture_after) } pub(crate) fn check_edit_with_config( + config: CompletionConfig, what: &str, ra_fixture_before: &str, ra_fixture_after: &str, - config: &CompletionConfig, ) { let ra_fixture_after = trim_indent(ra_fixture_after); let (analysis, position) = analysis_and_position(ra_fixture_before); let completions: Vec = - analysis.completions(config, position).unwrap().unwrap().into(); + analysis.completions(&config, position).unwrap().unwrap().into(); let (completion,) = completions .iter() .filter(|it| it.lookup() == what) @@ -106,9 +106,9 @@ pub(crate) fn check_pattern_is_applicable(code: &str, check: fn(SyntaxElement) - } pub(crate) fn get_all_completion_items( + config: CompletionConfig, code: &str, - options: &CompletionConfig, ) -> Vec { let (analysis, position) = analysis_and_position(code); - analysis.completions(options, position).unwrap().unwrap().into() + analysis.completions(&config, position).unwrap().unwrap().into() } diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 62d364bfa..35ab741d8 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs @@ -351,10 +351,10 @@ mod tests { use crate::{inlay_hints::InlayHintsConfig, mock_analysis::single_file}; fn check(ra_fixture: &str) { - check_with_config(ra_fixture, InlayHintsConfig::default()); + check_with_config(InlayHintsConfig::default(), ra_fixture); } - fn check_with_config(ra_fixture: &str, config: InlayHintsConfig) { + fn check_with_config(config: InlayHintsConfig, ra_fixture: &str) { let (analysis, file_id) = single_file(ra_fixture); let expected = extract_annotations(&*analysis.file_text(file_id).unwrap()); let inlay_hints = analysis.inlay_hints(file_id, &config).unwrap(); @@ -363,7 +363,7 @@ mod tests { assert_eq!(expected, actual); } - fn check_expect(ra_fixture: &str, config: InlayHintsConfig, expect: Expect) { + fn check_expect(config: InlayHintsConfig, ra_fixture: &str, expect: Expect) { let (analysis, file_id) = single_file(ra_fixture); let inlay_hints = analysis.inlay_hints(file_id, &config).unwrap(); expect.assert_debug_eq(&inlay_hints) @@ -372,6 +372,12 @@ mod tests { #[test] fn param_hints_only() { check_with_config( + InlayHintsConfig { + parameter_hints: true, + type_hints: false, + chaining_hints: false, + max_length: None, + }, r#" fn foo(a: i32, b: i32) -> i32 { a + b } fn main() { @@ -382,47 +388,41 @@ fn main() { //^ b ); }"#, - InlayHintsConfig { - parameter_hints: true, - type_hints: false, - chaining_hints: false, - max_length: None, - }, ); } #[test] fn hints_disabled() { check_with_config( - r#" -fn foo(a: i32, b: i32) -> i32 { a + b } -fn main() { - let _x = foo(4, 4); -}"#, InlayHintsConfig { type_hints: false, parameter_hints: false, chaining_hints: false, max_length: None, }, + r#" +fn foo(a: i32, b: i32) -> i32 { a + b } +fn main() { + let _x = foo(4, 4); +}"#, ); } #[test] fn type_hints_only() { check_with_config( - r#" -fn foo(a: i32, b: i32) -> i32 { a + b } -fn main() { - let _x = foo(4, 4); - //^^ i32 -}"#, InlayHintsConfig { type_hints: true, parameter_hints: false, chaining_hints: false, max_length: None, }, + r#" +fn foo(a: i32, b: i32) -> i32 { a + b } +fn main() { + let _x = foo(4, 4); + //^^ i32 +}"#, ); } @@ -590,6 +590,7 @@ fn main() { #[test] fn hint_truncation() { check_with_config( + InlayHintsConfig { max_length: Some(8), ..Default::default() }, r#" struct Smol(T); @@ -603,7 +604,6 @@ fn main() { let c = Smol(Smol(0u32)) //^ Smol> }"#, - InlayHintsConfig { max_length: Some(8), ..Default::default() }, ); } @@ -673,6 +673,7 @@ fn main() { #[test] fn omitted_parameters_hints_heuristics() { check_with_config( + InlayHintsConfig { max_length: Some(8), ..Default::default() }, r#" fn map(f: i32) {} fn filter(predicate: i32) {} @@ -753,13 +754,13 @@ fn main() { let _: f64 = a.div_euclid(b); let _: f64 = a.abs_sub(b); }"#, - InlayHintsConfig { max_length: Some(8), ..Default::default() }, ); } #[test] fn unit_structs_have_no_type_hints() { check_with_config( + InlayHintsConfig { max_length: Some(8), ..Default::default() }, r#" enum Result { Ok(T), Err(E) } use Result::*; @@ -772,13 +773,18 @@ fn main() { Err(SyntheticSyntax) => (), } }"#, - InlayHintsConfig { max_length: Some(8), ..Default::default() }, ); } #[test] fn chaining_hints_ignore_comments() { check_expect( + InlayHintsConfig { + parameter_hints: false, + type_hints: false, + chaining_hints: true, + max_length: None, + }, r#" struct A(B); impl A { fn into_b(self) -> B { self.0 } } @@ -792,12 +798,6 @@ fn main() { .into_c(); } "#, - InlayHintsConfig { - parameter_hints: false, - type_hints: false, - chaining_hints: true, - max_length: None, - }, expect![[r#" [ InlayHint { @@ -818,6 +818,12 @@ fn main() { #[test] fn chaining_hints_without_newlines() { check_with_config( + InlayHintsConfig { + parameter_hints: false, + type_hints: false, + chaining_hints: true, + max_length: None, + }, r#" struct A(B); impl A { fn into_b(self) -> B { self.0 } } @@ -828,18 +834,18 @@ struct C; fn main() { let c = A(B(C)).into_b().into_c(); }"#, - InlayHintsConfig { - parameter_hints: false, - type_hints: false, - chaining_hints: true, - max_length: None, - }, ); } #[test] fn struct_access_chaining_hints() { check_expect( + InlayHintsConfig { + parameter_hints: false, + type_hints: false, + chaining_hints: true, + max_length: None, + }, r#" struct A { pub b: B } struct B { pub c: C } @@ -858,12 +864,6 @@ fn main() { let x = D .foo(); }"#, - InlayHintsConfig { - parameter_hints: false, - type_hints: false, - chaining_hints: true, - max_length: None, - }, expect![[r#" [ InlayHint { @@ -884,6 +884,12 @@ fn main() { #[test] fn generic_chaining_hints() { check_expect( + InlayHintsConfig { + parameter_hints: false, + type_hints: false, + chaining_hints: true, + max_length: None, + }, r#" struct A(T); struct B(T); @@ -903,12 +909,6 @@ fn main() { .into_c(); } "#, - InlayHintsConfig { - parameter_hints: false, - type_hints: false, - chaining_hints: true, - max_length: None, - }, expect![[r#" [ InlayHint { diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs index 808a23b17..b1b222deb 100644 --- a/crates/rust-analyzer/src/diagnostics/to_proto.rs +++ b/crates/rust-analyzer/src/diagnostics/to_proto.rs @@ -258,7 +258,6 @@ mod tests { use expect::{expect_file, ExpectFile}; - // TODO: inlay hints config order fn check(diagnostics_json: &str, expect: ExpectFile) { check_with_config(DiagnosticsConfig::default(), diagnostics_json, expect) } -- cgit v1.2.3