Always put config first

This commit is contained in:
Aleksey Kladov 2020-07-09 16:12:53 +02:00
parent e075e6eef2
commit 65d9966a4f
4 changed files with 60 additions and 61 deletions

View file

@ -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())); completions.sort_by_key(|it| (Reverse(it.score()), it.label().to_string()));
let actual = completions let actual = completions
.into_iter() .into_iter()
@ -835,6 +835,7 @@ fn bar(s: &S) {
fn suppress_arg_snippets() { fn suppress_arg_snippets() {
mark::check!(suppress_arg_snippets); mark::check!(suppress_arg_snippets);
check_edit_with_config( check_edit_with_config(
CompletionConfig { add_call_argument_snippets: false, ..CompletionConfig::default() },
"with_args", "with_args",
r#" r#"
fn with_args(x: i32, y: String) {} fn with_args(x: i32, y: String) {}
@ -844,7 +845,6 @@ fn main() { with_<|> }
fn with_args(x: i32, y: String) {} fn with_args(x: i32, y: String) {}
fn main() { with_args($0) } fn main() { with_args($0) }
"#, "#,
&CompletionConfig { add_call_argument_snippets: false, ..CompletionConfig::default() },
); );
} }

View file

@ -13,15 +13,15 @@ use crate::{
}; };
pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec<CompletionItem> { pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec<CompletionItem> {
do_completion_with_config(code, kind, &CompletionConfig::default()) do_completion_with_config(CompletionConfig::default(), code, kind)
} }
pub(crate) fn do_completion_with_config( pub(crate) fn do_completion_with_config(
config: CompletionConfig,
code: &str, code: &str,
kind: CompletionKind, kind: CompletionKind,
config: &CompletionConfig,
) -> Vec<CompletionItem> { ) -> Vec<CompletionItem> {
let mut kind_completions: Vec<CompletionItem> = get_all_completion_items(code, config) let mut kind_completions: Vec<CompletionItem> = get_all_completion_items(config, code)
.into_iter() .into_iter()
.filter(|c| c.completion_kind == kind) .filter(|c| c.completion_kind == kind)
.collect(); .collect();
@ -30,15 +30,15 @@ pub(crate) fn do_completion_with_config(
} }
pub(crate) fn completion_list(code: &str, kind: CompletionKind) -> String { 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( pub(crate) fn completion_list_with_config(
config: CompletionConfig,
code: &str, code: &str,
kind: CompletionKind, kind: CompletionKind,
config: &CompletionConfig,
) -> String { ) -> String {
let mut kind_completions: Vec<CompletionItem> = get_all_completion_items(code, config) let mut kind_completions: Vec<CompletionItem> = get_all_completion_items(config, code)
.into_iter() .into_iter()
.filter(|c| c.completion_kind == kind) .filter(|c| c.completion_kind == kind)
.collect(); .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) { 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( pub(crate) fn check_edit_with_config(
config: CompletionConfig,
what: &str, what: &str,
ra_fixture_before: &str, ra_fixture_before: &str,
ra_fixture_after: &str, ra_fixture_after: &str,
config: &CompletionConfig,
) { ) {
let ra_fixture_after = trim_indent(ra_fixture_after); let ra_fixture_after = trim_indent(ra_fixture_after);
let (analysis, position) = analysis_and_position(ra_fixture_before); let (analysis, position) = analysis_and_position(ra_fixture_before);
let completions: Vec<CompletionItem> = let completions: Vec<CompletionItem> =
analysis.completions(config, position).unwrap().unwrap().into(); analysis.completions(&config, position).unwrap().unwrap().into();
let (completion,) = completions let (completion,) = completions
.iter() .iter()
.filter(|it| it.lookup() == what) .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( pub(crate) fn get_all_completion_items(
config: CompletionConfig,
code: &str, code: &str,
options: &CompletionConfig,
) -> Vec<CompletionItem> { ) -> Vec<CompletionItem> {
let (analysis, position) = analysis_and_position(code); let (analysis, position) = analysis_and_position(code);
analysis.completions(options, position).unwrap().unwrap().into() analysis.completions(&config, position).unwrap().unwrap().into()
} }

View file

@ -351,10 +351,10 @@ mod tests {
use crate::{inlay_hints::InlayHintsConfig, mock_analysis::single_file}; use crate::{inlay_hints::InlayHintsConfig, mock_analysis::single_file};
fn check(ra_fixture: &str) { 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 (analysis, file_id) = single_file(ra_fixture);
let expected = extract_annotations(&*analysis.file_text(file_id).unwrap()); let expected = extract_annotations(&*analysis.file_text(file_id).unwrap());
let inlay_hints = analysis.inlay_hints(file_id, &config).unwrap(); let inlay_hints = analysis.inlay_hints(file_id, &config).unwrap();
@ -363,7 +363,7 @@ mod tests {
assert_eq!(expected, actual); 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 (analysis, file_id) = single_file(ra_fixture);
let inlay_hints = analysis.inlay_hints(file_id, &config).unwrap(); let inlay_hints = analysis.inlay_hints(file_id, &config).unwrap();
expect.assert_debug_eq(&inlay_hints) expect.assert_debug_eq(&inlay_hints)
@ -372,6 +372,12 @@ mod tests {
#[test] #[test]
fn param_hints_only() { fn param_hints_only() {
check_with_config( check_with_config(
InlayHintsConfig {
parameter_hints: true,
type_hints: false,
chaining_hints: false,
max_length: None,
},
r#" r#"
fn foo(a: i32, b: i32) -> i32 { a + b } fn foo(a: i32, b: i32) -> i32 { a + b }
fn main() { fn main() {
@ -382,47 +388,41 @@ fn main() {
//^ b //^ b
); );
}"#, }"#,
InlayHintsConfig {
parameter_hints: true,
type_hints: false,
chaining_hints: false,
max_length: None,
},
); );
} }
#[test] #[test]
fn hints_disabled() { fn hints_disabled() {
check_with_config( check_with_config(
r#"
fn foo(a: i32, b: i32) -> i32 { a + b }
fn main() {
let _x = foo(4, 4);
}"#,
InlayHintsConfig { InlayHintsConfig {
type_hints: false, type_hints: false,
parameter_hints: false, parameter_hints: false,
chaining_hints: false, chaining_hints: false,
max_length: None, max_length: None,
}, },
r#"
fn foo(a: i32, b: i32) -> i32 { a + b }
fn main() {
let _x = foo(4, 4);
}"#,
); );
} }
#[test] #[test]
fn type_hints_only() { fn type_hints_only() {
check_with_config( check_with_config(
r#"
fn foo(a: i32, b: i32) -> i32 { a + b }
fn main() {
let _x = foo(4, 4);
//^^ i32
}"#,
InlayHintsConfig { InlayHintsConfig {
type_hints: true, type_hints: true,
parameter_hints: false, parameter_hints: false,
chaining_hints: false, chaining_hints: false,
max_length: None, 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] #[test]
fn hint_truncation() { fn hint_truncation() {
check_with_config( check_with_config(
InlayHintsConfig { max_length: Some(8), ..Default::default() },
r#" r#"
struct Smol<T>(T); struct Smol<T>(T);
@ -603,7 +604,6 @@ fn main() {
let c = Smol(Smol(0u32)) let c = Smol(Smol(0u32))
//^ Smol<Smol<…>> //^ Smol<Smol<…>>
}"#, }"#,
InlayHintsConfig { max_length: Some(8), ..Default::default() },
); );
} }
@ -673,6 +673,7 @@ fn main() {
#[test] #[test]
fn omitted_parameters_hints_heuristics() { fn omitted_parameters_hints_heuristics() {
check_with_config( check_with_config(
InlayHintsConfig { max_length: Some(8), ..Default::default() },
r#" r#"
fn map(f: i32) {} fn map(f: i32) {}
fn filter(predicate: i32) {} fn filter(predicate: i32) {}
@ -753,13 +754,13 @@ fn main() {
let _: f64 = a.div_euclid(b); let _: f64 = a.div_euclid(b);
let _: f64 = a.abs_sub(b); let _: f64 = a.abs_sub(b);
}"#, }"#,
InlayHintsConfig { max_length: Some(8), ..Default::default() },
); );
} }
#[test] #[test]
fn unit_structs_have_no_type_hints() { fn unit_structs_have_no_type_hints() {
check_with_config( check_with_config(
InlayHintsConfig { max_length: Some(8), ..Default::default() },
r#" r#"
enum Result<T, E> { Ok(T), Err(E) } enum Result<T, E> { Ok(T), Err(E) }
use Result::*; use Result::*;
@ -772,13 +773,18 @@ fn main() {
Err(SyntheticSyntax) => (), Err(SyntheticSyntax) => (),
} }
}"#, }"#,
InlayHintsConfig { max_length: Some(8), ..Default::default() },
); );
} }
#[test] #[test]
fn chaining_hints_ignore_comments() { fn chaining_hints_ignore_comments() {
check_expect( check_expect(
InlayHintsConfig {
parameter_hints: false,
type_hints: false,
chaining_hints: true,
max_length: None,
},
r#" r#"
struct A(B); struct A(B);
impl A { fn into_b(self) -> B { self.0 } } impl A { fn into_b(self) -> B { self.0 } }
@ -792,12 +798,6 @@ fn main() {
.into_c(); .into_c();
} }
"#, "#,
InlayHintsConfig {
parameter_hints: false,
type_hints: false,
chaining_hints: true,
max_length: None,
},
expect![[r#" expect![[r#"
[ [
InlayHint { InlayHint {
@ -818,6 +818,12 @@ fn main() {
#[test] #[test]
fn chaining_hints_without_newlines() { fn chaining_hints_without_newlines() {
check_with_config( check_with_config(
InlayHintsConfig {
parameter_hints: false,
type_hints: false,
chaining_hints: true,
max_length: None,
},
r#" r#"
struct A(B); struct A(B);
impl A { fn into_b(self) -> B { self.0 } } impl A { fn into_b(self) -> B { self.0 } }
@ -828,18 +834,18 @@ struct C;
fn main() { fn main() {
let c = A(B(C)).into_b().into_c(); let c = A(B(C)).into_b().into_c();
}"#, }"#,
InlayHintsConfig {
parameter_hints: false,
type_hints: false,
chaining_hints: true,
max_length: None,
},
); );
} }
#[test] #[test]
fn struct_access_chaining_hints() { fn struct_access_chaining_hints() {
check_expect( check_expect(
InlayHintsConfig {
parameter_hints: false,
type_hints: false,
chaining_hints: true,
max_length: None,
},
r#" r#"
struct A { pub b: B } struct A { pub b: B }
struct B { pub c: C } struct B { pub c: C }
@ -858,12 +864,6 @@ fn main() {
let x = D let x = D
.foo(); .foo();
}"#, }"#,
InlayHintsConfig {
parameter_hints: false,
type_hints: false,
chaining_hints: true,
max_length: None,
},
expect![[r#" expect![[r#"
[ [
InlayHint { InlayHint {
@ -884,6 +884,12 @@ fn main() {
#[test] #[test]
fn generic_chaining_hints() { fn generic_chaining_hints() {
check_expect( check_expect(
InlayHintsConfig {
parameter_hints: false,
type_hints: false,
chaining_hints: true,
max_length: None,
},
r#" r#"
struct A<T>(T); struct A<T>(T);
struct B<T>(T); struct B<T>(T);
@ -903,12 +909,6 @@ fn main() {
.into_c(); .into_c();
} }
"#, "#,
InlayHintsConfig {
parameter_hints: false,
type_hints: false,
chaining_hints: true,
max_length: None,
},
expect![[r#" expect![[r#"
[ [
InlayHint { InlayHint {

View file

@ -258,7 +258,6 @@ mod tests {
use expect::{expect_file, ExpectFile}; use expect::{expect_file, ExpectFile};
// TODO: inlay hints config order
fn check(diagnostics_json: &str, expect: ExpectFile) { fn check(diagnostics_json: &str, expect: ExpectFile) {
check_with_config(DiagnosticsConfig::default(), diagnostics_json, expect) check_with_config(DiagnosticsConfig::default(), diagnostics_json, expect)
} }