internal: Expand the derive attribute into a pseudo expansion

This commit is contained in:
Lukas Wirth 2022-02-21 02:42:58 +01:00
parent 1fe3b2edd6
commit 7b89d5ede2
17 changed files with 178 additions and 155 deletions

View file

@ -18,11 +18,7 @@ use crate::{
Highlight, HlMod, HlTag,
};
pub(super) fn token(
sema: &Semantics<RootDatabase>,
krate: Option<hir::Crate>,
token: SyntaxToken,
) -> Option<Highlight> {
pub(super) fn token(sema: &Semantics<RootDatabase>, token: SyntaxToken) -> Option<Highlight> {
if let Some(comment) = ast::Comment::cast(token.clone()) {
let h = HlTag::Comment;
return Some(match comment.kind().doc {
@ -39,17 +35,10 @@ pub(super) fn token(
INT_NUMBER | FLOAT_NUMBER => HlTag::NumericLiteral.into(),
BYTE => HlTag::ByteLiteral.into(),
CHAR => HlTag::CharLiteral.into(),
IDENT => {
let tt = ast::TokenTree::cast(token.parent()?)?;
let ident = ast::Ident::cast(token)?;
IDENT if token.parent().and_then(ast::TokenTree::cast).is_some() => {
// from this point on we are inside a token tree, this only happens for identifiers
// that were not mapped down into macro invocations
(|| {
let attr = tt.parent_meta()?.parent_attr()?;
let res = sema.resolve_derive_ident(&attr, &ident)?;
Some(highlight_def(sema, krate, Definition::from(res)))
})()
.unwrap_or_else(|| HlTag::None.into())
HlTag::None.into()
}
p if p.is_punct() => punctuation(sema, token, p),
k if k.is_keyword() => keyword(sema, token, k)?,