pub fn try_resolve_derive_input_at(
    sema: &Semantics<RootDatabase>,
    derive_attr: &ast::Attr,
    cursor: &SyntaxToken,
) -> Option<MacroDef> {
    use itertools::Itertools;
    if cursor.kind() != T![ident] {
        return None;
    }
    let tt = match derive_attr.as_simple_call() {
        Some((name, tt))
            if name == "derive" && tt.syntax().text_range().contains_range(cursor.text_range()) =>
        {
            tt
        }
        _ => return None,
    };
    let tokens: Vec<_> = cursor
        .siblings_with_tokens(Direction::Prev)
        .flat_map(SyntaxElement::into_token)
        .take_while(|tok| tok.kind() != T!['('] && tok.kind() != T![,])
        .collect();
    let path = ast::Path::parse(&tokens.into_iter().rev().join("")).ok()?;
    match sema.scope(tt.syntax()).speculative_resolve(&path) {
        Some(hir::PathResolution::Macro(makro)) if makro.kind() == hir::MacroKind::Derive => {
            Some(makro)
        }
        _ => None,
    }
}
/// Resolves the path at the cursor token as a derive macro if it inside a token tree of a derive attribute.
Resolves the path at the cursor token as a derive macro if it inside a token tree of a derive attribute.
Resolves the path at the cursor token as a derive macro if it inside a token tree of a derive attribute .
pub fn try_resolve_derive_input_at(
    sema: &Semantics<RootDatabase>,
    derive_attr: &ast::Attr,
    cursor: &SyntaxToken,
) -> Option<MacroDef> {
    use itertools::Itertools;
    if cursor.kind() != T![ident] {
        return None;
    }
    let tt = match derive_attr.as_simple_call() {
        Some((name, tt))
            if name == "derive" && tt.syntax().text_range().contains_range(cursor.text_range()) =>
        {
            tt
        }
        _ => return None,
    };
    let tokens: Vec<_> = cursor
        .siblings_with_tokens(Direction::Prev)
        .flat_map(SyntaxElement::into_token)
        .take_while(|tok| tok.kind() != T!['('] && tok.kind() != T![,])
        .collect();
    let path = ast::Path::parse(&tokens.into_iter().rev().join("")).ok()?;
    match sema.scope(tt.syntax()).speculative_resolve(&path) {
        Some(hir::PathResolution::Macro(makro)) if makro.kind() == hir::MacroKind::Derive => {
            Some(makro)
        }
        _ => None,
    }
}
pub fn try_resolve_derive_input_at ( sema : & Semantics < RootDatabase > , derive_attr : & ast :: Attr , cursor : & SyntaxToken , ) -> Option < MacroDef > { use itertools :: Itertools ; if cursor . kind ( ) != T ! [ ident ] { return None ; } let tt = match derive_attr . as_simple_call ( ) { Some ( ( name , tt ) ) if name == " " && tt . syntax ( ) . text_range ( ) . contains_range ( cursor . text_range ( ) ) => { tt } _ => return None , } ; let tokens : Vec < _ > = cursor . siblings_with_tokens ( Direction :: Prev ) . flat_map ( SyntaxElement :: into_token ) . take_while ( | tok | tok . kind ( ) != T ! [ '(' ] && tok . kind ( ) != T ! [ ] ) . collect ( ) ; let path = ast :: Path :: parse ( & tokens . into_iter ( ) . rev ( ) . join ( " " ) ) . ok ( ) ? ; match sema . scope ( tt . syntax ( ) ) . speculative_resolve ( & path ) { Some ( hir :: PathResolution :: Macro ( makro ) ) if makro . kind ( ) == hir :: MacroKind :: Derive => { Some ( makro ) } _ => None , } }
Resolves the path at the cursor token as a derive macro if it inside a token tree of a derive attribute.
Resolves the path at the cursor token as a derive macro if it inside a token tree of a derive attribute .
sema
&Semantics<RootDatabase>
derive_attr
&ast::Attr
cursor
&SyntaxToken