Skip to content

Function syntax highlighting with attribute proc macro #9513

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
gtsiam opened this issue Jul 6, 2021 · 3 comments
Closed

Function syntax highlighting with attribute proc macro #9513

gtsiam opened this issue Jul 6, 2021 · 3 comments

Comments

@gtsiam
Copy link

gtsiam commented Jul 6, 2021

So, I turned on experimental proc attr macro expansion for a custom macro, but syntax highlighting seems to really not like it when I pass expressions from the attributes to the output. Here's the macro (well, the shortest version of it where I could get the error):

struct FilterAttr {
    filters: Vec<Expr>,
}

// Parse attributes as Punctuated<_, Token![,]>
// impl Parse for FilterAttr { ... }

#[proc_macro_attribute]
pub fn filter_minimal(attr: TokenStream, item: TokenStream) -> TokenStream {
    let func = parse_macro_input!(item as ItemFn);
    let attr = parse_macro_input!(attr as FilterAttr);

    let filters = attr.filters;
    let vis = func.vis;
    let name = func.sig.ident;
    let tokens = quote! {
        #vis fn #name() {
            let dummy = 0i32 #( .wrapping_add(#filters) )*;
        }
    };

    tokens.into()
}
#[filter_minimal(1, 2, 3)]
pub async fn test() {}

Here's the problematic highlighting:

εικόνα
εικόνα

From some testing, it seems that the issue only appears when I try to put the attributes in the output. In every other case, highlighting seemed to work correctly. I also tried changing FilterAttr::filters to Vec<Lit>, but the issue persists.

@Veykril
Copy link
Member

Veykril commented Jul 6, 2021

Dupe of #9185 I believe?

@gtsiam
Copy link
Author

gtsiam commented Jul 6, 2021

Possibly? It's hard to tell, since I'm not familiar with rust-analyzer's internals.

@Veykril
Copy link
Member

Veykril commented Jul 6, 2021

On a second look ye this seems to be a dupe of that one, closing in favor of it.

@Veykril Veykril closed this as completed Jul 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants