mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Merge pull request #3910 from lnicola/fn-named-param-hint
Hide parameter hints for single-argument functions with the same name
This commit is contained in:
commit
8bd14a3483
1 changed files with 12 additions and 5 deletions
|
@ -235,7 +235,10 @@ fn should_show_param_hint(
|
||||||
param_name: &str,
|
param_name: &str,
|
||||||
argument: &ast::Expr,
|
argument: &ast::Expr,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if param_name.is_empty() || is_argument_similar_to_param(argument, param_name) {
|
if param_name.is_empty()
|
||||||
|
|| is_argument_similar_to_param(argument, param_name)
|
||||||
|
|| Some(param_name) == fn_signature.name.as_ref().map(String::as_str)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,10 +250,7 @@ fn should_show_param_hint(
|
||||||
|
|
||||||
// avoid displaying hints for common functions like map, filter, etc.
|
// avoid displaying hints for common functions like map, filter, etc.
|
||||||
// or other obvious words used in std
|
// or other obvious words used in std
|
||||||
if parameters_len == 1 && is_obvious_param(param_name) {
|
parameters_len != 1 || !is_obvious_param(param_name)
|
||||||
return false;
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_argument_similar_to_param(argument: &ast::Expr, param_name: &str) -> bool {
|
fn is_argument_similar_to_param(argument: &ast::Expr, param_name: &str) -> bool {
|
||||||
|
@ -1086,6 +1086,8 @@ impl Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn no_hints_expected(&self, _: i32, test_var: i32) {}
|
fn no_hints_expected(&self, _: i32, test_var: i32) {}
|
||||||
|
|
||||||
|
fn frob(&self, frob: bool) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Param {}
|
struct Param {}
|
||||||
|
@ -1093,6 +1095,8 @@ struct Param {}
|
||||||
fn different_order(param: &Param) {}
|
fn different_order(param: &Param) {}
|
||||||
fn different_order_mut(param: &mut Param) {}
|
fn different_order_mut(param: &mut Param) {}
|
||||||
|
|
||||||
|
fn twiddle(twiddle: bool) {}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let container: TestVarContainer = TestVarContainer { test_var: 42 };
|
let container: TestVarContainer = TestVarContainer { test_var: 42 };
|
||||||
let test: Test = Test {};
|
let test: Test = Test {};
|
||||||
|
@ -1105,6 +1109,9 @@ fn main() {
|
||||||
let test_var: i32 = 55;
|
let test_var: i32 = 55;
|
||||||
test_processed.no_hints_expected(22, test_var);
|
test_processed.no_hints_expected(22, test_var);
|
||||||
test_processed.no_hints_expected(33, container.test_var);
|
test_processed.no_hints_expected(33, container.test_var);
|
||||||
|
test_processed.frob(false);
|
||||||
|
|
||||||
|
twiddle(true);
|
||||||
|
|
||||||
let param_begin: Param = Param {};
|
let param_begin: Param = Param {};
|
||||||
different_order(¶m_begin);
|
different_order(¶m_begin);
|
||||||
|
|
Loading…
Reference in a new issue