Stream: t-compiler/rust-analyzer

Topic: Format after Expand Macro


Emmanuel Thompson (Apr 07 2021 at 02:34, on Zulip):

Hey all, I'm investigating how much effort it would be to format after expanding a macro, I found this in the code: https://github.com/rust-analyzer/rust-analyzer/blob/cf41e1410a0cf87a05b2dd632e3b5d67f8d55327/crates/ide/src/expand_macro.rs#L36-L38 , is there alot to accomplish this? Why is whitespace lost and re-added on expansion?

Jonas Schievink [he/him] (Apr 07 2021 at 02:40, on Zulip):

The difficult part here is adding a source code formatter in the first place, hooking it up to macros should be fairly straightforward

Emmanuel Thompson (Apr 07 2021 at 02:43, on Zulip):

Ahh because RA LSP calls out to rustfmt?

Edwin Cheng (Apr 07 2021 at 03:24, on Zulip):

In fact, I am working on this right now, we need a proper ast formatter internally for different purposes.

Edwin Cheng (Apr 07 2021 at 03:27, on Zulip):

Why is whitespace lost

Because our macro expansion code ignores whitespace information and even we preserve it we still need to reformat for proc-macro etc.

Edwin Cheng (Apr 07 2021 at 03:28, on Zulip):

Ahh because RA LSP calls out to rustfmt?

yes

Emmanuel Thompson (Apr 07 2021 at 03:37, on Zulip):

@Edwin Cheng neat! Thanks for the info.

Last update: Jul 24 2021 at 20:00UTC