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()));
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() },
);
}

View file

@ -13,15 +13,15 @@ use crate::{
};
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(
config: CompletionConfig,
code: &str,
kind: CompletionKind,
config: &CompletionConfig,
) -> 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()
.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<CompletionItem> = get_all_completion_items(code, config)
let mut kind_completions: Vec<CompletionItem> = 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<CompletionItem> =
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<CompletionItem> {
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};
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>(T);
@ -603,7 +604,6 @@ fn main() {
let c = Smol(Smol(0u32))
//^ Smol<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<T, E> { 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>(T);
struct B<T>(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 {

View file

@ -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)
}