ISSUE DESCRIPTION Cannot complete macro path in macro <!-- Troubleshooting guide:…
- User
ISSUE DESCRIPTION
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.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /rust-analyzer, current file: none) bash-$
- Assistant
I'll start by exploring the repository structure and searching for related completion/macro path code to understand the issue.
- Assistant
I'll search the completion crate for macro-related path completion logic.
- Assistant
rg is not found? That's odd, earlier it seemed to partially work. Let me try again with the full path or grep.
- Assistant
Let me look at how path completion works and when macros are expected. Also search for existing tests related to macro completion inside macros.
- Assistant
Looking at tests for completing macros inside macro calls and the path kind analysis.
- Assistant
Looking at how completions work inside token trees and macro inputs.
- Assistant
I'll inspect macro expansion analysis and how path kinds are determined for expanded macro contexts.
- Assistant
Examining how MacroCall path kinds are classified during completion analysis.
- Assistant
Checking how speculative expansion handles the completion marker and existing related issues.
- Assistant
I'll create a temporary test to reproduce the issue and observe actual completion results.
- Assistant
Let me add a temporary test to special.rs and run it.
- Assistant
Let me append a test to special.rs
- Assistant
Need to configure the Rust toolchain first.
- Assistant
There's a rust-version file with a commit hash - probably needs a specific nightly. Let me check if there's a way to install it.
- Assistant
I need to install a rust toolchain. The rust-version is a specific commit. Let me try installing nightly or that specific version.
- Assistant
Nightly is ready — next I'll try building and running the test.
- Assistant
Confirmed empty completions. Digging into path completion filtering for macros next.
- Assistant
Let me look at how process path completions filters for macro bangs. Also let me look at complete_expr_path.
- Assistant
I'll check git history and the positive case for completing macros with bangs.
- Assistant
Confirming empty completions — I'll instrument the analysis path to find the failure point.
- Assistant
I'll add temporary debug prints to the completion flow to see where context is lost.
- Assistant
I'll add temporary debug logging in expand_and_analyze and CompletionContext::new.
- Assistant
Checking how macro expansion behaves for this pattern and whether
expand_macro_callsucceeds. - Assistant
I'll add temporary debug output to the test path to inspect expansion and analysis.
- Assistant
Inspecting expand_maybe_stop to see how nested expansion is handled.
- Assistant
Checking what
is_inside_macro_calldoes — it may mis-detect the expanded path. - Assistant
Let me need the is_inside_macro_call implementation.
- Assistant
Found the bug:
is_inside_macro_calltreats the macro path as "inside" the call. Checking all callers before fixing. - Assistant
Reviewing search.rs usage to confirm the intended semantics of
is_inside_macro_call. - Assistant
I'll fix壊
is_inside_macro_callso it only treats tokens inside the macro arguments token tree as inside, not the macro path itself. - Assistant
Updating
is_inside_macro_callto only treat tokens inside the argument token tree as inside the call. - Assistant
Running the reproduction test to verify thespec fix.
- Assistant
Checking what completions the updated expect test recorded.
- Assistant
Comparing with direct macro path completion outside viel a macro call.
- Assistant
The file wasn't open — I'll open it and append the comparison test.
- Assistant
Checking whether completions are filtered by
has_macro_bangso only macros show when!is already present. - Assistant
grep is having issues with directories. Let me use find.
- Assistant
Confirming baseline: completing a macro path with
!should still list non-macros — matching existing behavior. - Assistant
Let me see what theexpect became.
- Assistant
Removing the temporary tests before submit, per instructions.
- Assistant
Checking for a duplicate implementation and running related tests via a temporary script.
- Assistant
Restoring special.rs and double-checking that only the intended fix remains.
- Assistant
Confirming the public Semantics wrapper forwards correctly, then running related tests.
- Assistant
There's only one is_inside_macro_call on SemanticsImpl - but wait, there should be a public Semantics facade. Let me check how public API exposes it.
- Assistant
Writing a temporary verification which I'll delete before submitting.
- Assistant
First case passed. Exploring edge cases without a token tree, then cleaning up.
- Assistant
Inspecting updated expect snapshots for all cases.
- Assistant
Nested path returned empty — checking whether that's pre-existing or introduced by this fix.
- Assistant
Both edge cases were empty without the fix. Restoring the fix and verifying regressions.
- Assistant
Confirming the regression test and cleaning up temporary files.
- Assistant
Running a broader smoke test for reference search and related functionality:
- Assistant
Final verification with a temporary external script, then submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.