mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Simplify inlay hints needs_resolve
This commit is contained in:
parent
f07489ada9
commit
3115fd8b41
15 changed files with 6 additions and 24 deletions
|
@ -151,13 +151,11 @@ pub struct InlayHint {
|
||||||
pub label: InlayHintLabel,
|
pub label: InlayHintLabel,
|
||||||
/// Text edit to apply when "accepting" this inlay hint.
|
/// Text edit to apply when "accepting" this inlay hint.
|
||||||
pub text_edit: Option<TextEdit>,
|
pub text_edit: Option<TextEdit>,
|
||||||
pub needs_resolve: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InlayHint {
|
impl InlayHint {
|
||||||
fn closing_paren_after(kind: InlayKind, range: TextRange) -> InlayHint {
|
fn closing_paren_after(kind: InlayKind, range: TextRange) -> InlayHint {
|
||||||
InlayHint {
|
InlayHint {
|
||||||
needs_resolve: false,
|
|
||||||
range,
|
range,
|
||||||
kind,
|
kind,
|
||||||
label: InlayHintLabel::from(")"),
|
label: InlayHintLabel::from(")"),
|
||||||
|
@ -167,9 +165,9 @@ impl InlayHint {
|
||||||
pad_right: false,
|
pad_right: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn opening_paren_before(kind: InlayKind, range: TextRange) -> InlayHint {
|
fn opening_paren_before(kind: InlayKind, range: TextRange) -> InlayHint {
|
||||||
InlayHint {
|
InlayHint {
|
||||||
needs_resolve: false,
|
|
||||||
range,
|
range,
|
||||||
kind,
|
kind,
|
||||||
label: InlayHintLabel::from("("),
|
label: InlayHintLabel::from("("),
|
||||||
|
@ -179,6 +177,10 @@ impl InlayHint {
|
||||||
pad_right: false,
|
pad_right: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn needs_resolve(&self) -> bool {
|
||||||
|
self.text_edit.is_some() || self.label.needs_resolve()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
@ -147,7 +147,6 @@ pub(super) fn hints(
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint {
|
||||||
needs_resolve: label.needs_resolve(),
|
|
||||||
range: expr.syntax().text_range(),
|
range: expr.syntax().text_range(),
|
||||||
pad_left: false,
|
pad_left: false,
|
||||||
pad_right: false,
|
pad_right: false,
|
||||||
|
|
|
@ -99,7 +99,6 @@ pub(super) fn hints(
|
||||||
None => pat.syntax().text_range(),
|
None => pat.syntax().text_range(),
|
||||||
};
|
};
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint {
|
||||||
needs_resolve: label.needs_resolve() || text_edit.is_some(),
|
|
||||||
range: match type_ascriptable {
|
range: match type_ascriptable {
|
||||||
Some(Some(t)) => text_range.cover(t.text_range()),
|
Some(Some(t)) => text_range.cover(t.text_range()),
|
||||||
_ => text_range,
|
_ => text_range,
|
||||||
|
|
|
@ -50,7 +50,6 @@ pub(super) fn hints(
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint {
|
||||||
needs_resolve: false,
|
|
||||||
range,
|
range,
|
||||||
kind: InlayKind::BindingMode,
|
kind: InlayKind::BindingMode,
|
||||||
label: r.into(),
|
label: r.into(),
|
||||||
|
@ -69,7 +68,6 @@ pub(super) fn hints(
|
||||||
hir::BindingMode::Ref(Mutability::Shared) => "ref",
|
hir::BindingMode::Ref(Mutability::Shared) => "ref",
|
||||||
};
|
};
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint {
|
||||||
needs_resolve: false,
|
|
||||||
range: pat.syntax().text_range(),
|
range: pat.syntax().text_range(),
|
||||||
kind: InlayKind::BindingMode,
|
kind: InlayKind::BindingMode,
|
||||||
label: bm.into(),
|
label: bm.into(),
|
||||||
|
|
|
@ -59,7 +59,6 @@ pub(super) fn hints(
|
||||||
}
|
}
|
||||||
let label = label_of_ty(famous_defs, config, &ty)?;
|
let label = label_of_ty(famous_defs, config, &ty)?;
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint {
|
||||||
needs_resolve: label.needs_resolve(),
|
|
||||||
range: expr.syntax().text_range(),
|
range: expr.syntax().text_range(),
|
||||||
kind: InlayKind::Chaining,
|
kind: InlayKind::Chaining,
|
||||||
label,
|
label,
|
||||||
|
|
|
@ -109,7 +109,6 @@ pub(super) fn hints(
|
||||||
|
|
||||||
let linked_location = name_range.map(|range| FileRange { file_id, range });
|
let linked_location = name_range.map(|range| FileRange { file_id, range });
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint {
|
||||||
needs_resolve: linked_location.is_some(),
|
|
||||||
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),
|
||||||
|
|
|
@ -32,7 +32,6 @@ pub(super) fn hints(
|
||||||
let range = closure.syntax().first_token()?.prev_token()?.text_range();
|
let range = closure.syntax().first_token()?.prev_token()?.text_range();
|
||||||
let range = TextRange::new(range.end() - TextSize::from(1), range.end());
|
let range = TextRange::new(range.end() - TextSize::from(1), range.end());
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint {
|
||||||
needs_resolve: false,
|
|
||||||
range,
|
range,
|
||||||
kind: InlayKind::ClosureCapture,
|
kind: InlayKind::ClosureCapture,
|
||||||
label: InlayHintLabel::from("move"),
|
label: InlayHintLabel::from("move"),
|
||||||
|
@ -45,7 +44,6 @@ pub(super) fn hints(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint {
|
||||||
needs_resolve: false,
|
|
||||||
range: move_kw_range,
|
range: move_kw_range,
|
||||||
kind: InlayKind::ClosureCapture,
|
kind: InlayKind::ClosureCapture,
|
||||||
label: InlayHintLabel::from("("),
|
label: InlayHintLabel::from("("),
|
||||||
|
@ -79,7 +77,6 @@ pub(super) fn hints(
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint {
|
||||||
needs_resolve: label.needs_resolve(),
|
|
||||||
range: move_kw_range,
|
range: move_kw_range,
|
||||||
kind: InlayKind::ClosureCapture,
|
kind: InlayKind::ClosureCapture,
|
||||||
label,
|
label,
|
||||||
|
@ -91,7 +88,6 @@ pub(super) fn hints(
|
||||||
|
|
||||||
if idx != last {
|
if idx != last {
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint {
|
||||||
needs_resolve: false,
|
|
||||||
range: move_kw_range,
|
range: move_kw_range,
|
||||||
kind: InlayKind::ClosureCapture,
|
kind: InlayKind::ClosureCapture,
|
||||||
label: InlayHintLabel::from(", "),
|
label: InlayHintLabel::from(", "),
|
||||||
|
@ -103,7 +99,6 @@ pub(super) fn hints(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint {
|
||||||
needs_resolve: false,
|
|
||||||
range: move_kw_range,
|
range: move_kw_range,
|
||||||
kind: InlayKind::ClosureCapture,
|
kind: InlayKind::ClosureCapture,
|
||||||
label: InlayHintLabel::from(")"),
|
label: InlayHintLabel::from(")"),
|
||||||
|
|
|
@ -64,7 +64,6 @@ pub(super) fn hints(
|
||||||
};
|
};
|
||||||
|
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint {
|
||||||
needs_resolve: label.needs_resolve() || text_edit.is_some(),
|
|
||||||
range: param_list.syntax().text_range(),
|
range: param_list.syntax().text_range(),
|
||||||
kind: InlayKind::Type,
|
kind: InlayKind::Type,
|
||||||
label,
|
label,
|
||||||
|
|
|
@ -79,7 +79,6 @@ fn variant_hints(
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint {
|
||||||
needs_resolve: label.needs_resolve(),
|
|
||||||
range: match eq_token {
|
range: match eq_token {
|
||||||
Some(t) => range.cover(t.text_range()),
|
Some(t) => range.cover(t.text_range()),
|
||||||
_ => range,
|
_ => range,
|
||||||
|
|
|
@ -22,7 +22,6 @@ pub(super) fn hints(
|
||||||
}
|
}
|
||||||
|
|
||||||
let mk_lt_hint = |t: SyntaxToken, label: String| InlayHint {
|
let mk_lt_hint = |t: SyntaxToken, label: String| InlayHint {
|
||||||
needs_resolve: false,
|
|
||||||
range: t.text_range(),
|
range: t.text_range(),
|
||||||
kind: InlayKind::Lifetime,
|
kind: InlayKind::Lifetime,
|
||||||
label: label.into(),
|
label: label.into(),
|
||||||
|
@ -184,7 +183,6 @@ pub(super) fn hints(
|
||||||
let angle_tok = gpl.l_angle_token()?;
|
let angle_tok = gpl.l_angle_token()?;
|
||||||
let is_empty = gpl.generic_params().next().is_none();
|
let is_empty = gpl.generic_params().next().is_none();
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint {
|
||||||
needs_resolve: false,
|
|
||||||
range: angle_tok.text_range(),
|
range: angle_tok.text_range(),
|
||||||
kind: InlayKind::Lifetime,
|
kind: InlayKind::Lifetime,
|
||||||
label: format!(
|
label: format!(
|
||||||
|
@ -200,7 +198,6 @@ pub(super) fn hints(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
(None, allocated_lifetimes) => acc.push(InlayHint {
|
(None, allocated_lifetimes) => acc.push(InlayHint {
|
||||||
needs_resolve: false,
|
|
||||||
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(),
|
||||||
|
|
|
@ -105,7 +105,6 @@ pub(super) fn hints(
|
||||||
pad_left: true,
|
pad_left: true,
|
||||||
pad_right: true,
|
pad_right: true,
|
||||||
kind: InlayKind::Drop,
|
kind: InlayKind::Drop,
|
||||||
needs_resolve: label.needs_resolve(),
|
|
||||||
label,
|
label,
|
||||||
text_edit: None,
|
text_edit: None,
|
||||||
})
|
})
|
||||||
|
|
|
@ -31,7 +31,6 @@ pub(super) fn hints(
|
||||||
if ty.lifetime().is_none() {
|
if ty.lifetime().is_none() {
|
||||||
let t = ty.amp_token()?;
|
let t = ty.amp_token()?;
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint {
|
||||||
needs_resolve: false,
|
|
||||||
range: t.text_range(),
|
range: t.text_range(),
|
||||||
kind: InlayKind::Lifetime,
|
kind: InlayKind::Lifetime,
|
||||||
label: "'static".into(),
|
label: "'static".into(),
|
||||||
|
|
|
@ -57,7 +57,6 @@ pub(super) fn hints(
|
||||||
let label =
|
let label =
|
||||||
InlayHintLabel::simple(format!("{param_name}{colon}"), None, linked_location);
|
InlayHintLabel::simple(format!("{param_name}{colon}"), None, linked_location);
|
||||||
InlayHint {
|
InlayHint {
|
||||||
needs_resolve: label.needs_resolve(),
|
|
||||||
range,
|
range,
|
||||||
kind: InlayKind::Parameter,
|
kind: InlayKind::Parameter,
|
||||||
label,
|
label,
|
||||||
|
|
|
@ -30,7 +30,6 @@ fn inlay_hint(token: SyntaxToken) -> InlayHint {
|
||||||
kind: crate::InlayKind::RangeExclusive,
|
kind: crate::InlayKind::RangeExclusive,
|
||||||
label: crate::InlayHintLabel::from("<"),
|
label: crate::InlayHintLabel::from("<"),
|
||||||
text_edit: None,
|
text_edit: None,
|
||||||
needs_resolve: false,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -446,7 +446,7 @@ pub(crate) fn inlay_hint(
|
||||||
file_id: FileId,
|
file_id: FileId,
|
||||||
inlay_hint: InlayHint,
|
inlay_hint: InlayHint,
|
||||||
) -> Cancellable<lsp_types::InlayHint> {
|
) -> Cancellable<lsp_types::InlayHint> {
|
||||||
let needs_resolve = inlay_hint.needs_resolve;
|
let needs_resolve = inlay_hint.needs_resolve();
|
||||||
let (label, tooltip, mut something_to_resolve) =
|
let (label, tooltip, mut something_to_resolve) =
|
||||||
inlay_hint_label(snap, fields_to_resolve, needs_resolve, inlay_hint.label)?;
|
inlay_hint_label(snap, fields_to_resolve, needs_resolve, inlay_hint.label)?;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue