mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-21 11:23:03 +00:00
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},
|
||||
match_ast, NodeOrToken, SyntaxNode, TextRange,
|
||||
};
|
||||
use text_edit::TextEdit;
|
||||
|
||||
use crate::{navigation_target::TryToNav, FileId};
|
||||
|
||||
@ -113,14 +114,26 @@ pub struct InlayHint {
|
||||
pub kind: InlayKind,
|
||||
/// The actual label to show in the inlay hint.
|
||||
pub label: InlayHintLabel,
|
||||
/// Text edit to apply when "accepting" this inlay hint.
|
||||
pub text_edit: Option<TextEdit>,
|
||||
}
|
||||
|
||||
impl 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 {
|
||||
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,
|
||||
),
|
||||
text_edit: None,
|
||||
});
|
||||
}
|
||||
if !postfix && needs_inner_parens {
|
||||
|
@ -12,9 +12,10 @@ use syntax::{
|
||||
match_ast,
|
||||
};
|
||||
|
||||
use crate::{inlay_hints::closure_has_block_body, InlayHint, InlayHintsConfig, InlayKind};
|
||||
|
||||
use super::label_of_ty;
|
||||
use crate::{
|
||||
inlay_hints::{closure_has_block_body, label_of_ty},
|
||||
InlayHint, InlayHintsConfig, InlayKind,
|
||||
};
|
||||
|
||||
pub(super) fn hints(
|
||||
acc: &mut Vec<InlayHint>,
|
||||
@ -50,6 +51,7 @@ pub(super) fn hints(
|
||||
},
|
||||
kind: InlayKind::Type,
|
||||
label,
|
||||
text_edit: None,
|
||||
});
|
||||
|
||||
Some(())
|
||||
|
@ -49,7 +49,12 @@ pub(super) fn hints(
|
||||
(true, false) => "&",
|
||||
_ => 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 {
|
||||
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(),
|
||||
kind: InlayKind::BindingMode,
|
||||
label: bm.to_string().into(),
|
||||
text_edit: 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(),
|
||||
kind: InlayKind::Chaining,
|
||||
label: label_of_ty(famous_defs, config, ty)?,
|
||||
text_edit: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -120,6 +121,7 @@ fn main() {
|
||||
},
|
||||
"",
|
||||
],
|
||||
text_edit: None,
|
||||
},
|
||||
InlayHint {
|
||||
range: 147..154,
|
||||
@ -140,6 +142,7 @@ fn main() {
|
||||
},
|
||||
"",
|
||||
],
|
||||
text_edit: None,
|
||||
},
|
||||
]
|
||||
"#]],
|
||||
@ -205,6 +208,7 @@ fn main() {
|
||||
},
|
||||
"",
|
||||
],
|
||||
text_edit: None,
|
||||
},
|
||||
InlayHint {
|
||||
range: 143..179,
|
||||
@ -225,6 +229,7 @@ fn main() {
|
||||
},
|
||||
"",
|
||||
],
|
||||
text_edit: None,
|
||||
},
|
||||
]
|
||||
"#]],
|
||||
@ -274,6 +279,7 @@ fn main() {
|
||||
},
|
||||
"",
|
||||
],
|
||||
text_edit: None,
|
||||
},
|
||||
InlayHint {
|
||||
range: 143..179,
|
||||
@ -294,6 +300,7 @@ fn main() {
|
||||
},
|
||||
"",
|
||||
],
|
||||
text_edit: None,
|
||||
},
|
||||
]
|
||||
"#]],
|
||||
@ -357,6 +364,7 @@ fn main() {
|
||||
},
|
||||
"<i32, bool>>",
|
||||
],
|
||||
text_edit: None,
|
||||
},
|
||||
InlayHint {
|
||||
range: 246..265,
|
||||
@ -390,6 +398,7 @@ fn main() {
|
||||
},
|
||||
"<i32, bool>>",
|
||||
],
|
||||
text_edit: None,
|
||||
},
|
||||
]
|
||||
"#]],
|
||||
@ -455,6 +464,7 @@ fn main() {
|
||||
},
|
||||
" = ()>",
|
||||
],
|
||||
text_edit: None,
|
||||
},
|
||||
InlayHint {
|
||||
range: 174..224,
|
||||
@ -488,6 +498,7 @@ fn main() {
|
||||
},
|
||||
" = ()>",
|
||||
],
|
||||
text_edit: None,
|
||||
},
|
||||
InlayHint {
|
||||
range: 174..206,
|
||||
@ -521,6 +532,7 @@ fn main() {
|
||||
},
|
||||
" = ()>",
|
||||
],
|
||||
text_edit: None,
|
||||
},
|
||||
InlayHint {
|
||||
range: 174..189,
|
||||
@ -541,6 +553,7 @@ fn main() {
|
||||
},
|
||||
"",
|
||||
],
|
||||
text_edit: None,
|
||||
},
|
||||
]
|
||||
"#]],
|
||||
@ -590,6 +603,7 @@ fn main() {
|
||||
},
|
||||
"",
|
||||
],
|
||||
text_edit: None,
|
||||
},
|
||||
InlayHint {
|
||||
range: 145..185,
|
||||
@ -610,6 +624,7 @@ fn main() {
|
||||
},
|
||||
"",
|
||||
],
|
||||
text_edit: None,
|
||||
},
|
||||
InlayHint {
|
||||
range: 145..168,
|
||||
@ -630,6 +645,7 @@ fn main() {
|
||||
},
|
||||
"",
|
||||
],
|
||||
text_edit: None,
|
||||
},
|
||||
InlayHint {
|
||||
range: 222..228,
|
||||
@ -648,6 +664,7 @@ fn main() {
|
||||
tooltip: "",
|
||||
},
|
||||
],
|
||||
text_edit: None,
|
||||
},
|
||||
]
|
||||
"#]],
|
||||
|
@ -112,6 +112,7 @@ pub(super) fn hints(
|
||||
range: closing_token.text_range(),
|
||||
kind: InlayKind::ClosingBrace,
|
||||
label: InlayHintLabel::simple(label, None, linked_location),
|
||||
text_edit: None,
|
||||
});
|
||||
|
||||
None
|
||||
|
@ -43,6 +43,7 @@ pub(super) fn hints(
|
||||
range: param_list.syntax().text_range(),
|
||||
kind: InlayKind::ClosureReturnType,
|
||||
label: label_of_ty(famous_defs, config, ty)?,
|
||||
text_edit: None,
|
||||
});
|
||||
Some(())
|
||||
}
|
||||
|
@ -75,6 +75,7 @@ fn variant_hints(
|
||||
})),
|
||||
None,
|
||||
),
|
||||
text_edit: None,
|
||||
});
|
||||
|
||||
Some(())
|
||||
|
@ -25,6 +25,7 @@ pub(super) fn hints(
|
||||
range: t.text_range(),
|
||||
kind: InlayKind::Lifetime,
|
||||
label: label.into(),
|
||||
text_edit: None,
|
||||
};
|
||||
|
||||
let param_list = func.param_list()?;
|
||||
@ -189,12 +190,14 @@ pub(super) fn hints(
|
||||
if is_empty { "" } else { ", " }
|
||||
)
|
||||
.into(),
|
||||
text_edit: None,
|
||||
});
|
||||
}
|
||||
(None, allocated_lifetimes) => acc.push(InlayHint {
|
||||
range: func.name()?.syntax().text_range(),
|
||||
kind: InlayKind::GenericParamList,
|
||||
label: format!("<{}>", allocated_lifetimes.iter().format(", "),).into(),
|
||||
text_edit: None,
|
||||
}),
|
||||
}
|
||||
Some(())
|
||||
|
@ -34,6 +34,7 @@ pub(super) fn hints(
|
||||
range: t.text_range(),
|
||||
kind: InlayKind::Lifetime,
|
||||
label: "'static".to_owned().into(),
|
||||
text_edit: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ pub(super) fn hints(
|
||||
range,
|
||||
kind: InlayKind::Parameter,
|
||||
label: InlayHintLabel::simple(param_name, None, linked_location),
|
||||
text_edit: None,
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -510,7 +510,7 @@ pub(crate) fn inlay_hint(
|
||||
| InlayKind::AdjustmentPostfix
|
||||
| InlayKind::ClosingBrace => None,
|
||||
},
|
||||
text_edits: None,
|
||||
text_edits: inlay_hint.text_edit.map(|it| text_edit_vec(line_index, it)),
|
||||
data: None,
|
||||
tooltip,
|
||||
label,
|
||||
|
Loading…
Reference in New Issue
Block a user