rust-lang / rust-lang/rust-analyzer

Improve derive macro helper input tokens span

Open
#21,496 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I noticed that once the generated result contains a span from the helper, all call-sites in the derived macro will point to every argument tt of the helper

This makes it difficult to goto-define and view hover in helpers

#[derive(serde::Serialize)]
struct Foo {
    #[serde(skip_serializing_if = "Option::is_none")]
    x: Option<i32>,
}

Cursor on is_none hover to output a large amount, such as extern crate serde
And the goto-definition also has multiple results pointing to the inside of the serde

Currently, call-site be obtained on is_none.
Expected to be obtained on the helper name (serde) instead of the helper argument (skip_serializing_if and "Option::is_none")

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 reproducing the derive-macro example with serde and inspect rust-analyzer's handling of helper input tokens and call-site spans; the issue names no source file or test. Done means hover and goto-definition on is_none resolve using the helper name span, such as serde, rather than the helper arguments.

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
40/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.