rust-lang / rust-lang/rust-analyzer

Provide code actions to recursively expand declarative macros

Open
#10,883 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-assists A-macro C-feature
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

Sometimes you notice that a macro DSL got out of hand and getting rid of it would actually improve the readability of the code. So it would be nice if rust-analyzer would provide code actions to selectively expand declarative macros. For example:

macro_rules! say {
    () => { concat!(say!(hello), say!(world)) }
    (hello) => { "hello " };
    (world) => { "world" };
}

fn main() {
    print!(say!(hello));
    print!(say!(world));
}

For this example the following code actions could be provided:

  • code action for macro definition (e.g. macro_rules! say): expand this macro recursively everywhere it is used
  • code action for macro rule definition (e.g. (hello) =>): expand this macro rule recursively everywhere it is used
  • code action for macro invocation (e.g. say!(hello)): expand this macro recursively

Currently there only appears to be the Expand macro recursively command that opens the macro invocation under the cursor in a new buffer (which of course isn't helpful for large-scale refactors).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by examining rust-analyzer's existing “Expand macro recursively” command for macro invocations. Define how code actions on a macro definition, macro rule definition, and invocation should selectively expand recursive uses, with completion meaning the resulting source is expanded at the requested scope.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.