Skip to content

Commit 259e233

Browse files
committed
Declare inlayHints_* as local
1 parent 34a255c commit 259e233

File tree

2 files changed

+130
-167
lines changed

2 files changed

+130
-167
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 127 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -344,50 +344,6 @@ config_data! {
344344
/// How to render the size information in a memory layout hover.
345345
hover_memoryLayout_size: Option<MemoryLayoutHoverRenderKindDef> = "\"both\"",
346346

347-
/// Whether to show inlay type hints for binding modes.
348-
inlayHints_bindingModeHints_enable: bool = "false",
349-
/// Whether to show inlay type hints for method chains.
350-
inlayHints_chainingHints_enable: bool = "true",
351-
/// Whether to show inlay hints after a closing `}` to indicate what item it belongs to.
352-
inlayHints_closingBraceHints_enable: bool = "true",
353-
/// Minimum number of lines required before the `}` until the hint is shown (set to 0 or 1
354-
/// to always show them).
355-
inlayHints_closingBraceHints_minLines: usize = "25",
356-
/// Whether to show inlay hints for closure captures.
357-
inlayHints_closureCaptureHints_enable: bool = "false",
358-
/// Whether to show inlay type hints for return types of closures.
359-
inlayHints_closureReturnTypeHints_enable: ClosureReturnTypeHintsDef = "\"never\"",
360-
/// Closure notation in type and chaining inlay hints.
361-
inlayHints_closureStyle: ClosureStyle = "\"impl_fn\"",
362-
/// Whether to show enum variant discriminant hints.
363-
inlayHints_discriminantHints_enable: DiscriminantHintsDef = "\"never\"",
364-
/// Whether to show inlay hints for type adjustments.
365-
inlayHints_expressionAdjustmentHints_enable: AdjustmentHintsDef = "\"never\"",
366-
/// Whether to hide inlay hints for type adjustments outside of `unsafe` blocks.
367-
inlayHints_expressionAdjustmentHints_hideOutsideUnsafe: bool = "false",
368-
/// Whether to show inlay hints as postfix ops (`.*` instead of `*`, etc).
369-
inlayHints_expressionAdjustmentHints_mode: AdjustmentHintsModeDef = "\"prefix\"",
370-
/// Whether to show inlay type hints for elided lifetimes in function signatures.
371-
inlayHints_lifetimeElisionHints_enable: LifetimeElisionDef = "\"never\"",
372-
/// Whether to prefer using parameter names as the name for elided lifetime hints if possible.
373-
inlayHints_lifetimeElisionHints_useParameterNames: bool = "false",
374-
/// Maximum length for inlay hints. Set to null to have an unlimited length.
375-
inlayHints_maxLength: Option<usize> = "25",
376-
/// Whether to show function parameter name inlay hints at the call
377-
/// site.
378-
inlayHints_parameterHints_enable: bool = "true",
379-
/// Whether to show inlay hints for compiler inserted reborrows.
380-
/// This setting is deprecated in favor of #rust-analyzer.inlayHints.expressionAdjustmentHints.enable#.
381-
inlayHints_reborrowHints_enable: ReborrowHintsDef = "\"never\"",
382-
/// Whether to render leading colons for type hints, and trailing colons for parameter hints.
383-
inlayHints_renderColons: bool = "true",
384-
/// Whether to show inlay type hints for variables.
385-
inlayHints_typeHints_enable: bool = "true",
386-
/// Whether to hide inlay type hints for `let` statements that initialize to a closure.
387-
/// Only applies to closures with blocks, same as `#rust-analyzer.inlayHints.closureReturnTypeHints.enable#`.
388-
inlayHints_typeHints_hideClosureInitialization: bool = "false",
389-
/// Whether to hide inlay type hints for constructors.
390-
inlayHints_typeHints_hideNamedConstructor: bool = "false",
391347
/// Enables the experimental support for interpreting tests.
392348
interpret_tests: bool = "false",
393349

@@ -551,6 +507,51 @@ config_data! {
551507
config_data! {
552508
struct LocalConfigData {
553509

510+
/// Whether to show inlay type hints for binding modes.
511+
inlayHints_bindingModeHints_enable: bool = "false",
512+
/// Whether to show inlay type hints for method chains.
513+
inlayHints_chainingHints_enable: bool = "true",
514+
/// Whether to show inlay hints after a closing `}` to indicate what item it belongs to.
515+
inlayHints_closingBraceHints_enable: bool = "true",
516+
/// Minimum number of lines required before the `}` until the hint is shown (set to 0 or 1
517+
/// to always show them).
518+
inlayHints_closingBraceHints_minLines: usize = "25",
519+
/// Whether to show inlay hints for closure captures.
520+
inlayHints_closureCaptureHints_enable: bool = "false",
521+
/// Whether to show inlay type hints for return types of closures.
522+
inlayHints_closureReturnTypeHints_enable: ClosureReturnTypeHintsDef = "\"never\"",
523+
/// Closure notation in type and chaining inlay hints.
524+
inlayHints_closureStyle: ClosureStyle = "\"impl_fn\"",
525+
/// Whether to show enum variant discriminant hints.
526+
inlayHints_discriminantHints_enable: DiscriminantHintsDef = "\"never\"",
527+
/// Whether to show inlay hints for type adjustments.
528+
inlayHints_expressionAdjustmentHints_enable: AdjustmentHintsDef = "\"never\"",
529+
/// Whether to hide inlay hints for type adjustments outside of `unsafe` blocks.
530+
inlayHints_expressionAdjustmentHints_hideOutsideUnsafe: bool = "false",
531+
/// Whether to show inlay hints as postfix ops (`.*` instead of `*`, etc).
532+
inlayHints_expressionAdjustmentHints_mode: AdjustmentHintsModeDef = "\"prefix\"",
533+
/// Whether to show inlay type hints for elided lifetimes in function signatures.
534+
inlayHints_lifetimeElisionHints_enable: LifetimeElisionDef = "\"never\"",
535+
/// Whether to prefer using parameter names as the name for elided lifetime hints if possible.
536+
inlayHints_lifetimeElisionHints_useParameterNames: bool = "false",
537+
/// Maximum length for inlay hints. Set to null to have an unlimited length.
538+
inlayHints_maxLength: Option<usize> = "25",
539+
/// Whether to show function parameter name inlay hints at the call
540+
/// site.
541+
inlayHints_parameterHints_enable: bool = "true",
542+
/// Whether to show inlay hints for compiler inserted reborrows.
543+
/// This setting is deprecated in favor of #rust-analyzer.inlayHints.expressionAdjustmentHints.enable#.
544+
inlayHints_reborrowHints_enable: ReborrowHintsDef = "\"never\"",
545+
/// Whether to render leading colons for type hints, and trailing colons for parameter hints.
546+
inlayHints_renderColons: bool = "true",
547+
/// Whether to show inlay type hints for variables.
548+
inlayHints_typeHints_enable: bool = "true",
549+
/// Whether to hide inlay type hints for `let` statements that initialize to a closure.
550+
/// Only applies to closures with blocks, same as `#rust-analyzer.inlayHints.closureReturnTypeHints.enable#`.
551+
inlayHints_typeHints_hideClosureInitialization: bool = "false",
552+
/// Whether to hide inlay type hints for constructors.
553+
inlayHints_typeHints_hideNamedConstructor: bool = "false",
554+
554555
/// Whether to enforce the import granularity setting for all files. If set to false rust-analyzer will try to keep import styles consistent per file.
555556
imports_granularity_enforce: bool = "false",
556557
/// How imports should be grouped into use statements.
@@ -713,6 +714,88 @@ impl<'a> LocalConfigView<'a> {
713714
skip_glob_imports: !self.local.imports_merge_glob,
714715
}
715716
}
717+
pub fn inlay_hints(&self) -> InlayHintsConfig {
718+
let client_capability_fields = self
719+
.caps
720+
.text_document
721+
.as_ref()
722+
.and_then(|text| text.inlay_hint.as_ref())
723+
.and_then(|inlay_hint_caps| inlay_hint_caps.resolve_support.as_ref())
724+
.map(|inlay_resolve| inlay_resolve.properties.iter())
725+
.into_iter()
726+
.flatten()
727+
.cloned()
728+
.collect::<FxHashSet<_>>();
729+
730+
InlayHintsConfig {
731+
render_colons: self.local.inlayHints_renderColons,
732+
type_hints: self.local.inlayHints_typeHints_enable,
733+
parameter_hints: self.local.inlayHints_parameterHints_enable,
734+
chaining_hints: self.local.inlayHints_chainingHints_enable,
735+
discriminant_hints: match self.local.inlayHints_discriminantHints_enable {
736+
DiscriminantHintsDef::Always => ide::DiscriminantHints::Always,
737+
DiscriminantHintsDef::Never => ide::DiscriminantHints::Never,
738+
DiscriminantHintsDef::Fieldless => ide::DiscriminantHints::Fieldless,
739+
},
740+
closure_return_type_hints: match self.local.inlayHints_closureReturnTypeHints_enable {
741+
ClosureReturnTypeHintsDef::Always => ide::ClosureReturnTypeHints::Always,
742+
ClosureReturnTypeHintsDef::Never => ide::ClosureReturnTypeHints::Never,
743+
ClosureReturnTypeHintsDef::WithBlock => ide::ClosureReturnTypeHints::WithBlock,
744+
},
745+
lifetime_elision_hints: match self.local.inlayHints_lifetimeElisionHints_enable {
746+
LifetimeElisionDef::Always => ide::LifetimeElisionHints::Always,
747+
LifetimeElisionDef::Never => ide::LifetimeElisionHints::Never,
748+
LifetimeElisionDef::SkipTrivial => ide::LifetimeElisionHints::SkipTrivial,
749+
},
750+
hide_named_constructor_hints: self.local.inlayHints_typeHints_hideNamedConstructor,
751+
hide_closure_initialization_hints: self
752+
.local
753+
.inlayHints_typeHints_hideClosureInitialization,
754+
closure_style: match self.local.inlayHints_closureStyle {
755+
ClosureStyle::ImplFn => hir::ClosureStyle::ImplFn,
756+
ClosureStyle::RustAnalyzer => hir::ClosureStyle::RANotation,
757+
ClosureStyle::WithId => hir::ClosureStyle::ClosureWithId,
758+
ClosureStyle::Hide => hir::ClosureStyle::Hide,
759+
},
760+
closure_capture_hints: self.local.inlayHints_closureCaptureHints_enable,
761+
adjustment_hints: match self.local.inlayHints_expressionAdjustmentHints_enable {
762+
AdjustmentHintsDef::Always => ide::AdjustmentHints::Always,
763+
AdjustmentHintsDef::Never => match self.local.inlayHints_reborrowHints_enable {
764+
ReborrowHintsDef::Always | ReborrowHintsDef::Mutable => {
765+
ide::AdjustmentHints::ReborrowOnly
766+
}
767+
ReborrowHintsDef::Never => ide::AdjustmentHints::Never,
768+
},
769+
AdjustmentHintsDef::Reborrow => ide::AdjustmentHints::ReborrowOnly,
770+
},
771+
adjustment_hints_mode: match self.local.inlayHints_expressionAdjustmentHints_mode {
772+
AdjustmentHintsModeDef::Prefix => ide::AdjustmentHintsMode::Prefix,
773+
AdjustmentHintsModeDef::Postfix => ide::AdjustmentHintsMode::Postfix,
774+
AdjustmentHintsModeDef::PreferPrefix => ide::AdjustmentHintsMode::PreferPrefix,
775+
AdjustmentHintsModeDef::PreferPostfix => ide::AdjustmentHintsMode::PreferPostfix,
776+
},
777+
adjustment_hints_hide_outside_unsafe: self
778+
.local
779+
.inlayHints_expressionAdjustmentHints_hideOutsideUnsafe,
780+
binding_mode_hints: self.local.inlayHints_bindingModeHints_enable,
781+
param_names_for_lifetime_elision_hints: self
782+
.local
783+
.inlayHints_lifetimeElisionHints_useParameterNames,
784+
max_length: self.local.inlayHints_maxLength,
785+
closing_brace_hints_min_lines: if self.local.inlayHints_closingBraceHints_enable {
786+
Some(self.local.inlayHints_closingBraceHints_minLines)
787+
} else {
788+
None
789+
},
790+
fields_to_resolve: InlayFieldsToResolve {
791+
resolve_text_edits: client_capability_fields.contains("textEdits"),
792+
resolve_hint_tooltip: client_capability_fields.contains("tooltip"),
793+
resolve_label_tooltip: client_capability_fields.contains("label.tooltip"),
794+
resolve_label_location: client_capability_fields.contains("label.location"),
795+
resolve_label_command: client_capability_fields.contains("label.command"),
796+
},
797+
}
798+
}
716799

717800
pub fn expand_proc_attr_macros(&self) -> bool {
718801
self.global.0.procMacro_enable && self.global.0.procMacro_attributes_enable
@@ -1609,127 +1692,6 @@ impl Config {
16091692
}
16101693
}
16111694

1612-
pub fn inlay_hints(&self) -> InlayHintsConfig {
1613-
let client_capability_fields = self
1614-
.caps
1615-
.text_document
1616-
.as_ref()
1617-
.and_then(|text| text.inlay_hint.as_ref())
1618-
.and_then(|inlay_hint_caps| inlay_hint_caps.resolve_support.as_ref())
1619-
.map(|inlay_resolve| inlay_resolve.properties.iter())
1620-
.into_iter()
1621-
.flatten()
1622-
.cloned()
1623-
.collect::<FxHashSet<_>>();
1624-
1625-
InlayHintsConfig {
1626-
render_colons: self.root_config.global.0.inlayHints_renderColons,
1627-
type_hints: self.root_config.global.0.inlayHints_typeHints_enable,
1628-
parameter_hints: self.root_config.global.0.inlayHints_parameterHints_enable,
1629-
chaining_hints: self.root_config.global.0.inlayHints_chainingHints_enable,
1630-
discriminant_hints: match self.root_config.global.0.inlayHints_discriminantHints_enable
1631-
{
1632-
DiscriminantHintsDef::Always => ide::DiscriminantHints::Always,
1633-
DiscriminantHintsDef::Never => ide::DiscriminantHints::Never,
1634-
DiscriminantHintsDef::Fieldless => ide::DiscriminantHints::Fieldless,
1635-
},
1636-
closure_return_type_hints: match self
1637-
.root_config
1638-
.global
1639-
.0
1640-
.inlayHints_closureReturnTypeHints_enable
1641-
{
1642-
ClosureReturnTypeHintsDef::Always => ide::ClosureReturnTypeHints::Always,
1643-
ClosureReturnTypeHintsDef::Never => ide::ClosureReturnTypeHints::Never,
1644-
ClosureReturnTypeHintsDef::WithBlock => ide::ClosureReturnTypeHints::WithBlock,
1645-
},
1646-
lifetime_elision_hints: match self
1647-
.root_config
1648-
.global
1649-
.0
1650-
.inlayHints_lifetimeElisionHints_enable
1651-
{
1652-
LifetimeElisionDef::Always => ide::LifetimeElisionHints::Always,
1653-
LifetimeElisionDef::Never => ide::LifetimeElisionHints::Never,
1654-
LifetimeElisionDef::SkipTrivial => ide::LifetimeElisionHints::SkipTrivial,
1655-
},
1656-
hide_named_constructor_hints: self
1657-
.root_config
1658-
.global
1659-
.0
1660-
.inlayHints_typeHints_hideNamedConstructor,
1661-
hide_closure_initialization_hints: self
1662-
.root_config
1663-
.global
1664-
.0
1665-
.inlayHints_typeHints_hideClosureInitialization,
1666-
closure_style: match self.root_config.global.0.inlayHints_closureStyle {
1667-
ClosureStyle::ImplFn => hir::ClosureStyle::ImplFn,
1668-
ClosureStyle::RustAnalyzer => hir::ClosureStyle::RANotation,
1669-
ClosureStyle::WithId => hir::ClosureStyle::ClosureWithId,
1670-
ClosureStyle::Hide => hir::ClosureStyle::Hide,
1671-
},
1672-
closure_capture_hints: self.root_config.global.0.inlayHints_closureCaptureHints_enable,
1673-
adjustment_hints: match self
1674-
.root_config
1675-
.global
1676-
.0
1677-
.inlayHints_expressionAdjustmentHints_enable
1678-
{
1679-
AdjustmentHintsDef::Always => ide::AdjustmentHints::Always,
1680-
AdjustmentHintsDef::Never => {
1681-
match self.root_config.global.0.inlayHints_reborrowHints_enable {
1682-
ReborrowHintsDef::Always | ReborrowHintsDef::Mutable => {
1683-
ide::AdjustmentHints::ReborrowOnly
1684-
}
1685-
ReborrowHintsDef::Never => ide::AdjustmentHints::Never,
1686-
}
1687-
}
1688-
AdjustmentHintsDef::Reborrow => ide::AdjustmentHints::ReborrowOnly,
1689-
},
1690-
adjustment_hints_mode: match self
1691-
.root_config
1692-
.global
1693-
.0
1694-
.inlayHints_expressionAdjustmentHints_mode
1695-
{
1696-
AdjustmentHintsModeDef::Prefix => ide::AdjustmentHintsMode::Prefix,
1697-
AdjustmentHintsModeDef::Postfix => ide::AdjustmentHintsMode::Postfix,
1698-
AdjustmentHintsModeDef::PreferPrefix => ide::AdjustmentHintsMode::PreferPrefix,
1699-
AdjustmentHintsModeDef::PreferPostfix => ide::AdjustmentHintsMode::PreferPostfix,
1700-
},
1701-
adjustment_hints_hide_outside_unsafe: self
1702-
.root_config
1703-
.global
1704-
.0
1705-
.inlayHints_expressionAdjustmentHints_hideOutsideUnsafe,
1706-
binding_mode_hints: self.root_config.global.0.inlayHints_bindingModeHints_enable,
1707-
param_names_for_lifetime_elision_hints: self
1708-
.root_config
1709-
.global
1710-
.0
1711-
.inlayHints_lifetimeElisionHints_useParameterNames,
1712-
max_length: self.root_config.global.0.inlayHints_maxLength,
1713-
closing_brace_hints_min_lines: if self
1714-
.root_config
1715-
.global
1716-
.0
1717-
.inlayHints_closingBraceHints_enable
1718-
{
1719-
Some(self.root_config.global.0.inlayHints_closingBraceHints_minLines)
1720-
} else {
1721-
None
1722-
},
1723-
fields_to_resolve: InlayFieldsToResolve {
1724-
resolve_text_edits: client_capability_fields.contains("textEdits"),
1725-
resolve_hint_tooltip: client_capability_fields.contains("tooltip"),
1726-
resolve_label_tooltip: client_capability_fields.contains("label.tooltip"),
1727-
resolve_label_location: client_capability_fields.contains("label.location"),
1728-
resolve_label_command: client_capability_fields.contains("label.command"),
1729-
},
1730-
}
1731-
}
1732-
17331695
pub fn find_all_refs_exclude_imports(&self) -> bool {
17341696
self.root_config.global.0.references_excludeImports
17351697
}

crates/rust-analyzer/src/handlers/request.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,7 @@ pub(crate) fn handle_inlay_hints(
14111411
params.range,
14121412
)?;
14131413
let line_index = snap.file_line_index(file_id)?;
1414-
let inlay_hints_config = snap.config.inlay_hints();
1414+
let inlay_hints_config = snap.config.localize_by_file_id(file_id).inlay_hints();
14151415
Ok(Some(
14161416
snap.analysis
14171417
.inlay_hints(&inlay_hints_config, file_id, Some(range))?
@@ -1455,7 +1455,8 @@ pub(crate) fn handle_inlay_hints_resolve(
14551455
range_start.checked_sub(1.into()).unwrap_or(range_start),
14561456
range_end.checked_add(1.into()).unwrap_or(range_end),
14571457
);
1458-
let mut forced_resolve_inlay_hints_config = snap.config.inlay_hints();
1458+
let mut forced_resolve_inlay_hints_config =
1459+
snap.config.localize_by_file_id(file_id).inlay_hints();
14591460
forced_resolve_inlay_hints_config.fields_to_resolve = InlayFieldsToResolve::empty();
14601461
let resolve_hints = snap.analysis.inlay_hints(
14611462
&forced_resolve_inlay_hints_config,

0 commit comments

Comments
 (0)