rust-lang / rust-lang/rust-analyzer

Intellisense fails when using macros

Open
#17,045 1 comment 3 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: 0.3.1916-standalone (7a8374c16 2024-04-08) and 0.4.1918-standalone (a5feb4f05 2024-04-09)

rustc version: 1.77.2 (25ef9e3d8 2024-04-09)

editor or extension: VSCode 1.88.0 2024-04-03

code snippet to reproduce:
main.rs:

use tracing::Level;
use tracing_subscriber::FmtSubscriber;

#[allow(dead_code)]
fn main() {
    let subscriber = FmtSubscriber::builder()
        .with_max_level(Level::TRACE)
        .with_target(false)
        .finish();

    tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");

    be_translated(vec![1, 2, 3]);
}

// #[cfg_attr(feature = "tracing", tracing::instrument(skip(v)))]
#[cfg_attr(feature = "tracing", tracing::instrument)]
// #[tracing::instrument]
fn be_translated(v: Vec<usize>) {
    println!("{:?}", v.len());
}


Cargo.toml:

[features]
default = ["tracing"]

tracing = []

[dependencies]
tracing = "0.1"
tracing-subscriber = "0.3"

If I add the cfg_attr, then autocomplete does not work:
图片

If I remove cfg_attr, autocomplete works:
图片

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 report with the shown main.rs and Cargo.toml, comparing completion with and without the cfg_attr macro. Start by tracing rust-analyzer's completion handling for macro-annotated functions. Done means autocomplete works in the cfg_attr case while preserving the behavior of the non-macro example.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.