diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs index 5955876d4468..63039b1cd34e 100644 --- a/crates/ide/src/inlay_hints.rs +++ b/crates/ide/src/inlay_hints.rs @@ -294,6 +294,7 @@ pub struct InlayHintsConfig { pub param_names_for_lifetime_elision_hints: bool, pub hide_named_constructor_hints: bool, pub hide_closure_initialization_hints: bool, + pub hide_closure_parameter_hints: bool, pub range_exclusive_hints: bool, pub closure_style: ClosureStyle, pub max_length: Option, @@ -860,6 +861,7 @@ mod tests { binding_mode_hints: false, hide_named_constructor_hints: false, hide_closure_initialization_hints: false, + hide_closure_parameter_hints: false, closure_style: ClosureStyle::ImplFn, param_names_for_lifetime_elision_hints: false, max_length: None, diff --git a/crates/ide/src/inlay_hints/bind_pat.rs b/crates/ide/src/inlay_hints/bind_pat.rs index 01a1a4545c47..c2986a9aa662 100644 --- a/crates/ide/src/inlay_hints/bind_pat.rs +++ b/crates/ide/src/inlay_hints/bind_pat.rs @@ -36,6 +36,9 @@ pub(super) fn hints( if it.ty().is_some() { return None; } + if config.hide_closure_parameter_hints && it.syntax().ancestors().nth(2).is_none_or(|n| matches!(ast::Expr::cast(n), Some(ast::Expr::ClosureExpr(_)))) { + return None; + } Some(it.colon_token()) }, ast::LetStmt(it) => { @@ -949,6 +952,36 @@ fn bar(f: impl FnOnce(u8) -> u8) -> impl FnOnce(u8) -> u8 { ); } + #[test] + fn skip_closure_parameter_hints() { + check_with_config( + InlayHintsConfig { + type_hints: true, + hide_closure_parameter_hints: true, + ..DISABLED_CONFIG + }, + r#" +//- minicore: fn +struct Foo; +impl Foo { + fn foo(self: Self) {} + fn bar(self: &Self) {} +} +fn main() { + let closure = |x, y| x + y; + // ^^^^^^^ impl Fn(i32, i32) -> {unknown} + closure(2, 3); + let point = (10, 20); + // ^^^^^ (i32, i32) + let (x, y) = point; + // ^ i32 ^ i32 + Foo::foo(Foo); + Foo::bar(&Foo); +} +"#, + ); + } + #[test] fn hint_truncation() { check_with_config( diff --git a/crates/ide/src/inlay_hints/closure_captures.rs b/crates/ide/src/inlay_hints/closure_captures.rs index 3e91618d08e6..9b981c0a3acf 100644 --- a/crates/ide/src/inlay_hints/closure_captures.rs +++ b/crates/ide/src/inlay_hints/closure_captures.rs @@ -1,4 +1,4 @@ -//! Implementation of "closure return type" inlay hints. +//! Implementation of "closure captures" inlay hints. //! //! Tests live in [`bind_pat`][super::bind_pat] module. use ide_db::famous_defs::FamousDefs; diff --git a/crates/ide/src/static_index.rs b/crates/ide/src/static_index.rs index 3121bb7a8e31..07553a87d28f 100644 --- a/crates/ide/src/static_index.rs +++ b/crates/ide/src/static_index.rs @@ -154,6 +154,7 @@ impl StaticIndex<'_> { implicit_drop_hints: false, hide_named_constructor_hints: false, hide_closure_initialization_hints: false, + hide_closure_parameter_hints: false, closure_style: hir::ClosureStyle::ImplFn, param_names_for_lifetime_elision_hints: false, binding_mode_hints: false, diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs index cd709afe091f..4fc6180920f5 100644 --- a/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/crates/rust-analyzer/src/cli/analysis_stats.rs @@ -1072,6 +1072,7 @@ impl flags::AnalysisStats { param_names_for_lifetime_elision_hints: true, hide_named_constructor_hints: false, hide_closure_initialization_hints: false, + hide_closure_parameter_hints: false, closure_style: hir::ClosureStyle::ImplFn, max_length: Some(25), closing_brace_hints_min_lines: Some(20), diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 7656c07c9485..e915e55722bb 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -208,6 +208,8 @@ config_data! { /// Whether to hide inlay type hints for `let` statements that initialize to a closure. /// Only applies to closures with blocks, same as `#rust-analyzer.inlayHints.closureReturnTypeHints.enable#`. inlayHints_typeHints_hideClosureInitialization: bool = false, + /// Whether to hide inlay parameter type hints for closures. + inlayHints_typeHints_hideClosureParameter:bool = false, /// Whether to hide inlay type hints for constructors. inlayHints_typeHints_hideNamedConstructor: bool = false, @@ -1666,6 +1668,9 @@ impl Config { hide_closure_initialization_hints: self .inlayHints_typeHints_hideClosureInitialization() .to_owned(), + hide_closure_parameter_hints: self + .inlayHints_typeHints_hideClosureParameter() + .to_owned(), closure_style: match self.inlayHints_closureStyle() { ClosureStyle::ImplFn => hir::ClosureStyle::ImplFn, ClosureStyle::RustAnalyzer => hir::ClosureStyle::RANotation, diff --git a/docs/book/src/configuration_generated.md b/docs/book/src/configuration_generated.md index 49eb7248898e..55678926609c 100644 --- a/docs/book/src/configuration_generated.md +++ b/docs/book/src/configuration_generated.md @@ -782,6 +782,11 @@ This setting is deprecated in favor of #rust-analyzer.inlayHints.expressionAdjus Only applies to closures with blocks, same as `#rust-analyzer.inlayHints.closureReturnTypeHints.enable#`. +**rust-analyzer.inlayHints.typeHints.hideClosureParameter** (default: false) + + Whether to hide inlay parameter type hints for closures. + + **rust-analyzer.inlayHints.typeHints.hideNamedConstructor** (default: false) Whether to hide inlay type hints for constructors. diff --git a/editors/code/package.json b/editors/code/package.json index 57f4254b6899..0a6037677052 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -2253,6 +2253,16 @@ } } }, + { + "title": "inlayHints", + "properties": { + "rust-analyzer.inlayHints.typeHints.hideClosureParameter": { + "markdownDescription": "Whether to hide inlay parameter type hints for closures.", + "default": false, + "type": "boolean" + } + } + }, { "title": "inlayHints", "properties": {