rust-lang / rust-lang/rust-analyzer

Autocomplete breaks inside macro

Open
#12,524 10 comments 19 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

rust-analyzer version: v0.3.1091
rustc version: 1.61
relevant settings: None, clean install

In my project I have several files that define logic via closures stored within vectors. The structure of the code roughly looks like this:

pub fn gold_mine() -> CardDefinition {
    CardDefinition {
        name: CardName::GoldMine,
        abilities: vec![
            simple_ability(
                at_dusk(|g, s, _| {
                    mutations::take_stored_mana(g, s.card_id(), 3, OnZeroStored::Sacrifice)?;
                    Ok(())
                }),
            ),
        ],
        config: CardConfig::default(),
    }
}

Autocomplete via rust analyzer breaks within these closures in all of the files in my project. It works as expected outside of them.

rust

This reproduces for me in a brand new installation of ubuntu 22.04 running Visual Studio Code and rust-analyzer. You should be able to reproduce it via:

git clone https://github.com/thurn/Spelldawn.git
git checkout 2ed24d0 (the exact point of the screenshot above)
rm .cargo/config.toml (if you don't have the lld linker installed, but the issue reproduces either way)
cargo build
open crates/cards/src/projects.rs (or any file in this directory really)
attempt to use auto-complete inside one of the closures, e.g. on line 43

This also reproduced for me on Mac OSX.

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 failure by cloning Spelldawn, checking out 2ed24d0, building with cargo, and opening crates/cards/src/projects.rs in Visual Studio Code. Test autocomplete inside and outside the closures, then trace the rust-analyzer behavior involved; done means autocomplete works inside these closures as well as elsewhere.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, vscode
Domain
developer-experience, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.