feat: Implement lifetime elision hints

This commit is contained in:
Lukas Wirth
2022-03-18 18:11:16 +01:00
parent 890f98f21f
commit 673e2b1d8f
5 changed files with 242 additions and 17 deletions

View File

@@ -255,6 +255,8 @@ config_data! {
inlayHints_chainingHints: bool = "true",
/// Whether to show inlay type hints for return types of closures with blocks.
inlayHints_closureReturnTypeHints: bool = "false",
/// Whether to show inlay type hints for elided lifetimes in function signatures.
inlayHints_lifetimeElisionHints: bool = "false",
/// Whether to hide inlay hints for constructors.
inlayHints_hideNamedConstructorHints: bool = "false",
@@ -855,6 +857,7 @@ impl Config {
parameter_hints: self.data.inlayHints_parameterHints,
chaining_hints: self.data.inlayHints_chainingHints,
closure_return_type_hints: self.data.inlayHints_closureReturnTypeHints,
lifetime_elision_hints: self.data.inlayHints_lifetimeElisionHints,
hide_named_constructor_hints: self.data.inlayHints_hideNamedConstructorHints,
max_length: self.data.inlayHints_maxLength,
}

View File

@@ -427,27 +427,34 @@ pub(crate) fn inlay_hint(
}),
position: match inlay_hint.kind {
InlayKind::ParameterHint => position(line_index, inlay_hint.range.start()),
InlayKind::ClosureReturnTypeHint | InlayKind::TypeHint | InlayKind::ChainingHint => {
position(line_index, inlay_hint.range.end())
}
InlayKind::ClosureReturnTypeHint
| InlayKind::TypeHint
| InlayKind::ChainingHint
| InlayKind::GenericParamListHint
| InlayKind::LifetimeHint => position(line_index, inlay_hint.range.end()),
},
kind: match inlay_hint.kind {
InlayKind::ParameterHint => Some(lsp_ext::InlayHintKind::PARAMETER),
InlayKind::ClosureReturnTypeHint | InlayKind::TypeHint | InlayKind::ChainingHint => {
Some(lsp_ext::InlayHintKind::TYPE)
}
InlayKind::GenericParamListHint | InlayKind::LifetimeHint => None,
},
tooltip: None,
padding_left: Some(match inlay_hint.kind {
InlayKind::TypeHint => !render_colons,
InlayKind::ParameterHint | InlayKind::ClosureReturnTypeHint => false,
InlayKind::ChainingHint => true,
InlayKind::GenericParamListHint => false,
InlayKind::LifetimeHint => false,
}),
padding_right: Some(match inlay_hint.kind {
InlayKind::TypeHint | InlayKind::ChainingHint | InlayKind::ClosureReturnTypeHint => {
false
}
InlayKind::ParameterHint => true,
InlayKind::LifetimeHint => true,
InlayKind::GenericParamListHint => false,
}),
}
}