mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
Auto merge of #14742 - Veykril:closure-capture-inlays, r=Veykril
feat: Closure capture inlay hints I opted for a fictional `move(foo, &bar, &mut qux)` syntax here, disabled by default as these are not correct rust syntax and hence could cause confusion. 
This commit is contained in:
commit
d3ce333ec8
11 changed files with 278 additions and 37 deletions
|
@ -340,6 +340,8 @@ config_data! {
|
|||
/// 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 hints for closure captures.
|
||||
inlayHints_closureCaptureHints_enable: bool = "false",
|
||||
/// Whether to show inlay type hints for return types of closures.
|
||||
inlayHints_closureReturnTypeHints_enable: ClosureReturnTypeHintsDef = "\"never\"",
|
||||
/// Closure notation in type and chaining inlay hints.
|
||||
|
@ -1314,6 +1316,7 @@ impl Config {
|
|||
ClosureStyle::WithId => hir::ClosureStyle::ClosureWithId,
|
||||
ClosureStyle::Hide => hir::ClosureStyle::Hide,
|
||||
},
|
||||
closure_capture_hints: self.data.inlayHints_closureCaptureHints_enable,
|
||||
adjustment_hints: match self.data.inlayHints_expressionAdjustmentHints_enable {
|
||||
AdjustmentHintsDef::Always => ide::AdjustmentHints::Always,
|
||||
AdjustmentHintsDef::Never => match self.data.inlayHints_reborrowHints_enable {
|
||||
|
|
|
@ -456,6 +456,7 @@ pub(crate) fn inlay_hint(
|
|||
| InlayKind::BindingMode => position(line_index, inlay_hint.range.start()),
|
||||
// after annotated thing
|
||||
InlayKind::ClosureReturnType
|
||||
| InlayKind::ClosureCapture
|
||||
| InlayKind::Type
|
||||
| InlayKind::Discriminant
|
||||
| InlayKind::Chaining
|
||||
|
@ -469,6 +470,7 @@ pub(crate) fn inlay_hint(
|
|||
InlayKind::Type => !render_colons,
|
||||
InlayKind::Chaining | InlayKind::ClosingBrace => true,
|
||||
InlayKind::ClosingParenthesis
|
||||
| InlayKind::ClosureCapture
|
||||
| InlayKind::Discriminant
|
||||
| InlayKind::OpeningParenthesis
|
||||
| InlayKind::BindingMode
|
||||
|
@ -490,6 +492,9 @@ pub(crate) fn inlay_hint(
|
|||
| InlayKind::Type
|
||||
| InlayKind::Discriminant
|
||||
| InlayKind::ClosingBrace => false,
|
||||
InlayKind::ClosureCapture => {
|
||||
matches!(&label, lsp_types::InlayHintLabel::String(s) if s == ")")
|
||||
}
|
||||
InlayKind::BindingMode => {
|
||||
matches!(&label, lsp_types::InlayHintLabel::String(s) if s != "&")
|
||||
}
|
||||
|
@ -501,6 +506,7 @@ pub(crate) fn inlay_hint(
|
|||
Some(lsp_types::InlayHintKind::TYPE)
|
||||
}
|
||||
InlayKind::ClosingParenthesis
|
||||
| InlayKind::ClosureCapture
|
||||
| InlayKind::Discriminant
|
||||
| InlayKind::OpeningParenthesis
|
||||
| InlayKind::BindingMode
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue