mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Split inlay hints into modules
This commit is contained in:
parent
ccbf8fef9b
commit
191cfba9d2
10 changed files with 1096 additions and 1017 deletions
39
crates/ide/src/inlay_hints/implicit_static.rs
Normal file
39
crates/ide/src/inlay_hints/implicit_static.rs
Normal file
|
@ -0,0 +1,39 @@
|
|||
use either::Either;
|
||||
use syntax::{
|
||||
ast::{self, AstNode},
|
||||
SyntaxKind,
|
||||
};
|
||||
|
||||
use crate::{InlayHint, InlayHintsConfig, InlayKind, InlayTooltip, LifetimeElisionHints};
|
||||
|
||||
pub(super) fn hints(
|
||||
acc: &mut Vec<InlayHint>,
|
||||
config: &InlayHintsConfig,
|
||||
statik_or_const: Either<ast::Static, ast::Const>,
|
||||
) -> Option<()> {
|
||||
if config.lifetime_elision_hints != LifetimeElisionHints::Always {
|
||||
return None;
|
||||
}
|
||||
|
||||
if let Either::Right(it) = &statik_or_const {
|
||||
if ast::AssocItemList::can_cast(
|
||||
it.syntax().parent().map_or(SyntaxKind::EOF, |it| it.kind()),
|
||||
) {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(ast::Type::RefType(ty)) = statik_or_const.either(|it| it.ty(), |it| it.ty()) {
|
||||
if ty.lifetime().is_none() {
|
||||
let t = ty.amp_token()?;
|
||||
acc.push(InlayHint {
|
||||
range: t.text_range(),
|
||||
kind: InlayKind::LifetimeHint,
|
||||
label: "'static".to_owned().into(),
|
||||
tooltip: Some(InlayTooltip::String("Elided static lifetime".into())),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Some(())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue