rust-analyzer: Autocompletion does not work for function-local variable when there is a macro on a function

Hello everyone! Love the work you are doing for the community!

Setup

VSCode plugin: v0.2.817 Rust: 1.56.1 (59eed8a2a 2021-11-01) Cargo: 1.56.0 (4ed5d137b 2021-10-04) Rust Analyzer: 73668334f 2021-11-15 stable

Problem

I can confirm it happening in NeoVim as well, so it’s not unique to VSCode setup.

SSCCE video

Reproduction

Here is the smallest reproducable example I can get:

  1. Do cargo init rust-analyzer-autocomplete-bug
  2. Do cargo add tracing
  3. Add following to your main.rs and try to type test where comment is
  4. Observe things not working
  5. Remove #[tracing::instrument] and try again to type test where comment is
  6. Observe everything working fine
// main.rs
use std::collections::HashSet;

fn main() {
    println!("Hello, world!");
}

struct Test;

impl Test {
    fn test() -> HashSet<String> {
        HashSet::new()
    }
}

#[tracing::instrument]
async fn buggy_autocomplete() {
    let test = Test::test();
    // cannot autocomplete test here
}

I’d be happy to provide any additional details if needed. Really am excited about your project getting better every weak! 🎉

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 5
  • Comments: 22 (10 by maintainers)

Most upvoted comments

I get what you’re saying, but:

  • for every user having trouble with async-trait, there will be two tokio users complaining that IDE features don’t work with #[tokio::main]
  • we enable features by default, for discoverability and to get bug reports when something doesn’t work right
  • the other crates we’ve filed issues against fixed it (by returning the original function body on parse errors); async-trait is the only crate where the maintainer refused
  • we generally want to push the whole ecosystem forward, not to hang back until everyone catches up

Filed https://github.com/async-rs/async-std/issues/998 for the async-std problem.

Regarding the original issue, this is interesting, typing just t gives the me autocompletion for test, but if I type te it disappears.

I am getting a feeling that my issue became a discussion for a completely separate issue. Is it so? If yes, can you please open another issue and move your discussion there?

The problem is that not enabling this option leads to other code not being handled correctly. Before the option was enabled by default, we had people reporting those problems instead. It might have been less prevalent, but if we revert the setting, it also means no-one notices the problem.

All proc macros using syn have this problem, unless they handle it as a special case. See https://github.com/dtolnay/async-trait/issues/178 for async-trait.

I don’t know if that helps but it happens with async-trait as well. I’m pretty sure auto-completion was working there in previous versions of rust-analyzer.