File tree Expand file tree Collapse file tree 8 files changed +58
-1
lines changed Expand file tree Collapse file tree 8 files changed +58
-1
lines changed Original file line number Diff line number Diff line change @@ -294,6 +294,7 @@ pub struct InlayHintsConfig {
294294 pub param_names_for_lifetime_elision_hints : bool ,
295295 pub hide_named_constructor_hints : bool ,
296296 pub hide_closure_initialization_hints : bool ,
297+ pub hide_closure_parameter_hints : bool ,
297298 pub range_exclusive_hints : bool ,
298299 pub closure_style : ClosureStyle ,
299300 pub max_length : Option < usize > ,
@@ -860,6 +861,7 @@ mod tests {
860861 binding_mode_hints : false ,
861862 hide_named_constructor_hints : false ,
862863 hide_closure_initialization_hints : false ,
864+ hide_closure_parameter_hints : false ,
863865 closure_style : ClosureStyle :: ImplFn ,
864866 param_names_for_lifetime_elision_hints : false ,
865867 max_length : None ,
Original file line number Diff line number Diff line change @@ -36,6 +36,9 @@ pub(super) fn hints(
3636 if it. ty( ) . is_some( ) {
3737 return None ;
3838 }
39+ if config. hide_closure_parameter_hints && it. syntax( ) . ancestors( ) . nth( 2 ) . is_none_or( |n| matches!( ast:: Expr :: cast( n) , Some ( ast:: Expr :: ClosureExpr ( _) ) ) ) {
40+ return None ;
41+ }
3942 Some ( it. colon_token( ) )
4043 } ,
4144 ast:: LetStmt ( it) => {
@@ -949,6 +952,36 @@ fn bar(f: impl FnOnce(u8) -> u8) -> impl FnOnce(u8) -> u8 {
949952 ) ;
950953 }
951954
955+ #[ test]
956+ fn skip_closure_parameter_hints ( ) {
957+ check_with_config (
958+ InlayHintsConfig {
959+ type_hints : true ,
960+ hide_closure_parameter_hints : true ,
961+ ..DISABLED_CONFIG
962+ } ,
963+ r#"
964+ //- minicore: fn
965+ struct Foo;
966+ impl Foo {
967+ fn foo(self: Self) {}
968+ fn bar(self: &Self) {}
969+ }
970+ fn main() {
971+ let closure = |x, y| x + y;
972+ // ^^^^^^^ impl Fn(i32, i32) -> {unknown}
973+ closure(2, 3);
974+ let point = (10, 20);
975+ // ^^^^^ (i32, i32)
976+ let (x, y) = point;
977+ // ^ i32 ^ i32
978+ Foo::foo(Foo);
979+ Foo::bar(&Foo);
980+ }
981+ "# ,
982+ ) ;
983+ }
984+
952985 #[ test]
953986 fn hint_truncation ( ) {
954987 check_with_config (
Original file line number Diff line number Diff line change 1- //! Implementation of "closure return type " inlay hints.
1+ //! Implementation of "closure captures " inlay hints.
22//!
33//! Tests live in [`bind_pat`][super::bind_pat] module.
44use ide_db:: famous_defs:: FamousDefs ;
Original file line number Diff line number Diff line change @@ -154,6 +154,7 @@ impl StaticIndex<'_> {
154154 implicit_drop_hints : false ,
155155 hide_named_constructor_hints : false ,
156156 hide_closure_initialization_hints : false ,
157+ hide_closure_parameter_hints : false ,
157158 closure_style : hir:: ClosureStyle :: ImplFn ,
158159 param_names_for_lifetime_elision_hints : false ,
159160 binding_mode_hints : false ,
Original file line number Diff line number Diff line change @@ -1072,6 +1072,7 @@ impl flags::AnalysisStats {
10721072 param_names_for_lifetime_elision_hints : true ,
10731073 hide_named_constructor_hints : false ,
10741074 hide_closure_initialization_hints : false ,
1075+ hide_closure_parameter_hints : false ,
10751076 closure_style : hir:: ClosureStyle :: ImplFn ,
10761077 max_length : Some ( 25 ) ,
10771078 closing_brace_hints_min_lines : Some ( 20 ) ,
Original file line number Diff line number Diff line change @@ -208,6 +208,8 @@ config_data! {
208208 /// Whether to hide inlay type hints for `let` statements that initialize to a closure.
209209 /// Only applies to closures with blocks, same as `#rust-analyzer.inlayHints.closureReturnTypeHints.enable#`.
210210 inlayHints_typeHints_hideClosureInitialization: bool = false ,
211+ /// Whether to hide inlay parameter type hints for closures.
212+ inlayHints_typeHints_hideClosureParameter: bool = false ,
211213 /// Whether to hide inlay type hints for constructors.
212214 inlayHints_typeHints_hideNamedConstructor: bool = false ,
213215
@@ -1666,6 +1668,9 @@ impl Config {
16661668 hide_closure_initialization_hints : self
16671669 . inlayHints_typeHints_hideClosureInitialization ( )
16681670 . to_owned ( ) ,
1671+ hide_closure_parameter_hints : self
1672+ . inlayHints_typeHints_hideClosureParameter ( )
1673+ . to_owned ( ) ,
16691674 closure_style : match self . inlayHints_closureStyle ( ) {
16701675 ClosureStyle :: ImplFn => hir:: ClosureStyle :: ImplFn ,
16711676 ClosureStyle :: RustAnalyzer => hir:: ClosureStyle :: RANotation ,
Original file line number Diff line number Diff line change @@ -782,6 +782,11 @@ This setting is deprecated in favor of #rust-analyzer.inlayHints.expressionAdjus
782782Only applies to closures with blocks, same as ` #rust-analyzer.inlayHints.closureReturnTypeHints.enable# ` .
783783
784784
785+ ** rust-analyzer.inlayHints.typeHints.hideClosureParameter** (default: false)
786+
787+ Whether to hide inlay parameter type hints for closures.
788+
789+
785790** rust-analyzer.inlayHints.typeHints.hideNamedConstructor** (default: false)
786791
787792 Whether to hide inlay type hints for constructors.
Original file line number Diff line number Diff line change 22532253 }
22542254 }
22552255 },
2256+ {
2257+ "title" : " inlayHints" ,
2258+ "properties" : {
2259+ "rust-analyzer.inlayHints.typeHints.hideClosureParameter" : {
2260+ "markdownDescription" : " Whether to hide inlay parameter type hints for closures." ,
2261+ "default" : false ,
2262+ "type" : " boolean"
2263+ }
2264+ }
2265+ },
22562266 {
22572267 "title" : " inlayHints" ,
22582268 "properties" : {
You can’t perform that action at this time.
0 commit comments