Cleanup parameter_hint_heuristics inlay hints test
This commit is contained in:
parent
b0f6d8868c
commit
5f1fac44c5
@ -315,6 +315,7 @@ fn should_hide_param_name_hint(
|
|||||||
param_name: &str,
|
param_name: &str,
|
||||||
argument: &ast::Expr,
|
argument: &ast::Expr,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
|
// These are to be tested in the `parameter_hint_heuristics` test
|
||||||
// hide when:
|
// hide when:
|
||||||
// - the parameter name is a suffix of the function's name
|
// - the parameter name is a suffix of the function's name
|
||||||
// - the argument is an enum whose name is equal to the parameter
|
// - the argument is an enum whose name is equal to the parameter
|
||||||
@ -395,7 +396,7 @@ fn get_string_representation(expr: &ast::Expr) -> Option<String> {
|
|||||||
ast::Expr::MethodCallExpr(method_call_expr) => {
|
ast::Expr::MethodCallExpr(method_call_expr) => {
|
||||||
let name_ref = method_call_expr.name_ref()?;
|
let name_ref = method_call_expr.name_ref()?;
|
||||||
match name_ref.text().as_str() {
|
match name_ref.text().as_str() {
|
||||||
"clone" => method_call_expr.receiver().map(|rec| rec.to_string()),
|
"clone" | "as_ref" => method_call_expr.receiver().map(|rec| rec.to_string()),
|
||||||
name_ref => Some(name_ref.to_owned()),
|
name_ref => Some(name_ref.to_owned()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -521,6 +522,8 @@ fn main() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parameter hint tests
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn param_hints_only() {
|
fn param_hints_only() {
|
||||||
check_params(
|
check_params(
|
||||||
@ -558,6 +561,15 @@ fn main() {
|
|||||||
check_params(
|
check_params(
|
||||||
r#"
|
r#"
|
||||||
fn param_with_underscore(with_underscore: i32) -> i32 { with_underscore }
|
fn param_with_underscore(with_underscore: i32) -> i32 { with_underscore }
|
||||||
|
fn main() {
|
||||||
|
let _x = param_with_underscore(
|
||||||
|
4,
|
||||||
|
);
|
||||||
|
}"#,
|
||||||
|
);
|
||||||
|
check_params(
|
||||||
|
r#"
|
||||||
|
fn param_with_underscore(underscore: i32) -> i32 { underscore }
|
||||||
fn main() {
|
fn main() {
|
||||||
let _x = param_with_underscore(
|
let _x = param_with_underscore(
|
||||||
4,
|
4,
|
||||||
@ -583,30 +595,32 @@ fn main() {
|
|||||||
fn never_hide_param_when_multiple_params() {
|
fn never_hide_param_when_multiple_params() {
|
||||||
check_params(
|
check_params(
|
||||||
r#"
|
r#"
|
||||||
fn foo(bar: i32, baz: i32) -> i32 { bar + baz }
|
fn foo(foo: i32, bar: i32) -> i32 { bar + baz }
|
||||||
fn main() {
|
fn main() {
|
||||||
let _x = foo(
|
let _x = foo(
|
||||||
4,
|
4,
|
||||||
//^ bar
|
//^ foo
|
||||||
8,
|
8,
|
||||||
//^ baz
|
//^ bar
|
||||||
);
|
);
|
||||||
}"#,
|
}"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn hide_param_hints_for_clones() {
|
fn param_hints_look_through_as_ref_and_clone() {
|
||||||
check_params(
|
check_params(
|
||||||
r#"
|
r#"
|
||||||
fn foo(bar: i32, baz: String, qux: f32) {}
|
fn foo(bar: i32, baz: f32) {}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let bar = 3;
|
let bar = 3;
|
||||||
let baz = &"baz";
|
let baz = &"baz";
|
||||||
let fez = 1.0;
|
let fez = 1.0;
|
||||||
foo(bar.clone(), baz.clone(), fez.clone());
|
foo(bar.clone(), bar.clone());
|
||||||
//^^^^^^^^^^^ qux
|
//^^^^^^^^^^^ baz
|
||||||
|
foo(bar.as_ref(), bar.as_ref());
|
||||||
|
//^^^^^^^^^^^^ baz
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
@ -639,10 +653,10 @@ fn main() {
|
|||||||
r#"pub fn test(a: i32, b: i32) -> [i32; 2] { [a, b] }
|
r#"pub fn test(a: i32, b: i32) -> [i32; 2] { [a, b] }
|
||||||
fn main() {
|
fn main() {
|
||||||
test(
|
test(
|
||||||
0x0fab272b,
|
0xa_b,
|
||||||
//^^^^^^^^^^ a
|
//^^^^^ a
|
||||||
0x0fab272b
|
0xa_b,
|
||||||
//^^^^^^^^^^ b
|
//^^^^^ b
|
||||||
);
|
);
|
||||||
}"#,
|
}"#,
|
||||||
)
|
)
|
||||||
@ -650,7 +664,7 @@ fn main() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn function_call_parameter_hint() {
|
fn function_call_parameter_hint() {
|
||||||
check(
|
check_params(
|
||||||
r#"
|
r#"
|
||||||
enum Option<T> { None, Some(T) }
|
enum Option<T> { None, Some(T) }
|
||||||
use Option::*;
|
use Option::*;
|
||||||
@ -685,7 +699,6 @@ fn test_func(mut foo: i32, bar: i32, msg: &str, _: i32, last: i32) -> i32 {
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let not_literal = 1;
|
let not_literal = 1;
|
||||||
//^^^^^^^^^^^ i32
|
|
||||||
let _: i32 = test_func(1, 2, "hello", 3, not_literal);
|
let _: i32 = test_func(1, 2, "hello", 3, not_literal);
|
||||||
//^ foo ^ bar ^^^^^^^ msg ^^^^^^^^^^^ last
|
//^ foo ^ bar ^^^^^^^ msg ^^^^^^^^^^^ last
|
||||||
let t: Test = Test {};
|
let t: Test = Test {};
|
||||||
@ -712,97 +725,65 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn omitted_parameters_hints_heuristics() {
|
fn parameter_hint_heuristics() {
|
||||||
check_with_config(
|
check_params(
|
||||||
InlayHintsConfig { max_length: Some(8), ..TEST_CONFIG },
|
|
||||||
r#"
|
r#"
|
||||||
|
fn check(ra_fixture_thing: &str) {}
|
||||||
|
|
||||||
fn map(f: i32) {}
|
fn map(f: i32) {}
|
||||||
fn filter(predicate: i32) {}
|
fn filter(predicate: i32) {}
|
||||||
|
|
||||||
struct TestVarContainer {
|
fn strip_suffix(suffix: &str) {}
|
||||||
test_var: i32,
|
fn stripsuffix(suffix: &str) {}
|
||||||
}
|
fn same(same: u32) {}
|
||||||
|
fn same2(_same2: u32) {}
|
||||||
|
|
||||||
impl TestVarContainer {
|
|
||||||
fn test_var(&self) -> i32 {
|
|
||||||
self.test_var
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Test {}
|
|
||||||
|
|
||||||
impl Test {
|
|
||||||
fn map(self, f: i32) -> Self {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
fn filter(self, predicate: i32) -> Self {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
fn field(self, value: i32) -> Self {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
fn no_hints_expected(&self, _: i32, test_var: i32) {}
|
|
||||||
|
|
||||||
fn frob(&self, frob: bool) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Param {}
|
|
||||||
|
|
||||||
fn different_order(param: &Param) {}
|
|
||||||
fn different_order_mut(param: &mut Param) {}
|
|
||||||
fn has_underscore(_param: bool) {}
|
|
||||||
fn enum_matches_param_name(completion_kind: CompletionKind) {}
|
fn enum_matches_param_name(completion_kind: CompletionKind) {}
|
||||||
fn param_destructuring_omitted_1((a, b): (u32, u32)) {}
|
|
||||||
fn param_destructuring_omitted_2(TestVarContainer { test_var: _ }: TestVarContainer) {}
|
|
||||||
|
|
||||||
fn twiddle(twiddle: bool) {}
|
fn foo(param: u32) {}
|
||||||
fn doo(_doo: bool) {}
|
fn bar(param_eter: u32) {}
|
||||||
|
|
||||||
enum CompletionKind {
|
enum CompletionKind {
|
||||||
Keyword,
|
Keyword,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn non_ident_pat((a, b): (u32, u32)) {}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let container: TestVarContainer = TestVarContainer { test_var: 42 };
|
check("");
|
||||||
let test: Test = Test {};
|
|
||||||
|
|
||||||
map(22);
|
map(0);
|
||||||
filter(33);
|
filter(0);
|
||||||
|
|
||||||
let test_processed: Test = test.map(1).filter(2).field(3);
|
strip_suffix("");
|
||||||
|
stripsuffix("");
|
||||||
let test_var: i32 = 55;
|
//^^ suffix
|
||||||
test_processed.no_hints_expected(22, test_var);
|
same(0);
|
||||||
test_processed.no_hints_expected(33, container.test_var);
|
same2(0);
|
||||||
test_processed.no_hints_expected(44, container.test_var());
|
|
||||||
test_processed.frob(false);
|
|
||||||
|
|
||||||
twiddle(true);
|
|
||||||
doo(true);
|
|
||||||
|
|
||||||
const TWIDDLE_UPPERCASE: bool = true;
|
|
||||||
twiddle(TWIDDLE_UPPERCASE);
|
|
||||||
|
|
||||||
let mut param_begin: Param = Param {};
|
|
||||||
different_order(¶m_begin);
|
|
||||||
different_order(&mut param_begin);
|
|
||||||
|
|
||||||
let param: bool = true;
|
|
||||||
has_underscore(param);
|
|
||||||
|
|
||||||
enum_matches_param_name(CompletionKind::Keyword);
|
enum_matches_param_name(CompletionKind::Keyword);
|
||||||
|
|
||||||
let a: f64 = 7.0;
|
let param = 0;
|
||||||
let b: f64 = 4.0;
|
foo(param);
|
||||||
let _: f64 = a.div_euclid(b);
|
let param_end = 0;
|
||||||
let _: f64 = a.abs_sub(b);
|
foo(param_end);
|
||||||
|
let start_param = 0;
|
||||||
|
foo(start_param);
|
||||||
|
let param2 = 0;
|
||||||
|
foo(param2);
|
||||||
|
//^^^^^^ param
|
||||||
|
|
||||||
let range: (u32, u32) = (3, 5);
|
let param_eter = 0;
|
||||||
param_destructuring_omitted_1(range);
|
bar(param_eter);
|
||||||
param_destructuring_omitted_2(container);
|
let param_eter_end = 0;
|
||||||
|
bar(param_eter_end);
|
||||||
|
let start_param_eter = 0;
|
||||||
|
bar(start_param_eter);
|
||||||
|
let param_eter2 = 0;
|
||||||
|
bar(param_eter2);
|
||||||
|
//^^^^^^^^^^^ param_eter
|
||||||
|
|
||||||
|
non_ident_pat((0, 0));
|
||||||
}"#,
|
}"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user