Skip to content
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

proc macro attributes considered to be unresolvedReference #10935

Open
jhgg opened this issue Dec 5, 2021 · 3 comments
Open

proc macro attributes considered to be unresolvedReference #10935

jhgg opened this issue Dec 5, 2021 · 3 comments
Labels
A-ide general IDE features C-feature Category: feature request

Comments

@jhgg
Copy link
Contributor

jhgg commented Dec 5, 2021

consider the following code used w/ the serde library:

use serde::Deserialize;

#[derive(Deserialize)]
struct Foo {
    #[serde(default)]
   // ^^^^^ unresolvedReference 
    bar: u64,
}

We should be able to figure out if this is a valid attribute or not, by looking at the things the structs derive from and looking at the attributes for each proc macro to compute a list of identifiers that are valid within this context:

// in serde_derive/src/lib.rs
#[proc_macro_derive(Deserialize, attributes(serde))]
                                         // ^^^^^ we should find these.
pub fn derive_deserialize(input: TokenStream) -> TokenStream {
    let mut input = parse_macro_input!(input as DeriveInput);
    de::expand_derive_deserialize(&mut input)
        .unwrap_or_else(to_compile_errors)
        .into()
}

Bonus points would be to have a hover implementation that shows which proc macro's are consuming this attribute as well!

rust-analyzer version: 6434ada 2021-12-05 dev
rustc-version: 1.57.0

@Veykril
Copy link
Member

Veykril commented Dec 5, 2021

Ah right, I completely forgot about (derive) helper attributes which we now show as unresolved since they aren't being mapped to anything by macros...

As you said we can do some specific things here to fix that for derive helpers specifically, but the problem persists for helper attributes of proc-macro attributes as well like with salsa here
image
In which case we can't know about these

So I guess we'll have to add that attribute highlight heuristics back for now...

I do like the hover idea though 👍

@Veykril
Copy link
Member

Veykril commented Dec 5, 2021

Actually now I wonder if it would make sense to push proc macro authors to expose dummy attributes that resolve to these helpers. That way people could also hover them for more info on the helper itself 🤔

bors bot added a commit that referenced this issue Dec 5, 2021
10937: fix: Add highlighting hack back for unresolved attributes r=Veykril a=Veykril

cc #10935
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
@Veykril
Copy link
Member

Veykril commented Dec 5, 2021

Opened a zulip thread for the latter idea.

Highlighting issue papered over again with #10937 for now.

@Veykril Veykril added A-ide general IDE features C-feature Category: feature request labels Dec 5, 2021
bors added a commit that referenced this issue Jul 26, 2022
feat: Resolve derive helper attributes in IDE layer

![image](https://user-images.githubusercontent.com/3757771/180647125-98cae13b-a7b4-446b-8a64-fae014f982e2.png)

Also downmaps tokens inside deriver helpers to the derive expansion
![image](https://user-images.githubusercontent.com/3757771/180642110-699bdc73-e1f3-4692-94f2-21544f824ab9.png)

This does not handle the case where multiple derives make use of the same helper name though, unsure how to tackle that yet.

Partially addresses #10935
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ide general IDE features C-feature Category: feature request
Projects
None yet
Development

No branches or pull requests

2 participants