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 relevant completion/macro path code to understand the issue.
- Assistant
I'll search for existing tests and code related to macro path completion.
- Assistant
Let me look at the completions directory and search for tests related to this issue.
- Assistant
rg is not available as a command but earlier it seemed to work... wait, the first one used rg and it worked. Maybe path issue. Let me use grep.
- Assistant
Let me look at expression.rs tests for macro completions, and also the expr.rs completion code.
- Assistant
Let me look for tests that specifically deal with completing identifiers inside macro invocations, and look at how macro fragment completions work.
- Assistant
Let me look at the special.rs tests and the context analysis to understand how completions inside macros work. Also looking for ident fragment completion.
- Assistant
There's a test
completes_in_simple_macro_call- let me look at that and the surrounding context. Also the issue is specifically about completing a macro name that is used as$i:identand then invoked as$i!(). - Assistant
Let me understand how completions inside macro arguments work, especially for
identfragments. - Assistant
Let me read the analysis.rs more carefully around the macro expansion handling, especially for when speculative expansion fails (like with
:identfragment that expects just an identifier without!... - Assistant
Let me look at how PathKind is determined for macro calls and how path completions work for macros.
- Assistant
Let me look at existing tests infrastructure and try to reproduce the issue with a temporary test.
- Assistant
I'll add a temporary test to reproduce the incomplete macro path completion inside macros.
- Assistant
Let me add a test that reproduces the issue.
- Assistant
I accidentally removed the
#[test]attribute — fixing that now. - Assistant
Running the test to reproduce the issue.
- Assistant
Need to set up the rust toolchain.
- Assistant
There's a specific rust version in rust-version file. Let me set up rustup properly.
- Assistant
There's a toolchain installed but rustup can't find the default. Let me set RUSTUP_HOME
- Assistant
Running the test now.
- Assistant
Confirmed empty completions. Digging into path completion and how macro bang paths are handled.
- Assistant
Let me look at how path completions filter macros, and also look at the analysis of tokens after expansion more carefully. The issue might be that when the original expands to
b!()and speculative e... - Assistant
Let me examine how expansion produces tokens and how the speculative macro call path is classified.
- Assistant
Inspecting the full expand function from the start.
- Assistant
Let me continue reading to the macro call expansion path and also look at is_inside_macro_call.
- Assistant
Checking how
is_inside_macro_callworks — that seems central to the bug. - Assistant
Let me read the is_inside_macro_call function.
- Assistant
The bug is clear:
is_inside_macro_callreturns true for the macro path itself. Checking other call sites before fixing. - Assistant
Checking git history for
is_inside_macro_calland related changes. - Assistant
Verifying AST structure for MacroCall and TokenTree before applying the fix.
- Assistant
I'll fix
is_inside_macro_callso it only treats tokens inside a macro's argument token tree as inside the call. - Assistant
Let me apply the fix.
- Assistant
Running the test to verify the fix.
- Assistant
Checking normal macro path completion for comparison, and looking at how macros are filtered when
has_macro_bangis set. - Assistant
Let me check whether bare macro bang paths filter completions at the call site.
- Assistant
The bang caused history expansion. Let me escape it.
- Assistant
I'll add a quick comparison test for bare macro-path completion.
- Assistant
There's still empty line issues. Let me run the tests.
- Assistant
Our fix matches bare bang-path completion. Removing the temporary tests per instructions.
- Assistant
Restoring the test file from git after a bad edit.
- Assistant
I'll write a temporary validation script and run related completion tests.
- Assistant
Running a broader set of completion tests, and verifying the fix with a temporary script outside the repo.
- Assistant
Running tests that touch
is_inside_macro_call/ find-all-refs. - Assistant
Cleaning up nested if for style, then verifying the fix once more with a temporary test.
- Assistant
Adding a temporary verification test once more, then removing it.
- Assistant
I'll add a temp test👊 run, remove.
- Assistant
Restoring the missing
#[test]attribute. - Assistant
Interesting - evenयां with
bar$0prefix, itstill shows all items. This is probably because completion filtering happens by fuzzy matching later în the LSP layer, while these tests show all... - Assistant
Tests don't filter by prefix — completions are present. Removing the temporary test and finalizing.
- Assistant
Checking whether bare macro path completion at the call site still works — potential regression.
- Assistant
Checking the entry point of expansion analysis — bare macro paths may take a different code path.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.