Skip to content

Commit d4f45d7

Browse files
Merge pull request #21203 from A4-Tacks/hide-placeholder-hints
Add config hide placeholders type hints
2 parents 98418dc + e8ee597 commit d4f45d7

File tree

7 files changed

+44
-1
lines changed

7 files changed

+44
-1
lines changed

crates/ide/src/inlay_hints.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ pub struct InlayHintsConfig<'a> {
320320
pub implied_dyn_trait_hints: bool,
321321
pub lifetime_elision_hints: LifetimeElisionHints,
322322
pub param_names_for_lifetime_elision_hints: bool,
323+
pub hide_inferred_type_hints: bool,
323324
pub hide_named_constructor_hints: bool,
324325
pub hide_closure_initialization_hints: bool,
325326
pub hide_closure_parameter_hints: bool,
@@ -900,6 +901,7 @@ mod tests {
900901
adjustment_hints_mode: AdjustmentHintsMode::Prefix,
901902
adjustment_hints_hide_outside_unsafe: false,
902903
binding_mode_hints: false,
904+
hide_inferred_type_hints: false,
903905
hide_named_constructor_hints: false,
904906
hide_closure_initialization_hints: false,
905907
hide_closure_parameter_hints: false,

crates/ide/src/inlay_hints/placeholders.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub(super) fn type_hints(
2020
display_target: DisplayTarget,
2121
placeholder: InferType,
2222
) -> Option<()> {
23-
if !config.type_hints {
23+
if !config.type_hints || config.hide_inferred_type_hints {
2424
return None;
2525
}
2626

@@ -73,4 +73,22 @@ fn foo() {
7373
"#,
7474
);
7575
}
76+
77+
#[test]
78+
fn hide_inferred_types() {
79+
check_with_config(
80+
InlayHintsConfig {
81+
type_hints: true,
82+
hide_inferred_type_hints: true,
83+
..DISABLED_CONFIG
84+
},
85+
r#"
86+
struct S<T>(T);
87+
88+
fn foo() {
89+
let t: (_, _, [_; _]) = (1_u32, S(2), [false] as _);
90+
}
91+
"#,
92+
);
93+
}
7694
}

crates/ide/src/static_index.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ impl StaticIndex<'_> {
183183
adjustment_hints_hide_outside_unsafe: false,
184184
implicit_drop_hints: false,
185185
implied_dyn_trait_hints: false,
186+
hide_inferred_type_hints: false,
186187
hide_named_constructor_hints: false,
187188
hide_closure_initialization_hints: false,
188189
hide_closure_parameter_hints: false,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,7 @@ impl flags::AnalysisStats {
12221222
implied_dyn_trait_hints: true,
12231223
lifetime_elision_hints: ide::LifetimeElisionHints::Always,
12241224
param_names_for_lifetime_elision_hints: true,
1225+
hide_inferred_type_hints: false,
12251226
hide_named_constructor_hints: false,
12261227
hide_closure_initialization_hints: false,
12271228
hide_closure_parameter_hints: false,

crates/rust-analyzer/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ config_data! {
304304
/// Hide inlay parameter type hints for closures.
305305
inlayHints_typeHints_hideClosureParameter: bool = false,
306306

307+
/// Hide inlay type hints for inferred types.
308+
inlayHints_typeHints_hideInferredTypes: bool = false,
309+
307310
/// Hide inlay type hints for constructors.
308311
inlayHints_typeHints_hideNamedConstructor: bool = false,
309312

@@ -1937,6 +1940,7 @@ impl Config {
19371940
hide_named_constructor_hints: self
19381941
.inlayHints_typeHints_hideNamedConstructor()
19391942
.to_owned(),
1943+
hide_inferred_type_hints: self.inlayHints_typeHints_hideInferredTypes().to_owned(),
19401944
hide_closure_initialization_hints: self
19411945
.inlayHints_typeHints_hideClosureInitialization()
19421946
.to_owned(),

docs/book/src/configuration_generated.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,13 @@ Default: `false`
11181118
Hide inlay parameter type hints for closures.
11191119

11201120

1121+
## rust-analyzer.inlayHints.typeHints.hideInferredTypes {#inlayHints.typeHints.hideInferredTypes}
1122+
1123+
Default: `false`
1124+
1125+
Hide inlay type hints for inferred types.
1126+
1127+
11211128
## rust-analyzer.inlayHints.typeHints.hideNamedConstructor {#inlayHints.typeHints.hideNamedConstructor}
11221129

11231130
Default: `false`

editors/code/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2466,6 +2466,16 @@
24662466
}
24672467
}
24682468
},
2469+
{
2470+
"title": "Inlay Hints",
2471+
"properties": {
2472+
"rust-analyzer.inlayHints.typeHints.hideInferredTypes": {
2473+
"markdownDescription": "Hide inlay type hints for inferred types.",
2474+
"default": false,
2475+
"type": "boolean"
2476+
}
2477+
}
2478+
},
24692479
{
24702480
"title": "Inlay Hints",
24712481
"properties": {

0 commit comments

Comments
 (0)