Add field for text edits to InlayHint
This commit is contained in:
parent
ac03de773f
commit
fcbc250723
@ -16,6 +16,7 @@ use syntax::{
|
|||||||
ast::{self, AstNode},
|
ast::{self, AstNode},
|
||||||
match_ast, NodeOrToken, SyntaxNode, TextRange,
|
match_ast, NodeOrToken, SyntaxNode, TextRange,
|
||||||
};
|
};
|
||||||
|
use text_edit::TextEdit;
|
||||||
|
|
||||||
use crate::{navigation_target::TryToNav, FileId};
|
use crate::{navigation_target::TryToNav, FileId};
|
||||||
|
|
||||||
@ -113,14 +114,26 @@ pub struct InlayHint {
|
|||||||
pub kind: InlayKind,
|
pub kind: InlayKind,
|
||||||
/// The actual label to show in the inlay hint.
|
/// The actual label to show in the inlay hint.
|
||||||
pub label: InlayHintLabel,
|
pub label: InlayHintLabel,
|
||||||
|
/// Text edit to apply when "accepting" this inlay hint.
|
||||||
|
pub text_edit: Option<TextEdit>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InlayHint {
|
impl InlayHint {
|
||||||
fn closing_paren(range: TextRange) -> InlayHint {
|
fn closing_paren(range: TextRange) -> InlayHint {
|
||||||
InlayHint { range, kind: InlayKind::ClosingParenthesis, label: InlayHintLabel::from(")") }
|
InlayHint {
|
||||||
|
range,
|
||||||
|
kind: InlayKind::ClosingParenthesis,
|
||||||
|
label: InlayHintLabel::from(")"),
|
||||||
|
text_edit: None,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fn opening_paren(range: TextRange) -> InlayHint {
|
fn opening_paren(range: TextRange) -> InlayHint {
|
||||||
InlayHint { range, kind: InlayKind::OpeningParenthesis, label: InlayHintLabel::from("(") }
|
InlayHint {
|
||||||
|
range,
|
||||||
|
kind: InlayKind::OpeningParenthesis,
|
||||||
|
label: InlayHintLabel::from("("),
|
||||||
|
text_edit: None,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,6 +135,7 @@ pub(super) fn hints(
|
|||||||
))),
|
))),
|
||||||
None,
|
None,
|
||||||
),
|
),
|
||||||
|
text_edit: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if !postfix && needs_inner_parens {
|
if !postfix && needs_inner_parens {
|
||||||
|
@ -12,9 +12,10 @@ use syntax::{
|
|||||||
match_ast,
|
match_ast,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{inlay_hints::closure_has_block_body, InlayHint, InlayHintsConfig, InlayKind};
|
use crate::{
|
||||||
|
inlay_hints::{closure_has_block_body, label_of_ty},
|
||||||
use super::label_of_ty;
|
InlayHint, InlayHintsConfig, InlayKind,
|
||||||
|
};
|
||||||
|
|
||||||
pub(super) fn hints(
|
pub(super) fn hints(
|
||||||
acc: &mut Vec<InlayHint>,
|
acc: &mut Vec<InlayHint>,
|
||||||
@ -50,6 +51,7 @@ pub(super) fn hints(
|
|||||||
},
|
},
|
||||||
kind: InlayKind::Type,
|
kind: InlayKind::Type,
|
||||||
label,
|
label,
|
||||||
|
text_edit: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
Some(())
|
Some(())
|
||||||
|
@ -49,7 +49,12 @@ pub(super) fn hints(
|
|||||||
(true, false) => "&",
|
(true, false) => "&",
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
acc.push(InlayHint { range, kind: InlayKind::BindingMode, label: r.to_string().into() });
|
acc.push(InlayHint {
|
||||||
|
range,
|
||||||
|
kind: InlayKind::BindingMode,
|
||||||
|
label: r.to_string().into(),
|
||||||
|
text_edit: None,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
match pat {
|
match pat {
|
||||||
ast::Pat::IdentPat(pat) if pat.ref_token().is_none() && pat.mut_token().is_none() => {
|
ast::Pat::IdentPat(pat) if pat.ref_token().is_none() && pat.mut_token().is_none() => {
|
||||||
@ -63,6 +68,7 @@ pub(super) fn hints(
|
|||||||
range: pat.syntax().text_range(),
|
range: pat.syntax().text_range(),
|
||||||
kind: InlayKind::BindingMode,
|
kind: InlayKind::BindingMode,
|
||||||
label: bm.to_string().into(),
|
label: bm.to_string().into(),
|
||||||
|
text_edit: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
ast::Pat::OrPat(pat) if !pattern_adjustments.is_empty() && outer_paren_pat.is_none() => {
|
ast::Pat::OrPat(pat) if !pattern_adjustments.is_empty() && outer_paren_pat.is_none() => {
|
||||||
|
@ -61,6 +61,7 @@ pub(super) fn hints(
|
|||||||
range: expr.syntax().text_range(),
|
range: expr.syntax().text_range(),
|
||||||
kind: InlayKind::Chaining,
|
kind: InlayKind::Chaining,
|
||||||
label: label_of_ty(famous_defs, config, ty)?,
|
label: label_of_ty(famous_defs, config, ty)?,
|
||||||
|
text_edit: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -120,6 +121,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
"",
|
"",
|
||||||
],
|
],
|
||||||
|
text_edit: None,
|
||||||
},
|
},
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range: 147..154,
|
range: 147..154,
|
||||||
@ -140,6 +142,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
"",
|
"",
|
||||||
],
|
],
|
||||||
|
text_edit: None,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
"#]],
|
"#]],
|
||||||
@ -205,6 +208,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
"",
|
"",
|
||||||
],
|
],
|
||||||
|
text_edit: None,
|
||||||
},
|
},
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range: 143..179,
|
range: 143..179,
|
||||||
@ -225,6 +229,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
"",
|
"",
|
||||||
],
|
],
|
||||||
|
text_edit: None,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
"#]],
|
"#]],
|
||||||
@ -274,6 +279,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
"",
|
"",
|
||||||
],
|
],
|
||||||
|
text_edit: None,
|
||||||
},
|
},
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range: 143..179,
|
range: 143..179,
|
||||||
@ -294,6 +300,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
"",
|
"",
|
||||||
],
|
],
|
||||||
|
text_edit: None,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
"#]],
|
"#]],
|
||||||
@ -357,6 +364,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
"<i32, bool>>",
|
"<i32, bool>>",
|
||||||
],
|
],
|
||||||
|
text_edit: None,
|
||||||
},
|
},
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range: 246..265,
|
range: 246..265,
|
||||||
@ -390,6 +398,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
"<i32, bool>>",
|
"<i32, bool>>",
|
||||||
],
|
],
|
||||||
|
text_edit: None,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
"#]],
|
"#]],
|
||||||
@ -455,6 +464,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
" = ()>",
|
" = ()>",
|
||||||
],
|
],
|
||||||
|
text_edit: None,
|
||||||
},
|
},
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range: 174..224,
|
range: 174..224,
|
||||||
@ -488,6 +498,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
" = ()>",
|
" = ()>",
|
||||||
],
|
],
|
||||||
|
text_edit: None,
|
||||||
},
|
},
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range: 174..206,
|
range: 174..206,
|
||||||
@ -521,6 +532,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
" = ()>",
|
" = ()>",
|
||||||
],
|
],
|
||||||
|
text_edit: None,
|
||||||
},
|
},
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range: 174..189,
|
range: 174..189,
|
||||||
@ -541,6 +553,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
"",
|
"",
|
||||||
],
|
],
|
||||||
|
text_edit: None,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
"#]],
|
"#]],
|
||||||
@ -590,6 +603,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
"",
|
"",
|
||||||
],
|
],
|
||||||
|
text_edit: None,
|
||||||
},
|
},
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range: 145..185,
|
range: 145..185,
|
||||||
@ -610,6 +624,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
"",
|
"",
|
||||||
],
|
],
|
||||||
|
text_edit: None,
|
||||||
},
|
},
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range: 145..168,
|
range: 145..168,
|
||||||
@ -630,6 +645,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
"",
|
"",
|
||||||
],
|
],
|
||||||
|
text_edit: None,
|
||||||
},
|
},
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range: 222..228,
|
range: 222..228,
|
||||||
@ -648,6 +664,7 @@ fn main() {
|
|||||||
tooltip: "",
|
tooltip: "",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
text_edit: None,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
"#]],
|
"#]],
|
||||||
|
@ -112,6 +112,7 @@ pub(super) fn hints(
|
|||||||
range: closing_token.text_range(),
|
range: closing_token.text_range(),
|
||||||
kind: InlayKind::ClosingBrace,
|
kind: InlayKind::ClosingBrace,
|
||||||
label: InlayHintLabel::simple(label, None, linked_location),
|
label: InlayHintLabel::simple(label, None, linked_location),
|
||||||
|
text_edit: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
None
|
None
|
||||||
|
@ -43,6 +43,7 @@ pub(super) fn hints(
|
|||||||
range: param_list.syntax().text_range(),
|
range: param_list.syntax().text_range(),
|
||||||
kind: InlayKind::ClosureReturnType,
|
kind: InlayKind::ClosureReturnType,
|
||||||
label: label_of_ty(famous_defs, config, ty)?,
|
label: label_of_ty(famous_defs, config, ty)?,
|
||||||
|
text_edit: None,
|
||||||
});
|
});
|
||||||
Some(())
|
Some(())
|
||||||
}
|
}
|
||||||
|
@ -75,6 +75,7 @@ fn variant_hints(
|
|||||||
})),
|
})),
|
||||||
None,
|
None,
|
||||||
),
|
),
|
||||||
|
text_edit: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
Some(())
|
Some(())
|
||||||
|
@ -25,6 +25,7 @@ pub(super) fn hints(
|
|||||||
range: t.text_range(),
|
range: t.text_range(),
|
||||||
kind: InlayKind::Lifetime,
|
kind: InlayKind::Lifetime,
|
||||||
label: label.into(),
|
label: label.into(),
|
||||||
|
text_edit: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let param_list = func.param_list()?;
|
let param_list = func.param_list()?;
|
||||||
@ -189,12 +190,14 @@ pub(super) fn hints(
|
|||||||
if is_empty { "" } else { ", " }
|
if is_empty { "" } else { ", " }
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
|
text_edit: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
(None, allocated_lifetimes) => acc.push(InlayHint {
|
(None, allocated_lifetimes) => acc.push(InlayHint {
|
||||||
range: func.name()?.syntax().text_range(),
|
range: func.name()?.syntax().text_range(),
|
||||||
kind: InlayKind::GenericParamList,
|
kind: InlayKind::GenericParamList,
|
||||||
label: format!("<{}>", allocated_lifetimes.iter().format(", "),).into(),
|
label: format!("<{}>", allocated_lifetimes.iter().format(", "),).into(),
|
||||||
|
text_edit: None,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
Some(())
|
Some(())
|
||||||
|
@ -34,6 +34,7 @@ pub(super) fn hints(
|
|||||||
range: t.text_range(),
|
range: t.text_range(),
|
||||||
kind: InlayKind::Lifetime,
|
kind: InlayKind::Lifetime,
|
||||||
label: "'static".to_owned().into(),
|
label: "'static".to_owned().into(),
|
||||||
|
text_edit: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,7 @@ pub(super) fn hints(
|
|||||||
range,
|
range,
|
||||||
kind: InlayKind::Parameter,
|
kind: InlayKind::Parameter,
|
||||||
label: InlayHintLabel::simple(param_name, None, linked_location),
|
label: InlayHintLabel::simple(param_name, None, linked_location),
|
||||||
|
text_edit: None,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -510,7 +510,7 @@ pub(crate) fn inlay_hint(
|
|||||||
| InlayKind::AdjustmentPostfix
|
| InlayKind::AdjustmentPostfix
|
||||||
| InlayKind::ClosingBrace => None,
|
| InlayKind::ClosingBrace => None,
|
||||||
},
|
},
|
||||||
text_edits: None,
|
text_edits: inlay_hint.text_edit.map(|it| text_edit_vec(line_index, it)),
|
||||||
data: None,
|
data: None,
|
||||||
tooltip,
|
tooltip,
|
||||||
label,
|
label,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user