mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-12-09 02:55:12 +00:00
Add config hide placeholders type hints
In the inferred type hints, expand the line too long. add config to disable it.
Example
---
```json
{"rust-analyzer.inlayHints.typeHints.hideInferredTypes": true}
```
```rust
use std::collections::HashMap;
fn foo(iter: Vec<Result<HashMap<String, String>, std::io::Error>>) {
let output = iter.into_iter().collect::<Result<Vec<_>, _>>().unwrap();
}
```
**Before this PR**
```rust
let output: Vec<HashMap<String, String>> = iter.into_iter().collect::<Result<Vec<_ = HashMap<String, String>>, _ = Error>>().unwrap();
```
**After this PR**
```rust
let output: Vec<HashMap<String, String>> = iter.into_iter().collect::<Result<Vec<_>, _>>().unwrap();
```
This commit is contained in:
parent
633cff2520
commit
e8ee597340
7 changed files with 44 additions and 1 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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 _);
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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`
|
||||
|
|
|
|||
|
|
@ -2466,6 +2466,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": {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue