File tree 8 files changed +58
-1
lines changed
8 files changed +58
-1
lines changed Original file line number Diff line number Diff line change @@ -294,6 +294,7 @@ pub struct InlayHintsConfig {
294
294
pub param_names_for_lifetime_elision_hints : bool ,
295
295
pub hide_named_constructor_hints : bool ,
296
296
pub hide_closure_initialization_hints : bool ,
297
+ pub hide_closure_parameter_hints : bool ,
297
298
pub range_exclusive_hints : bool ,
298
299
pub closure_style : ClosureStyle ,
299
300
pub max_length : Option < usize > ,
@@ -860,6 +861,7 @@ mod tests {
860
861
binding_mode_hints : false ,
861
862
hide_named_constructor_hints : false ,
862
863
hide_closure_initialization_hints : false ,
864
+ hide_closure_parameter_hints : false ,
863
865
closure_style : ClosureStyle :: ImplFn ,
864
866
param_names_for_lifetime_elision_hints : false ,
865
867
max_length : None ,
Original file line number Diff line number Diff line change @@ -36,6 +36,9 @@ pub(super) fn hints(
36
36
if it. ty( ) . is_some( ) {
37
37
return None ;
38
38
}
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
+ }
39
42
Some ( it. colon_token( ) )
40
43
} ,
41
44
ast:: LetStmt ( it) => {
@@ -949,6 +952,36 @@ fn bar(f: impl FnOnce(u8) -> u8) -> impl FnOnce(u8) -> u8 {
949
952
) ;
950
953
}
951
954
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
+
952
985
#[ test]
953
986
fn hint_truncation ( ) {
954
987
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.
2
2
//!
3
3
//! Tests live in [`bind_pat`][super::bind_pat] module.
4
4
use ide_db:: famous_defs:: FamousDefs ;
Original file line number Diff line number Diff line change @@ -154,6 +154,7 @@ impl StaticIndex<'_> {
154
154
implicit_drop_hints : false ,
155
155
hide_named_constructor_hints : false ,
156
156
hide_closure_initialization_hints : false ,
157
+ hide_closure_parameter_hints : false ,
157
158
closure_style : hir:: ClosureStyle :: ImplFn ,
158
159
param_names_for_lifetime_elision_hints : false ,
159
160
binding_mode_hints : false ,
Original file line number Diff line number Diff line change @@ -1072,6 +1072,7 @@ impl flags::AnalysisStats {
1072
1072
param_names_for_lifetime_elision_hints : true ,
1073
1073
hide_named_constructor_hints : false ,
1074
1074
hide_closure_initialization_hints : false ,
1075
+ hide_closure_parameter_hints : false ,
1075
1076
closure_style : hir:: ClosureStyle :: ImplFn ,
1076
1077
max_length : Some ( 25 ) ,
1077
1078
closing_brace_hints_min_lines : Some ( 20 ) ,
Original file line number Diff line number Diff line change @@ -208,6 +208,8 @@ config_data! {
208
208
/// Whether to hide inlay type hints for `let` statements that initialize to a closure.
209
209
/// Only applies to closures with blocks, same as `#rust-analyzer.inlayHints.closureReturnTypeHints.enable#`.
210
210
inlayHints_typeHints_hideClosureInitialization: bool = false ,
211
+ /// Whether to hide inlay parameter type hints for closures.
212
+ inlayHints_typeHints_hideClosureParameter: bool = false ,
211
213
/// Whether to hide inlay type hints for constructors.
212
214
inlayHints_typeHints_hideNamedConstructor: bool = false ,
213
215
@@ -1666,6 +1668,9 @@ impl Config {
1666
1668
hide_closure_initialization_hints : self
1667
1669
. inlayHints_typeHints_hideClosureInitialization ( )
1668
1670
. to_owned ( ) ,
1671
+ hide_closure_parameter_hints : self
1672
+ . inlayHints_typeHints_hideClosureParameter ( )
1673
+ . to_owned ( ) ,
1669
1674
closure_style : match self . inlayHints_closureStyle ( ) {
1670
1675
ClosureStyle :: ImplFn => hir:: ClosureStyle :: ImplFn ,
1671
1676
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
782
782
Only applies to closures with blocks, same as ` #rust-analyzer.inlayHints.closureReturnTypeHints.enable# ` .
783
783
784
784
785
+ ** rust-analyzer.inlayHints.typeHints.hideClosureParameter** (default: false)
786
+
787
+ Whether to hide inlay parameter type hints for closures.
788
+
789
+
785
790
** rust-analyzer.inlayHints.typeHints.hideNamedConstructor** (default: false)
786
791
787
792
Whether to hide inlay type hints for constructors.
Original file line number Diff line number Diff line change 2253
2253
}
2254
2254
}
2255
2255
},
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
+ },
2256
2266
{
2257
2267
"title" : " inlayHints" ,
2258
2268
"properties" : {
You can’t perform that action at this time.
0 commit comments