Skip to content

Resolving variable references is not working as expected in function that is annotated with proc macro #12050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
FylmTM opened this issue Apr 21, 2022 · 2 comments · Fixed by #12064
Labels
A-ide general IDE features A-macro macro expansion

Comments

@FylmTM
Copy link

FylmTM commented Apr 21, 2022

rust-analyzer version: 65fbe0a 2022-04-18 stable
rustc version: rustc 1.60.0 (7737e0b5c 2022-04-04)
relevant settings: -

When annotating function with proc-macro, resolving references inside such a function does not behaves as expected:

  • Variable references are no longer highlighted
  • Pressing "Go to definition" on variable declaration does not open reference list

In my case, this is tracing::instrument proc macro.

Code example:

struct Struct { field: i32 }


#[tracing::instrument]
fn test_with_instrumentation() {
    let variable = Struct { field: 42 };

    variable.field;
    variable.field;

}

fn test_without_instrumentation() {
    let variable = Struct { field: 42 };

    variable.field;
    variable.field;
}

Here how it looks like in function that is not annotated:
image

You can see that I can get a list of references (when executing go to definition on variable declaration) and references are highlighted with gray box.

Here how it looks like in function that is annotated:
image
Go to definition does nothing, and references are not highlighted.

However if I try go to definition on one of usages, it will jump me to declaration.

I tried to add this configuration in VS Code, but it did not made any difference:

    "rust-analyzer.procMacro.ignored": {
        "tracing": [
            "instrument"
        ]
    }
@Veykril
Copy link
Member

Veykril commented Apr 21, 2022

    "rust-analyzer.procMacro.ignored": {
        "tracing-attributes": [
            "instrument"
        ]
    }

should work as a workaround (the attributes come from tracing-attributes not tracing, they are just re-exported there)

@FylmTM
Copy link
Author

FylmTM commented Apr 21, 2022

Can confirm that this workaround works for me. 🎉
Thanks! Amazing stuff 🕺

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ide general IDE features A-macro macro expansion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants