Remove unnecessary Hint suffix on InlayKind variants

This commit is contained in:
Lukas Wirth 2023-01-14 12:20:12 +01:00
parent 60075a6625
commit f2444b2a40
13 changed files with 87 additions and 95 deletions

View file

@ -86,17 +86,17 @@ pub enum AdjustmentHintsMode {
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum InlayKind { pub enum InlayKind {
BindingModeHint, BindingMode,
ChainingHint, Chaining,
ClosingBraceHint, ClosingBrace,
ClosureReturnTypeHint, ClosureReturnType,
GenericParamListHint, GenericParamList,
AdjustmentHint, Adjustment,
AdjustmentHintPostfix, AdjustmentPostfix,
LifetimeHint, Lifetime,
ParameterHint, Parameter,
TypeHint, Type,
DiscriminantHint, Discriminant,
OpeningParenthesis, OpeningParenthesis,
ClosingParenthesis, ClosingParenthesis,
} }

View file

@ -97,11 +97,7 @@ pub(super) fn hints(
}; };
acc.push(InlayHint { acc.push(InlayHint {
range: expr.syntax().text_range(), range: expr.syntax().text_range(),
kind: if postfix { kind: if postfix { InlayKind::AdjustmentPostfix } else { InlayKind::Adjustment },
InlayKind::AdjustmentHintPostfix
} else {
InlayKind::AdjustmentHint
},
label: if postfix { format!(".{}", text.trim_end()).into() } else { text.into() }, label: if postfix { format!(".{}", text.trim_end()).into() } else { text.into() },
}); });
} }

View file

@ -48,7 +48,7 @@ pub(super) fn hints(
Some(name) => name.syntax().text_range(), Some(name) => name.syntax().text_range(),
None => pat.syntax().text_range(), None => pat.syntax().text_range(),
}, },
kind: InlayKind::TypeHint, kind: InlayKind::Type,
label, label,
}); });
@ -316,14 +316,14 @@ fn main(a: SliceIter<'_, Container>) {
[ [
InlayHint { InlayHint {
range: 484..554, range: 484..554,
kind: ChainingHint, kind: Chaining,
label: [ label: [
"impl Iterator<Item = impl Iterator<Item = &&str>>", "impl Iterator<Item = impl Iterator<Item = &&str>>",
], ],
}, },
InlayHint { InlayHint {
range: 484..485, range: 484..485,
kind: ChainingHint, kind: Chaining,
label: [ label: [
"", "",
InlayHintLabelPart { InlayHintLabelPart {

View file

@ -40,11 +40,7 @@ pub(super) fn hints(
(true, false) => "&", (true, false) => "&",
_ => return, _ => return,
}; };
acc.push(InlayHint { acc.push(InlayHint { range, kind: InlayKind::BindingMode, label: r.to_string().into() });
range,
kind: InlayKind::BindingModeHint,
label: r.to_string().into(),
});
}); });
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() => {
@ -56,7 +52,7 @@ pub(super) fn hints(
}; };
acc.push(InlayHint { acc.push(InlayHint {
range: pat.syntax().text_range(), range: pat.syntax().text_range(),
kind: InlayKind::BindingModeHint, kind: InlayKind::BindingMode,
label: bm.to_string().into(), label: bm.to_string().into(),
}); });
} }

View file

@ -59,7 +59,7 @@ pub(super) fn hints(
} }
acc.push(InlayHint { acc.push(InlayHint {
range: expr.syntax().text_range(), range: expr.syntax().text_range(),
kind: InlayKind::ChainingHint, kind: InlayKind::Chaining,
label: label_of_ty(famous_defs, config, ty)?, label: label_of_ty(famous_defs, config, ty)?,
}); });
} }
@ -110,7 +110,7 @@ fn main() {
[ [
InlayHint { InlayHint {
range: 147..172, range: 147..172,
kind: ChainingHint, kind: Chaining,
label: [ label: [
"", "",
InlayHintLabelPart { InlayHintLabelPart {
@ -130,7 +130,7 @@ fn main() {
}, },
InlayHint { InlayHint {
range: 147..154, range: 147..154,
kind: ChainingHint, kind: Chaining,
label: [ label: [
"", "",
InlayHintLabelPart { InlayHintLabelPart {
@ -195,14 +195,14 @@ fn main() {
[ [
InlayHint { InlayHint {
range: 143..190, range: 143..190,
kind: ChainingHint, kind: Chaining,
label: [ label: [
"C", "C",
], ],
}, },
InlayHint { InlayHint {
range: 143..179, range: 143..179,
kind: ChainingHint, kind: Chaining,
label: [ label: [
"B", "B",
], ],
@ -238,7 +238,7 @@ fn main() {
[ [
InlayHint { InlayHint {
range: 143..190, range: 143..190,
kind: ChainingHint, kind: Chaining,
label: [ label: [
"", "",
InlayHintLabelPart { InlayHintLabelPart {
@ -258,7 +258,7 @@ fn main() {
}, },
InlayHint { InlayHint {
range: 143..179, range: 143..179,
kind: ChainingHint, kind: Chaining,
label: [ label: [
"", "",
InlayHintLabelPart { InlayHintLabelPart {
@ -308,7 +308,7 @@ fn main() {
[ [
InlayHint { InlayHint {
range: 246..283, range: 246..283,
kind: ChainingHint, kind: Chaining,
label: [ label: [
"", "",
InlayHintLabelPart { InlayHintLabelPart {
@ -341,7 +341,7 @@ fn main() {
}, },
InlayHint { InlayHint {
range: 246..265, range: 246..265,
kind: ChainingHint, kind: Chaining,
label: [ label: [
"", "",
InlayHintLabelPart { InlayHintLabelPart {
@ -406,28 +406,28 @@ fn main() {
[ [
InlayHint { InlayHint {
range: 174..241, range: 174..241,
kind: ChainingHint, kind: Chaining,
label: [ label: [
"impl Iterator<Item = ()>", "impl Iterator<Item = ()>",
], ],
}, },
InlayHint { InlayHint {
range: 174..224, range: 174..224,
kind: ChainingHint, kind: Chaining,
label: [ label: [
"impl Iterator<Item = ()>", "impl Iterator<Item = ()>",
], ],
}, },
InlayHint { InlayHint {
range: 174..206, range: 174..206,
kind: ChainingHint, kind: Chaining,
label: [ label: [
"impl Iterator<Item = ()>", "impl Iterator<Item = ()>",
], ],
}, },
InlayHint { InlayHint {
range: 174..189, range: 174..189,
kind: ChainingHint, kind: Chaining,
label: [ label: [
"&mut ", "&mut ",
InlayHintLabelPart { InlayHintLabelPart {
@ -476,7 +476,7 @@ fn main() {
[ [
InlayHint { InlayHint {
range: 124..130, range: 124..130,
kind: TypeHint, kind: Type,
label: [ label: [
"", "",
InlayHintLabelPart { InlayHintLabelPart {
@ -496,7 +496,7 @@ fn main() {
}, },
InlayHint { InlayHint {
range: 145..185, range: 145..185,
kind: ChainingHint, kind: Chaining,
label: [ label: [
"", "",
InlayHintLabelPart { InlayHintLabelPart {
@ -516,7 +516,7 @@ fn main() {
}, },
InlayHint { InlayHint {
range: 145..168, range: 145..168,
kind: ChainingHint, kind: Chaining,
label: [ label: [
"", "",
InlayHintLabelPart { InlayHintLabelPart {
@ -536,7 +536,7 @@ fn main() {
}, },
InlayHint { InlayHint {
range: 222..228, range: 222..228,
kind: ParameterHint, kind: Parameter,
label: [ label: [
InlayHintLabelPart { InlayHintLabelPart {
text: "self", text: "self",

View file

@ -113,7 +113,7 @@ pub(super) fn hints(
.flatten(); .flatten();
acc.push(InlayHint { acc.push(InlayHint {
range: closing_token.text_range(), range: closing_token.text_range(),
kind: InlayKind::ClosingBraceHint, kind: InlayKind::ClosingBrace,
label: InlayHintLabel::simple(label, None, linked_location), label: InlayHintLabel::simple(label, None, linked_location),
}); });

View file

@ -41,7 +41,7 @@ pub(super) fn hints(
} }
acc.push(InlayHint { acc.push(InlayHint {
range: param_list.syntax().text_range(), range: param_list.syntax().text_range(),
kind: InlayKind::ClosureReturnTypeHint, kind: InlayKind::ClosureReturnType,
label: label_of_ty(famous_defs, config, ty)?, label: label_of_ty(famous_defs, config, ty)?,
}); });
Some(()) Some(())

View file

@ -43,7 +43,7 @@ pub(super) fn hints(
Some(field_list) => name.syntax().text_range().cover(field_list.syntax().text_range()), Some(field_list) => name.syntax().text_range().cover(field_list.syntax().text_range()),
None => name.syntax().text_range(), None => name.syntax().text_range(),
}, },
kind: InlayKind::DiscriminantHint, kind: InlayKind::Discriminant,
label: InlayHintLabel::simple( label: InlayHintLabel::simple(
match &d { match &d {
Ok(v) => format!("{}", v), Ok(v) => format!("{}", v),

View file

@ -23,7 +23,7 @@ pub(super) fn hints(
let mk_lt_hint = |t: SyntaxToken, label: String| InlayHint { let mk_lt_hint = |t: SyntaxToken, label: String| InlayHint {
range: t.text_range(), range: t.text_range(),
kind: InlayKind::LifetimeHint, kind: InlayKind::Lifetime,
label: label.into(), label: label.into(),
}; };
@ -182,7 +182,7 @@ pub(super) fn hints(
let is_empty = gpl.generic_params().next().is_none(); let is_empty = gpl.generic_params().next().is_none();
acc.push(InlayHint { acc.push(InlayHint {
range: angle_tok.text_range(), range: angle_tok.text_range(),
kind: InlayKind::LifetimeHint, kind: InlayKind::Lifetime,
label: format!( label: format!(
"{}{}", "{}{}",
allocated_lifetimes.iter().format(", "), allocated_lifetimes.iter().format(", "),
@ -193,7 +193,7 @@ pub(super) fn hints(
} }
(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::GenericParamListHint, kind: InlayKind::GenericParamList,
label: format!("<{}>", allocated_lifetimes.iter().format(", "),).into(), label: format!("<{}>", allocated_lifetimes.iter().format(", "),).into(),
}), }),
} }

View file

@ -32,7 +32,7 @@ pub(super) fn hints(
let t = ty.amp_token()?; let t = ty.amp_token()?;
acc.push(InlayHint { acc.push(InlayHint {
range: t.text_range(), range: t.text_range(),
kind: InlayKind::LifetimeHint, kind: InlayKind::Lifetime,
label: "'static".to_owned().into(), label: "'static".to_owned().into(),
}); });
} }

View file

@ -55,7 +55,7 @@ pub(super) fn hints(
InlayHint { InlayHint {
range, range,
kind: InlayKind::ParameterHint, kind: InlayKind::Parameter,
label: InlayHintLabel::simple(param_name, None, linked_location), label: InlayHintLabel::simple(param_name, None, linked_location),
} }
}); });

View file

@ -431,10 +431,10 @@ pub(crate) fn inlay_hint(
mut inlay_hint: InlayHint, mut inlay_hint: InlayHint,
) -> Cancellable<lsp_types::InlayHint> { ) -> Cancellable<lsp_types::InlayHint> {
match inlay_hint.kind { match inlay_hint.kind {
InlayKind::ParameterHint if render_colons => inlay_hint.label.append_str(":"), InlayKind::Parameter if render_colons => inlay_hint.label.append_str(":"),
InlayKind::TypeHint if render_colons => inlay_hint.label.prepend_str(": "), InlayKind::Type if render_colons => inlay_hint.label.prepend_str(": "),
InlayKind::ClosureReturnTypeHint => inlay_hint.label.prepend_str(" -> "), InlayKind::ClosureReturnType => inlay_hint.label.prepend_str(" -> "),
InlayKind::DiscriminantHint => inlay_hint.label.prepend_str(" = "), InlayKind::Discriminant => inlay_hint.label.prepend_str(" = "),
_ => {} _ => {}
} }
@ -444,64 +444,64 @@ pub(crate) fn inlay_hint(
position: match inlay_hint.kind { position: match inlay_hint.kind {
// before annotated thing // before annotated thing
InlayKind::OpeningParenthesis InlayKind::OpeningParenthesis
| InlayKind::ParameterHint | InlayKind::Parameter
| InlayKind::AdjustmentHint | InlayKind::Adjustment
| InlayKind::BindingModeHint => position(line_index, inlay_hint.range.start()), | InlayKind::BindingMode => position(line_index, inlay_hint.range.start()),
// after annotated thing // after annotated thing
InlayKind::ClosureReturnTypeHint InlayKind::ClosureReturnType
| InlayKind::TypeHint | InlayKind::Type
| InlayKind::DiscriminantHint | InlayKind::Discriminant
| InlayKind::ChainingHint | InlayKind::Chaining
| InlayKind::GenericParamListHint | InlayKind::GenericParamList
| InlayKind::ClosingParenthesis | InlayKind::ClosingParenthesis
| InlayKind::AdjustmentHintPostfix | InlayKind::AdjustmentPostfix
| InlayKind::LifetimeHint | InlayKind::Lifetime
| InlayKind::ClosingBraceHint => position(line_index, inlay_hint.range.end()), | InlayKind::ClosingBrace => position(line_index, inlay_hint.range.end()),
}, },
padding_left: Some(match inlay_hint.kind { padding_left: Some(match inlay_hint.kind {
InlayKind::TypeHint => !render_colons, InlayKind::Type => !render_colons,
InlayKind::ChainingHint | InlayKind::ClosingBraceHint => true, InlayKind::Chaining | InlayKind::ClosingBrace => true,
InlayKind::ClosingParenthesis InlayKind::ClosingParenthesis
| InlayKind::DiscriminantHint | InlayKind::Discriminant
| InlayKind::OpeningParenthesis | InlayKind::OpeningParenthesis
| InlayKind::BindingModeHint | InlayKind::BindingMode
| InlayKind::ClosureReturnTypeHint | InlayKind::ClosureReturnType
| InlayKind::GenericParamListHint | InlayKind::GenericParamList
| InlayKind::AdjustmentHint | InlayKind::Adjustment
| InlayKind::AdjustmentHintPostfix | InlayKind::AdjustmentPostfix
| InlayKind::LifetimeHint | InlayKind::Lifetime
| InlayKind::ParameterHint => false, | InlayKind::Parameter => false,
}), }),
padding_right: Some(match inlay_hint.kind { padding_right: Some(match inlay_hint.kind {
InlayKind::ClosingParenthesis InlayKind::ClosingParenthesis
| InlayKind::OpeningParenthesis | InlayKind::OpeningParenthesis
| InlayKind::ChainingHint | InlayKind::Chaining
| InlayKind::ClosureReturnTypeHint | InlayKind::ClosureReturnType
| InlayKind::GenericParamListHint | InlayKind::GenericParamList
| InlayKind::AdjustmentHint | InlayKind::Adjustment
| InlayKind::AdjustmentHintPostfix | InlayKind::AdjustmentPostfix
| InlayKind::TypeHint | InlayKind::Type
| InlayKind::DiscriminantHint | InlayKind::Discriminant
| InlayKind::ClosingBraceHint => false, | InlayKind::ClosingBrace => false,
InlayKind::BindingModeHint => { InlayKind::BindingMode => {
matches!(&label, lsp_types::InlayHintLabel::String(s) if s != "&") matches!(&label, lsp_types::InlayHintLabel::String(s) if s != "&")
} }
InlayKind::ParameterHint | InlayKind::LifetimeHint => true, InlayKind::Parameter | InlayKind::Lifetime => true,
}), }),
kind: match inlay_hint.kind { kind: match inlay_hint.kind {
InlayKind::ParameterHint => Some(lsp_types::InlayHintKind::PARAMETER), InlayKind::Parameter => Some(lsp_types::InlayHintKind::PARAMETER),
InlayKind::ClosureReturnTypeHint | InlayKind::TypeHint | InlayKind::ChainingHint => { InlayKind::ClosureReturnType | InlayKind::Type | InlayKind::Chaining => {
Some(lsp_types::InlayHintKind::TYPE) Some(lsp_types::InlayHintKind::TYPE)
} }
InlayKind::ClosingParenthesis InlayKind::ClosingParenthesis
| InlayKind::DiscriminantHint | InlayKind::Discriminant
| InlayKind::OpeningParenthesis | InlayKind::OpeningParenthesis
| InlayKind::BindingModeHint | InlayKind::BindingMode
| InlayKind::GenericParamListHint | InlayKind::GenericParamList
| InlayKind::LifetimeHint | InlayKind::Lifetime
| InlayKind::AdjustmentHint | InlayKind::Adjustment
| InlayKind::AdjustmentHintPostfix | InlayKind::AdjustmentPostfix
| InlayKind::ClosingBraceHint => None, | InlayKind::ClosingBrace => None,
}, },
text_edits: None, text_edits: None,
data: None, data: None,

View file

@ -1,5 +1,5 @@
<!--- <!---
lsp_ext.rs hash: 45bd7985265725c5 lsp_ext.rs hash: d296ce1226e3568d
If you need to change the above hash to make the test pass, please check if you If you need to change the above hash to make the test pass, please check if you
need to adjust this doc as well and ping this issue: need to adjust this doc as well and ping this issue: