Skip to content
TheChatArchiveThe Chat Archive
composer-2.5· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

Cannot complete macro path in macro <!-- Troubleshooting guide:…

  1. User

    Cannot complete macro path in macro

    rust-analyzer version: rust-analyzer 0.4.2897-standalone

    rustc version: rustc 1.97.0-nightly (36ba2c771 2026-04-23)

    editor or extension: Vim

    code snippet to reproduce:

    macro_rules! bar { () => (); }
    macro_rules! foo { ($i:ident) => { $i!() }; }
    fn main() {
        foo!(bar$0);
    }
    

    Interface

    No new interfaces are introduced.

  2. Assistant

    Investigating macro path completion inside macro invocations — I'll search the codebase for how completions are handled in macro contexts.

  3. Assistant

    I'll add a test for this scenario and run it to see what completions we get today.

  4. Assistant

    No completions returned — I'll trace speculative macro expansion and path-context detection.

  5. Assistant

    Macro path tokens are incorrectly treated as macro input because is_inside_macro_call matches any token under MacroCall, including the callee path. I'll narrow that check to tokens inside the macro's token tree.

  6. Assistant

    Fixed macro path completion when an ident metavariable expands to a macro invocation like $i!().

    Root cause

    Completion uses speculative macro expansion to map the cursor from foo!(bar) to the expanded position bar!(). Expansion stopped too early because is_inside_macro_call treated any token under a MacroCall as macro input—including the callee path (bar in bar!()).

    That made expand_maybe_stop think it was still inside macro input and fail to reach the macro-path completion context, so no completions were offered.

    Fix

    Updated is_inside_macro_call in crates/hir/src/semantics.rs to only return true for tokens inside the macro call's token tree (the actual input), not the path:

        pub fn is_inside_macro_call(&self, token @ InFile { value, .. }: InFile<&SyntaxToken>) -> bool {
            value.parent_ancestors().any(|ancestor| {
                if let Some(macro_call) = ast::MacroCall::cast(ancestor.clone()) {
                    return macro_call
                        .token_tree()
                        .is_some_and(|tt| tt.syntax().text_range().contains_range(value.text_range()));
                }
    

    This matches the documented behavior (“strictly check if it lies inside the input of a macro call”).

    Tests

    Added completes_macro_path_in_macro_invocation covering both partial typing (foo!(bar$0)) and applying a completion from scratch (foo!($0)).

    All 733 ide-completion tests pass.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.