rust-lang / rust-lang/rust-analyzer

autocomplete breaks in an item identity macro.

Open
#11,652 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

consider the following macro:

macro_rules! item_ident {
    ($($item:item)*) => {
        $( $item )*
    }
}

When writing code within this macro, syntax as we're typing might not be considered a valid "item". for example:

item_ident! {
    fn baz() {
        let x = <|>
    }
}

Of course rust-analyzer complains about this:

expected Item
rust-analyzer[macro-error](https://rust-analyzer.github.io/manual.html#macro-error)

This is a fairly common pattern, for example, used in tokio to wrap code blocks with valid #[cfg(...)]s: https://github.com/tokio-rs/tokio/blob/master/tokio-util%2Fsrc%2Fcfg.rs

I wonder if we can recover from these syntax errors such that autocomplete and the likes work in this situation.

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

Reproduce the issue with the item_ident! macro shown in the report and compare behavior with the Tokio tokio-util/src/cfg.rs example. Investigate rust-analyzer's macro parsing and recovery around an incomplete expression such as <|>. Done means autocomplete and related IDE features work inside the macro despite the temporary item syntax error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.