Stream: t-compiler/rust-analyzer

Topic: Analysis within macro_rules


Paul Faria (Aug 13 2020 at 13:18, on Zulip):

@matklad I was thinking of trying to tackle at least partial analysis within macro_rules! bodies. My thought was that we could guarantee resolution of items like $crate and the paths that follow. Is there any existing issue based on that, or do you have any thoughts on whether we should approach something like that right now?

pksunkara (Aug 13 2020 at 14:51, on Zulip):

I think the best approach would be to do it like how I proposed in https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/macro_rules.20highlighting

pksunkara (Aug 13 2020 at 14:51, on Zulip):

But there's no issue created for this yet.

pksunkara (Aug 13 2020 at 14:53, on Zulip):

I know that topic talks about analyzing content inside macro! but it is relevant to also analyzing content inside macro_rules!

Paul Faria (Aug 14 2020 at 14:25, on Zulip):

I looked into it this morning. The biggest issue is that the body of a macro_rules macro is just a token tree, and there's currently no analysis done if the macro itself isn't called. @matklad could we sync at some point to go over a best path forward here? I have a couple ideas, but not sure which is the best approach:

matklad (Aug 18 2020 at 12:07, on Zulip):

I don't think it makes sense to do any kind of "fancy" analysis of macro bodies any time soon

matklad (Aug 18 2020 at 12:07, on Zulip):

This is a deeply heurisitc thing, and it's not like we got the basic stuff working

matklad (Aug 18 2020 at 12:08, on Zulip):

What can, and should be done though, is supporting goto definition and compleiton for meta vars

matklad (Aug 18 2020 at 12:08, on Zulip):

clicking on $foo should bring one to $foo:expr

matklad (Aug 18 2020 at 12:09, on Zulip):

I am not sure how to best achieve this, as macro machinery fundametally works with token trees, and not the syntax trees

matklad (Aug 18 2020 at 12:09, on Zulip):

I think the right approach here is just a huge wad of code in ide which uses TokenID to switch bridge the two representations

Paul Faria (Aug 18 2020 at 13:32, on Zulip):

Could we at least have the ungrammar account for this within macro rules? https://doc.rust-lang.org/reference/macros-by-example.html

Paul Faria (Aug 18 2020 at 13:32, on Zulip):

I noticed it's not in the official grammar (the one being produced by wg-grammar), but only in the reference linked above.

matklad (Aug 18 2020 at 13:33, on Zulip):

I don't think this should be handle by ungrammar -- macros are token trees

Paul Faria (Aug 18 2020 at 13:35, on Zulip):

Ok, so ide would be the area to handle macro_rules in a special way?

matklad (Aug 18 2020 at 13:36, on Zulip):

yup

matklad (Aug 18 2020 at 13:36, on Zulip):

IDE would call into mbe to make sense of macro rules invocations

matklad (Aug 18 2020 at 13:36, on Zulip):

should also stress our IR-mapping infrastructure (not that we have any :D ), as mbe are essentially are a separate IR

Paul Faria (Aug 18 2020 at 13:38, on Zulip):

I did not even realize mbe existed. Ok I'll review this for the time being. Thanks for following up!

pksunkara (Sep 10 2020 at 22:07, on Zulip):

Can someone please tag this issue as macro? https://github.com/rust-analyzer/rust-analyzer/issues/5972

Laurențiu (Sep 11 2020 at 05:37, on Zulip):

Done

Last update: Jul 28 2021 at 03:00UTC