Skip to content

SCIP: Emit references for symbols referenced in macro-expansion#22605

Open
Wilfred wants to merge 2 commits into
rust-lang:masterfrom
Wilfred:macro_expansion
Open

SCIP: Emit references for symbols referenced in macro-expansion#22605
Wilfred wants to merge 2 commits into
rust-lang:masterfrom
Wilfred:macro_expansion

Conversation

@Wilfred

@Wilfred Wilfred commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Previously, we only emitted references from source tokens. This causes issues with find-references tools built on top of SCIP. For example, the following code would produce a SCIP index with no references to greeting.

use askama::Template;

#[derive(Template)]
#[template(source = "{{ crate::greeting() }}", ext = "txt")]
struct Page;

fn greeting() -> &'static str {
    "hello from askama"
}

Instead, walk macro-expanded tokens and emit SCIP references with the Generated role.

Whilst this is strictly more work, SCIP generation time increased by less than 10% when testing on the crates inside rust-analyzer.

(I've split out a commit that reindents the closure a bunch, to hopefully make the actual logic changes easier to read.)

AI disclosure: Partially written by Codex and GPT-5.5.

Trivial change that causes a bunch of reindentation, makes the
next commit simpler.
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 17, 2026
Previously, we only emitted references from source tokens. This causes
issues with find-references tools built on top of SCIP. For example,
the following code would produce a SCIP index with no references to
`greeting`.

    use askama::Template;

    #[derive(Template)]
    #[template(source = "{{ crate::greeting() }}", ext = "txt")]
    struct Page;

    fn greeting() -> &'static str {
        "hello from askama"
    }

Instead, walk macro-expanded tokens and emit SCIP references with the
Generated role.

Whilst this is strictly more work, SCIP generation time increased by
less than 10% when testing on the crates inside rust-analyzer.

AI disclosure: Partially written by Codex and GPT-5.5.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants