-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Next steps in macro support #688
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
Comments
Hm, I am having second thoughts regarding the usage of
Hopefully designing our own token tree type wouldn't be too difficult! We also could try a better API |
question: is it possible to expand proc_macros from a crate like this on stable rust? Afaict the only caller allowed to invoke proc_macros is rustc. |
@kazimuth , It is possible to do that with dynamic loading: https://github.com/fedochet/rust-proc-macro-expander That is using nightly rustc api, But by dispatching the macro parsing to separate process, it is allowed RA on build in stable. On the other hand, if rust ABI is not concerned, it is possible to change that to use only stable rust api too. |
I have a custom derive which takes in structs and builds more structs and their implementations. The generated structs and methods don't seem to be available for resolving types and autocompletion and highlighting. I think this issue solves it, doesn't it? Or am I wrong? |
Also, from a discussion in zulip
Should I create a different issue for this or does this issue cover it? |
Did you enable proc-macro support with the following config? {
"rust-analyzer.cargo.loadOutDirsFromCheck": true,
"rust-analyzer.procMacro.enable": true,
} |
Yeah, I even restarted a lot of things too. The types are definitely not being resolved. |
Our macro engine has been pretty capable for a long time now, so closing in favor of more specific issues. |
@matklad Hi. I've had the settings mentioned above, enabled in my config for a very long time but completion for proc macro generated code doesn't work for zbus at least. Is there any other configurations I need to enable or does zbus macros need to do something? |
Attribute proc macros aren't supported yet, just derives and function-like ones. See e.g. #6029. |
The basic infra for macros is in place: hir uses
HirFileId
which can refer to both usual files and macro expansions.Now we need to learn how to actually expand macros. We need to handle two kinds of macros: macro by example (
macro_rules
) and procedural macros. Crates like https://github.com/nrc/proc-macro-rules (thanks @nrc!) should allow us to handle only the second case. Basically, the pipeline should look likeWe need to implement only first and last arrow (which might be not easy as it seems because we need hygiene info somewhere).
The next big step after understanding
macro_rules
would be plugging them into the resolver in a proper recursive way.The text was updated successfully, but these errors were encountered: