Skip to content

Commit 9075b4a

Browse files
Merge pull request #21068 from Aditya-PS-05/feat/configure-dyn-inlay-hint
feat: make dyn inlay hints configurable
2 parents 636c3aa + ba5ecc0 commit 9075b4a

File tree

7 files changed

+38
-2
lines changed

7 files changed

+38
-2
lines changed

crates/ide/src/inlay_hints.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ pub struct InlayHintsConfig<'a> {
316316
pub closure_capture_hints: bool,
317317
pub binding_mode_hints: bool,
318318
pub implicit_drop_hints: bool,
319+
pub implied_dyn_trait_hints: bool,
319320
pub lifetime_elision_hints: LifetimeElisionHints,
320321
pub param_names_for_lifetime_elision_hints: bool,
321322
pub hide_named_constructor_hints: bool,
@@ -907,6 +908,7 @@ mod tests {
907908
closing_brace_hints_min_lines: None,
908909
fields_to_resolve: InlayFieldsToResolve::empty(),
909910
implicit_drop_hints: false,
911+
implied_dyn_trait_hints: false,
910912
range_exclusive_hints: false,
911913
minicore: MiniCore::default(),
912914
};

crates/ide/src/inlay_hints/implied_dyn_trait.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ pub(super) fn hints(
1414
config: &InlayHintsConfig<'_>,
1515
path: Either<ast::PathType, ast::DynTraitType>,
1616
) -> Option<()> {
17+
if !config.implied_dyn_trait_hints {
18+
return None;
19+
}
20+
1721
let parent = path.syntax().parent()?;
1822
let range = match path {
1923
Either::Left(path) => {
@@ -76,7 +80,14 @@ mod tests {
7680

7781
#[track_caller]
7882
fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str) {
79-
check_with_config(InlayHintsConfig { sized_bound: true, ..DISABLED_CONFIG }, ra_fixture);
83+
check_with_config(
84+
InlayHintsConfig {
85+
sized_bound: true,
86+
implied_dyn_trait_hints: true,
87+
..DISABLED_CONFIG
88+
},
89+
ra_fixture,
90+
);
8091
}
8192

8293
#[test]
@@ -125,7 +136,7 @@ fn foo(
125136
#[test]
126137
fn edit() {
127138
check_edit(
128-
DISABLED_CONFIG,
139+
InlayHintsConfig { implied_dyn_trait_hints: true, ..DISABLED_CONFIG },
129140
r#"
130141
trait T {}
131142
fn foo(

crates/ide/src/static_index.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ impl StaticIndex<'_> {
173173
adjustment_hints_mode: AdjustmentHintsMode::Prefix,
174174
adjustment_hints_hide_outside_unsafe: false,
175175
implicit_drop_hints: false,
176+
implied_dyn_trait_hints: false,
176177
hide_named_constructor_hints: false,
177178
hide_closure_initialization_hints: false,
178179
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
@@ -1186,6 +1186,7 @@ impl flags::AnalysisStats {
11861186
closure_capture_hints: true,
11871187
binding_mode_hints: true,
11881188
implicit_drop_hints: true,
1189+
implied_dyn_trait_hints: true,
11891190
lifetime_elision_hints: ide::LifetimeElisionHints::Always,
11901191
param_names_for_lifetime_elision_hints: true,
11911192
hide_named_constructor_hints: false,

crates/rust-analyzer/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ config_data! {
263263
/// Show inlay hints for the implied type parameter `Sized` bound.
264264
inlayHints_implicitSizedBoundHints_enable: bool = false,
265265

266+
/// Show inlay hints for the implied `dyn` keyword in trait object types.
267+
inlayHints_impliedDynTraitHints_enable: bool = true,
268+
266269
/// Show inlay type hints for elided lifetimes in function signatures.
267270
inlayHints_lifetimeElisionHints_enable: LifetimeElisionDef = LifetimeElisionDef::Never,
268271

@@ -1983,6 +1986,7 @@ impl Config {
19831986
&client_capability_fields,
19841987
),
19851988
implicit_drop_hints: self.inlayHints_implicitDrops_enable().to_owned(),
1989+
implied_dyn_trait_hints: self.inlayHints_impliedDynTraitHints_enable().to_owned(),
19861990
range_exclusive_hints: self.inlayHints_rangeExclusiveHints_enable().to_owned(),
19871991
minicore,
19881992
}

docs/book/src/configuration_generated.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,13 @@ Default: `false`
10331033
Show inlay hints for the implied type parameter `Sized` bound.
10341034

10351035

1036+
## rust-analyzer.inlayHints.impliedDynTraitHints.enable {#inlayHints.impliedDynTraitHints.enable}
1037+
1038+
Default: `true`
1039+
1040+
Show inlay hints for the implied `dyn` keyword in trait object types.
1041+
1042+
10361043
## rust-analyzer.inlayHints.lifetimeElisionHints.enable {#inlayHints.lifetimeElisionHints.enable}
10371044

10381045
Default: `"never"`

editors/code/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2343,6 +2343,16 @@
23432343
}
23442344
}
23452345
},
2346+
{
2347+
"title": "Inlay Hints",
2348+
"properties": {
2349+
"rust-analyzer.inlayHints.impliedDynTraitHints.enable": {
2350+
"markdownDescription": "Show inlay hints for the implied `dyn` keyword in trait object types.",
2351+
"default": true,
2352+
"type": "boolean"
2353+
}
2354+
}
2355+
},
23462356
{
23472357
"title": "Inlay Hints",
23482358
"properties": {

0 commit comments

Comments
 (0)