You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wrote some experimental code to generate completions for the builder macro here. It was showcased in the 2.0 update blog post.
However, the current impl is rather limited. It does some custom manual parsing trying to be resilient to incomplete/errored syntax. The goal for this effort is that the macro must be able to parse any incomplete syntax and always generate the use statements with completions for all attributes passed to the macro. This must include attributes on struct fields and on function arguments (current dirty impl ignores those).
Summary
The idea is to use rust-analyzer's APIs (RA publishes its crates to crates.io) to parse the tokens handed to the macro instead of using the custom impl I wrote, which is very limited. The RA crates need to be added as dependencies under cfg(rust_analyzer) condition only. For example:
The cfg(rust_analyzer) is an internal CFG used by RA when it analyzes Rust's code. We can work with RA maintainers to guarantee this CFG is stable, or discuss alternatives (maybe use a more generic name for the CFG).
This effort requires a lot of research and the nuances are undiscovered yet. I'm not yet sure how hard this will be to use RA to provide good completions for users, and also keep it in sync with the real macro implementation.
The text was updated successfully, but these errors were encountered:
Context
I wrote some experimental code to generate completions for the builder macro here. It was showcased in the 2.0 update blog post.
However, the current impl is rather limited. It does some custom manual parsing trying to be resilient to incomplete/errored syntax. The goal for this effort is that the macro must be able to parse any incomplete syntax and always generate the use statements with completions for all attributes passed to the macro. This must include attributes on struct fields and on function arguments (current dirty impl ignores those).
Summary
The idea is to use rust-analyzer's APIs (RA publishes its crates to crates.io) to parse the tokens handed to the macro instead of using the custom impl I wrote, which is very limited. The RA crates need to be added as dependencies under
cfg(rust_analyzer)
condition only. For example:The
cfg(rust_analyzer)
is an internal CFG used by RA when it analyzes Rust's code. We can work with RA maintainers to guarantee this CFG is stable, or discuss alternatives (maybe use a more generic name for the CFG).This effort requires a lot of research and the nuances are undiscovered yet. I'm not yet sure how hard this will be to use RA to provide good completions for users, and also keep it in sync with the real macro implementation.
The text was updated successfully, but these errors were encountered: