Stream: t-compiler/rust-analyzer

Topic: source_to_def and attribute macros

Jonas Schievink [he/him] (Jun 05 2021 at 19:14, on Zulip):

I'm looking into how to fix, aaand this looks potentially quite difficult, since any syntactical item might actually be a macro call. There doesn't happen to be a convenient place to check for this and have everything magically work, right?

matklad (Jun 06 2021 at 12:07, on Zulip):

Yeah, I think this is fundamentally tricky.....

Basically, the problem with this is that source2def(src).src == src equality does not hold with attributes

matklad (Jun 06 2021 at 12:08, on Zulip):

That is, we start with annotated fn node, but should get a def whose source is actually in an expanded file

Florian Diebold (Jun 06 2021 at 12:31, on Zulip):

well in principle, there just is no def for the original fn ast node, is there?

Florian Diebold (Jun 06 2021 at 12:32, on Zulip):

it's like calling to_def on a macro call

Florian Diebold (Jun 06 2021 at 12:39, on Zulip):

so I guess that the IDE functionality should first be descending into the macro calls, but it doesn't because it's only looking for MacroCall nodes? :thinking:

Florian Diebold (Jun 06 2021 at 12:41, on Zulip):

there just is no def for the original fn ast node, is there?

unless the node gets passed through completely by the attribute of course, then it might be arguable that there is... but I'm not sure whether it would be necessary or helpful to do that

Florian Diebold (Jun 06 2021 at 12:43, on Zulip):

i.e. in descend_into_macros, we need to not just look for MacroCalls, but also any ancestors annotated with proc macro attributes?

Jonas Schievink [he/him] (Jun 06 2021 at 12:45, on Zulip):

yeah I played around with descend_into_macros the other day, that might get us some of the way there already

Jonas Schievink [he/him] (Jun 07 2021 at 20:44, on Zulip):

I've changed descend_into_macros to work with attribute macro, and it seems to work when printing the original and remapped token. I've also changed to account for attribute macros and descend into them, but somehow all identifiers in the invocation stay unresolved. Any idea what might cause this? Do we have any way to debug the token mapping?

Jonas Schievink [he/him] (Jun 09 2021 at 13:08, on Zulip):

This is now largely fixed, but some way to debug TokenMap operations would still be nice

Last update: Jul 24 2021 at 20:15UTC