pub fn expand_speculative(
    db: &dyn AstDatabase,
    actual_macro_call: MacroCallId,
    speculative_args: &ast::TokenTree,
    token_to_map: SyntaxToken,
) -> Option<(SyntaxNode, SyntaxToken)> {
    let (tt, tmap_1) = mbe::syntax_node_to_token_tree(speculative_args.syntax());
    let range =
        token_to_map.text_range().checked_sub(speculative_args.syntax().text_range().start())?;
    let token_id = tmap_1.token_by_range(range)?;

    let macro_def = {
        let loc: MacroCallLoc = db.lookup_intern_macro(actual_macro_call);
        db.macro_def(loc.def)?
    };

    let speculative_expansion = macro_def.expand(db, actual_macro_call, &tt);

    let fragment_kind = macro_fragment_kind(db, actual_macro_call);

    let (node, tmap_2) =
        mbe::token_tree_to_syntax_node(&speculative_expansion.value, fragment_kind).ok()?;

    let token_id = macro_def.map_id_down(token_id);
    let range = tmap_2.range_by_token(token_id, token_to_map.kind())?;
    let token = node.syntax_node().covering_element(range).into_token()?;
    Some((node.syntax_node(), token))
}
/// This expands the given macro call, but with different arguments. This is
/// used for completion, where we want to see what 'would happen' if we insert a
/// token. The `token_to_map` mapped down into the expansion, with the mapped
/// token returned.
This expands the given macro call, but with different arguments. This is
used for completion, where we want to see what 'would happen' if we insert a
token. The `token_to_map` mapped down into the expansion, with the mapped
token returned.
This expands the given macro call but with different arguments . This is used for completion where we want to see what ' would happen ' if we insert a token . The ` token_to_map ` mapped down into the expansion with the mapped token returned .
pub fn expand_speculative(
    db: &dyn AstDatabase,
    actual_macro_call: MacroCallId,
    speculative_args: &ast::TokenTree,
    token_to_map: SyntaxToken,
) -> Option<(SyntaxNode, SyntaxToken)> {
    let (tt, tmap_1) = mbe::syntax_node_to_token_tree(speculative_args.syntax());
    let range =
        token_to_map.text_range().checked_sub(speculative_args.syntax().text_range().start())?;
    let token_id = tmap_1.token_by_range(range)?;
    let macro_def = {
        let loc: MacroCallLoc = db.lookup_intern_macro(actual_macro_call);
        db.macro_def(loc.def)?
    };
    let speculative_expansion = macro_def.expand(db, actual_macro_call, &tt);
    let fragment_kind = macro_fragment_kind(db, actual_macro_call);
    let (node, tmap_2) =
        mbe::token_tree_to_syntax_node(&speculative_expansion.value, fragment_kind).ok()?;
    let token_id = macro_def.map_id_down(token_id);
    let range = tmap_2.range_by_token(token_id, token_to_map.kind())?;
    let token = node.syntax_node().covering_element(range).into_token()?;
    Some((node.syntax_node(), token))
}
pub fn expand_speculative ( db : & dyn AstDatabase , actual_macro_call : MacroCallId , speculative_args : & ast :: TokenTree , token_to_map : SyntaxToken , ) -> Option < ( SyntaxNode , SyntaxToken ) > { let ( tt , tmap_1 ) = mbe :: syntax_node_to_token_tree ( speculative_args . syntax ( ) ) ; let range = token_to_map . text_range ( ) . checked_sub ( speculative_args . syntax ( ) . text_range ( ) . start ( ) ) ? ; let token_id = tmap_1 . token_by_range ( range ) ? ; let macro_def = { let loc : MacroCallLoc = db . lookup_intern_macro ( actual_macro_call ) ; db . macro_def ( loc . def ) ? } ; let speculative_expansion = macro_def . expand ( db , actual_macro_call , & tt ) ; let fragment_kind = macro_fragment_kind ( db , actual_macro_call ) ; let ( node , tmap_2 ) = mbe :: token_tree_to_syntax_node ( & speculative_expansion . value , fragment_kind ) . ok ( ) ? ; let token_id = macro_def . map_id_down ( token_id ) ; let range = tmap_2 . range_by_token ( token_id , token_to_map . kind ( ) ) ? ; let token = node . syntax_node ( ) . covering_element ( range ) . into_token ( ) ? ; Some ( ( node . syntax_node ( ) , token ) ) }
This expands the given macro call, but with different arguments.
This expands the given macro call but with different arguments .
db
&dyn AstDatabase
actual_macro_call
MacroCallId
speculative_args
&ast::TokenTree
token_to_map
SyntaxToken