Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #21203 from A4-Tacks/hide-placeholder-hints
Add config hide placeholders type hints
Chayim Refael Friedman 5 months ago
parent 98418dc · parent e8ee597 · commit d4f45d7
-rw-r--r--crates/ide/src/inlay_hints.rs2
-rw-r--r--crates/ide/src/inlay_hints/placeholders.rs20
-rw-r--r--crates/ide/src/static_index.rs1
-rw-r--r--crates/rust-analyzer/src/cli/analysis_stats.rs1
-rw-r--r--crates/rust-analyzer/src/config.rs4
-rw-r--r--docs/book/src/configuration_generated.md7
-rw-r--r--editors/code/package.json10
7 files changed, 44 insertions, 1 deletions
diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs
index deacc7fafb..260da900f4 100644
--- a/crates/ide/src/inlay_hints.rs
+++ b/crates/ide/src/inlay_hints.rs
@@ -320,6 +320,7 @@ pub struct InlayHintsConfig<'a> {
pub implied_dyn_trait_hints: bool,
pub lifetime_elision_hints: LifetimeElisionHints,
pub param_names_for_lifetime_elision_hints: bool,
+ pub hide_inferred_type_hints: bool,
pub hide_named_constructor_hints: bool,
pub hide_closure_initialization_hints: bool,
pub hide_closure_parameter_hints: bool,
@@ -900,6 +901,7 @@ mod tests {
adjustment_hints_mode: AdjustmentHintsMode::Prefix,
adjustment_hints_hide_outside_unsafe: false,
binding_mode_hints: false,
+ hide_inferred_type_hints: false,
hide_named_constructor_hints: false,
hide_closure_initialization_hints: false,
hide_closure_parameter_hints: false,
diff --git a/crates/ide/src/inlay_hints/placeholders.rs b/crates/ide/src/inlay_hints/placeholders.rs
index 96d2c17c03..e535b92a57 100644
--- a/crates/ide/src/inlay_hints/placeholders.rs
+++ b/crates/ide/src/inlay_hints/placeholders.rs
@@ -20,7 +20,7 @@ pub(super) fn type_hints(
display_target: DisplayTarget,
placeholder: InferType,
) -> Option<()> {
- if !config.type_hints {
+ if !config.type_hints || config.hide_inferred_type_hints {
return None;
}
@@ -73,4 +73,22 @@ fn foo() {
"#,
);
}
+
+ #[test]
+ fn hide_inferred_types() {
+ check_with_config(
+ InlayHintsConfig {
+ type_hints: true,
+ hide_inferred_type_hints: true,
+ ..DISABLED_CONFIG
+ },
+ r#"
+struct S<T>(T);
+
+fn foo() {
+ let t: (_, _, [_; _]) = (1_u32, S(2), [false] as _);
+}
+ "#,
+ );
+ }
}
diff --git a/crates/ide/src/static_index.rs b/crates/ide/src/static_index.rs
index 0cf2e15bc6..f3cda9156b 100644
--- a/crates/ide/src/static_index.rs
+++ b/crates/ide/src/static_index.rs
@@ -183,6 +183,7 @@ impl StaticIndex<'_> {
adjustment_hints_hide_outside_unsafe: false,
implicit_drop_hints: false,
implied_dyn_trait_hints: false,
+ hide_inferred_type_hints: false,
hide_named_constructor_hints: false,
hide_closure_initialization_hints: false,
hide_closure_parameter_hints: false,
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs
index ed0b646685..bd3f05977e 100644
--- a/crates/rust-analyzer/src/cli/analysis_stats.rs
+++ b/crates/rust-analyzer/src/cli/analysis_stats.rs
@@ -1222,6 +1222,7 @@ impl flags::AnalysisStats {
implied_dyn_trait_hints: true,
lifetime_elision_hints: ide::LifetimeElisionHints::Always,
param_names_for_lifetime_elision_hints: true,
+ hide_inferred_type_hints: false,
hide_named_constructor_hints: false,
hide_closure_initialization_hints: false,
hide_closure_parameter_hints: false,
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index c380621d81..1a2ea97204 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -304,6 +304,9 @@ config_data! {
/// Hide inlay parameter type hints for closures.
inlayHints_typeHints_hideClosureParameter: bool = false,
+ /// Hide inlay type hints for inferred types.
+ inlayHints_typeHints_hideInferredTypes: bool = false,
+
/// Hide inlay type hints for constructors.
inlayHints_typeHints_hideNamedConstructor: bool = false,
@@ -1937,6 +1940,7 @@ impl Config {
hide_named_constructor_hints: self
.inlayHints_typeHints_hideNamedConstructor()
.to_owned(),
+ hide_inferred_type_hints: self.inlayHints_typeHints_hideInferredTypes().to_owned(),
hide_closure_initialization_hints: self
.inlayHints_typeHints_hideClosureInitialization()
.to_owned(),
diff --git a/docs/book/src/configuration_generated.md b/docs/book/src/configuration_generated.md
index fe1ea57c9b..b36576b4bb 100644
--- a/docs/book/src/configuration_generated.md
+++ b/docs/book/src/configuration_generated.md
@@ -1118,6 +1118,13 @@ Default: `false`
Hide inlay parameter type hints for closures.
+## rust-analyzer.inlayHints.typeHints.hideInferredTypes {#inlayHints.typeHints.hideInferredTypes}
+
+Default: `false`
+
+Hide inlay type hints for inferred types.
+
+
## rust-analyzer.inlayHints.typeHints.hideNamedConstructor {#inlayHints.typeHints.hideNamedConstructor}
Default: `false`
diff --git a/editors/code/package.json b/editors/code/package.json
index 8475864427..abe85d6c9d 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -2469,6 +2469,16 @@
{
"title": "Inlay Hints",
"properties": {
+ "rust-analyzer.inlayHints.typeHints.hideInferredTypes": {
+ "markdownDescription": "Hide inlay type hints for inferred types.",
+ "default": false,
+ "type": "boolean"
+ }
+ }
+ },
+ {
+ "title": "Inlay Hints",
+ "properties": {
"rust-analyzer.inlayHints.typeHints.hideNamedConstructor": {
"markdownDescription": "Hide inlay type hints for constructors.",
"default": false,