Skip to content

Commit

Permalink
Merge pull request #19104 from jnyfah/some-branch
Browse files Browse the repository at this point in the history
option to disable inlay Type hints for Closure parameters
  • Loading branch information
Veykril authored Feb 7, 2025
2 parents ef05ca5 + 7d1fedc commit 039ac84
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 1 deletion.
2 changes: 2 additions & 0 deletions crates/ide/src/inlay_hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize>,
Expand Down Expand Up @@ -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,
Expand Down
33 changes: 33 additions & 0 deletions crates/ide/src/inlay_hints/bind_pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion crates/ide/src/inlay_hints/closure_captures.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 1 addition & 0 deletions crates/ide/src/static_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions crates/rust-analyzer/src/cli/analysis_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
5 changes: 5 additions & 0 deletions crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions docs/book/src/configuration_generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 039ac84

Please sign in to comment.