Skip to content

Commit 98b16ea

Browse files
committed
closure parameter inlay hints
1 parent d18dd4d commit 98b16ea

File tree

8 files changed

+60
-1
lines changed

8 files changed

+60
-1
lines changed

src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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,

src/tools/rust-analyzer/crates/ide/src/inlay_hints/bind_pat.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ pub(super) fn hints(
3636
if it.ty().is_some() {
3737
return None;
3838
}
39+
if config.hide_closure_parameter_hints {
40+
if it.syntax().ancestors().any(|n| matches!(ast::Expr::cast(n), Some(ast::Expr::ClosureExpr(_)))) {
41+
return None;
42+
}
43+
}
3944
Some(it.colon_token())
4045
},
4146
ast::LetStmt(it) => {
@@ -949,6 +954,36 @@ fn bar(f: impl FnOnce(u8) -> u8) -> impl FnOnce(u8) -> u8 {
949954
);
950955
}
951956

957+
#[test]
958+
fn skip_closure_parameter_hints() {
959+
check_with_config(
960+
InlayHintsConfig {
961+
type_hints: true,
962+
hide_closure_parameter_hints: true,
963+
..DISABLED_CONFIG
964+
},
965+
r#"
966+
//- minicore: fn
967+
struct Foo;
968+
impl Foo {
969+
fn foo(self: Self) {}
970+
fn bar(self: &Self) {}
971+
}
972+
fn main() {
973+
let closure = |x, y| x + y;
974+
// ^^^^^^^ impl Fn(i32, i32) -> {unknown}
975+
closure(2, 3);
976+
let point = (10, 20);
977+
// ^^^^^ (i32, i32)
978+
let (x, y) = point;
979+
// ^ i32 ^ i32
980+
Foo::foo(Foo);
981+
Foo::bar(&Foo);
982+
}
983+
"#,
984+
);
985+
}
986+
952987
#[test]
953988
fn hint_truncation() {
954989
check_with_config(

src/tools/rust-analyzer/crates/ide/src/inlay_hints/closure_captures.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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.
44
use ide_db::famous_defs::FamousDefs;

src/tools/rust-analyzer/crates/ide/src/static_index.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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,

src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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),

src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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,

src/tools/rust-analyzer/docs/book/src/configuration_generated.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,11 @@ This setting is deprecated in favor of #rust-analyzer.inlayHints.expressionAdjus
782782
Only 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.

src/tools/rust-analyzer/editors/code/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,6 +2253,16 @@
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": {

0 commit comments

Comments
 (0)