Show inlay hints after a } to indicate the closed item

This commit is contained in:
Jonas Schievink 2022-05-13 19:42:59 +02:00
parent 58234c64da
commit 867a7dc7a0
6 changed files with 185 additions and 7 deletions

View file

@ -259,6 +259,11 @@ config_data! {
inlayHints_bindingModeHints_enable: bool = "false",
/// Whether to show inlay type hints for method chains.
inlayHints_chainingHints_enable: bool = "true",
/// Whether to show inlay hints after a closing `}` to indicate what item it belongs to.
inlayHints_closingBraceHints_enable: bool = "true",
/// Minimum number of lines required before the `}` until the hint is shown (set to 0 or 1
/// to always show them).
inlayHints_closingBraceHints_minLines: usize = "25",
/// Whether to show inlay type hints for return types of closures with blocks.
inlayHints_closureReturnTypeHints_enable: bool = "false",
/// Whether to show inlay type hints for elided lifetimes in function signatures.
@ -1005,6 +1010,11 @@ impl Config {
.data
.inlayHints_lifetimeElisionHints_useParameterNames,
max_length: self.data.inlayHints_maxLength,
closing_brace_hints_min_lines: if self.data.inlayHints_closingBraceHints_enable {
Some(self.data.inlayHints_closingBraceHints_minLines)
} else {
None
},
}
}

View file

@ -426,7 +426,8 @@ pub(crate) fn inlay_hint(
| InlayKind::TypeHint
| InlayKind::ChainingHint
| InlayKind::GenericParamListHint
| InlayKind::LifetimeHint => position(line_index, inlay_hint.range.end()),
| InlayKind::LifetimeHint
| InlayKind::ClosingBraceHint => position(line_index, inlay_hint.range.end()),
},
label: lsp_types::InlayHintLabel::String(match inlay_hint.kind {
InlayKind::ParameterHint if render_colons => format!("{}:", inlay_hint.label),
@ -442,12 +443,13 @@ pub(crate) fn inlay_hint(
InlayKind::BindingModeHint
| InlayKind::GenericParamListHint
| InlayKind::LifetimeHint
| InlayKind::ImplicitReborrowHint => None,
| InlayKind::ImplicitReborrowHint
| InlayKind::ClosingBraceHint => None,
},
tooltip: None,
padding_left: Some(match inlay_hint.kind {
InlayKind::TypeHint => !render_colons,
InlayKind::ChainingHint => true,
InlayKind::ChainingHint | InlayKind::ClosingBraceHint => true,
InlayKind::BindingModeHint
| InlayKind::ClosureReturnTypeHint
| InlayKind::GenericParamListHint
@ -460,7 +462,8 @@ pub(crate) fn inlay_hint(
| InlayKind::ClosureReturnTypeHint
| InlayKind::GenericParamListHint
| InlayKind::ImplicitReborrowHint
| InlayKind::TypeHint => false,
| InlayKind::TypeHint
| InlayKind::ClosingBraceHint => false,
InlayKind::BindingModeHint => inlay_hint.label != "&",
InlayKind::ParameterHint | InlayKind::LifetimeHint => true,
}),