mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-02 12:59:12 +00:00
Merge pull request #19104 from jnyfah/some-branch
option to disable inlay Type hints for Closure parameters
This commit is contained in:
commit
039ac844f1
8 changed files with 58 additions and 1 deletions
|
|
@ -294,6 +294,7 @@ pub struct InlayHintsConfig {
|
||||||
pub param_names_for_lifetime_elision_hints: bool,
|
pub param_names_for_lifetime_elision_hints: bool,
|
||||||
pub hide_named_constructor_hints: bool,
|
pub hide_named_constructor_hints: bool,
|
||||||
pub hide_closure_initialization_hints: bool,
|
pub hide_closure_initialization_hints: bool,
|
||||||
|
pub hide_closure_parameter_hints: bool,
|
||||||
pub range_exclusive_hints: bool,
|
pub range_exclusive_hints: bool,
|
||||||
pub closure_style: ClosureStyle,
|
pub closure_style: ClosureStyle,
|
||||||
pub max_length: Option<usize>,
|
pub max_length: Option<usize>,
|
||||||
|
|
@ -860,6 +861,7 @@ mod tests {
|
||||||
binding_mode_hints: false,
|
binding_mode_hints: false,
|
||||||
hide_named_constructor_hints: false,
|
hide_named_constructor_hints: false,
|
||||||
hide_closure_initialization_hints: false,
|
hide_closure_initialization_hints: false,
|
||||||
|
hide_closure_parameter_hints: false,
|
||||||
closure_style: ClosureStyle::ImplFn,
|
closure_style: ClosureStyle::ImplFn,
|
||||||
param_names_for_lifetime_elision_hints: false,
|
param_names_for_lifetime_elision_hints: false,
|
||||||
max_length: None,
|
max_length: None,
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,9 @@ pub(super) fn hints(
|
||||||
if it.ty().is_some() {
|
if it.ty().is_some() {
|
||||||
return None;
|
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())
|
Some(it.colon_token())
|
||||||
},
|
},
|
||||||
ast::LetStmt(it) => {
|
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]
|
#[test]
|
||||||
fn hint_truncation() {
|
fn hint_truncation() {
|
||||||
check_with_config(
|
check_with_config(
|
||||||
|
|
|
||||||
|
|
@ -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.
|
//! Tests live in [`bind_pat`][super::bind_pat] module.
|
||||||
use ide_db::famous_defs::FamousDefs;
|
use ide_db::famous_defs::FamousDefs;
|
||||||
|
|
|
||||||
|
|
@ -154,6 +154,7 @@ impl StaticIndex<'_> {
|
||||||
implicit_drop_hints: false,
|
implicit_drop_hints: false,
|
||||||
hide_named_constructor_hints: false,
|
hide_named_constructor_hints: false,
|
||||||
hide_closure_initialization_hints: false,
|
hide_closure_initialization_hints: false,
|
||||||
|
hide_closure_parameter_hints: false,
|
||||||
closure_style: hir::ClosureStyle::ImplFn,
|
closure_style: hir::ClosureStyle::ImplFn,
|
||||||
param_names_for_lifetime_elision_hints: false,
|
param_names_for_lifetime_elision_hints: false,
|
||||||
binding_mode_hints: false,
|
binding_mode_hints: false,
|
||||||
|
|
|
||||||
|
|
@ -1072,6 +1072,7 @@ impl flags::AnalysisStats {
|
||||||
param_names_for_lifetime_elision_hints: true,
|
param_names_for_lifetime_elision_hints: true,
|
||||||
hide_named_constructor_hints: false,
|
hide_named_constructor_hints: false,
|
||||||
hide_closure_initialization_hints: false,
|
hide_closure_initialization_hints: false,
|
||||||
|
hide_closure_parameter_hints: false,
|
||||||
closure_style: hir::ClosureStyle::ImplFn,
|
closure_style: hir::ClosureStyle::ImplFn,
|
||||||
max_length: Some(25),
|
max_length: Some(25),
|
||||||
closing_brace_hints_min_lines: Some(20),
|
closing_brace_hints_min_lines: Some(20),
|
||||||
|
|
|
||||||
|
|
@ -208,6 +208,8 @@ config_data! {
|
||||||
/// Whether to hide inlay type hints for `let` statements that initialize to a closure.
|
/// 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#`.
|
/// Only applies to closures with blocks, same as `#rust-analyzer.inlayHints.closureReturnTypeHints.enable#`.
|
||||||
inlayHints_typeHints_hideClosureInitialization: bool = false,
|
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.
|
/// Whether to hide inlay type hints for constructors.
|
||||||
inlayHints_typeHints_hideNamedConstructor: bool = false,
|
inlayHints_typeHints_hideNamedConstructor: bool = false,
|
||||||
|
|
||||||
|
|
@ -1666,6 +1668,9 @@ impl Config {
|
||||||
hide_closure_initialization_hints: self
|
hide_closure_initialization_hints: self
|
||||||
.inlayHints_typeHints_hideClosureInitialization()
|
.inlayHints_typeHints_hideClosureInitialization()
|
||||||
.to_owned(),
|
.to_owned(),
|
||||||
|
hide_closure_parameter_hints: self
|
||||||
|
.inlayHints_typeHints_hideClosureParameter()
|
||||||
|
.to_owned(),
|
||||||
closure_style: match self.inlayHints_closureStyle() {
|
closure_style: match self.inlayHints_closureStyle() {
|
||||||
ClosureStyle::ImplFn => hir::ClosureStyle::ImplFn,
|
ClosureStyle::ImplFn => hir::ClosureStyle::ImplFn,
|
||||||
ClosureStyle::RustAnalyzer => hir::ClosureStyle::RANotation,
|
ClosureStyle::RustAnalyzer => hir::ClosureStyle::RANotation,
|
||||||
|
|
|
||||||
|
|
@ -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#`.
|
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)
|
**rust-analyzer.inlayHints.typeHints.hideNamedConstructor** (default: false)
|
||||||
|
|
||||||
Whether to hide inlay type hints for constructors.
|
Whether to hide inlay type hints for constructors.
|
||||||
|
|
|
||||||
|
|
@ -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",
|
"title": "inlayHints",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue