rust-lang / rust-lang/rust-analyzer
Refactor and improve macro debugging/general utilities
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
Rust analyzer's expand macro recursively command is nice, however, it is also greatly flawed and provides little to no utility for debugging more complex macros. This issue is aimed at refactoring it and turning it into a useful tool.
Flaws with expand macro recursively
- No formatting is applied to the expanded code, most people dont care about formatting inside macros, so the output ends up looking pretty horrid.
- The macro expander expands all the macros recursively (duh). This may seem useful, but it often just causes more confusion around what is coming from the main macro and what is recursively expanded, and it generally just outputs miscellaneous code you dont care about.
- There is no way of knowing what code came from what binding, and the expansion does not show the macro either, so now you have to go back and forth to try and see what is what.
Proposal for refactoring the command
Instead of a simple text read only editor, we can make use of vsc's custom editor windows extension to make a prettier and more useful editor.
The changes would have to be made in steps:
- Refactor
hir::sema::expandto give more info about what code came from what binding, i suspect this will be the hardest part. - Implement a basic editor which colors code blocks depending on where they came from.
- (maybe) implement highlighting in the actual source code when the editor is live.
- Make an experimental command (not sure of how RA handles experimental features).
- Deprecate the expand macro recursively command and eventually phase it out.
Challenges
- Not all macros are pretty, some are very cursed, especially recursive macros, displaying them in a nice way is going to be a challenge.
- Modeling what bindings created what code may be a challenge in the expansion code.
- Good editor design is hard :(
So what might it look like? 👀
I am by no means a design guy, and i realize this is a blob of colors, but this is conceptually what it might look like:

If anyone has suggestions then please put them below.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the existing expand macro recursively command and hir::sema::expand, then review how rust-analyzer handles experimental features and VS Code custom editor windows. Define the provenance information needed to distinguish bindings and expansion levels before evaluating the staged editor proposal. Done should include a scoped experimental command with readable, formatted expansion and clear source attribution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, vscode
- Domain
- compilers, developer-experience, devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100