Cannot complete macro path in macro <!-- Troubleshooting guide:…
- 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.
- Assistant
Investigating macro path completion inside macro invocations — searching the codebase for how completions are resolved in that context.
- Assistant
Implementing the fix: speculative expansion fails when the inner macro name includes the completion marker, so we'll stop at the mapped expansion level instead.
- Assistant
Refining the fix: only stop early when the speculative macro call path itself contains the completion marker (e.g.
barraCompletionMarker!()), not when the marker is only in macro arguments. - Assistant
Fixed macro path completion when an
identmetavariable is spliced into a macro invocation path (e.g.$i!()).Root cause
When completing inside
foo!(bar$0)wherefooexpands to$i!():- Speculative expansion correctly mapped the cursor into
barraCompletionMarker!()in the expanded file. - Completion then tried to expand that inner macro call further.
- That failed because the speculative path (
barraCompletionMarker) doesn't match the real path (bar). - The whole expansion was discarded, so
CompletionContext::newreturnedNoneand no completions were offered.
Fix
In
crates/ide-completion/src/context/analysis.rs, when further expansion fails but the mapped token is part of a speculative macro call path (completion marker in the macro path, not in macro arguments), stop at the current expansion level instead of giving up.This preserves existing behavior for cases like
m!(v$0)where the marker is passed as a macro argument tohelper!($v)and completion should continue at the$vexpression site.Tests
Added
completes_macro_path_in_macroincrates/ide-completion/src/tests/special.rscovering:foo!(bar$0)— partial namefoo!($0)— empty argument- Applying the
barcompletion
All 733
ide-completiontests pass. - Speculative expansion correctly mapped the cursor into
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- fable-5Compare side by side →
- fable-5Compare side by side →