-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[Proposal] Allow embedding other languages in macros #5389
Comments
For an extension API, it's also worth thinking about how to support macros that allow embedding of snippets of Rust code inside them. Presumably the macro LSP could provide information about what kind of AST fragment it is expecting in a given location. |
Does anyone know how support for JS and CSS is implemented in HTML? Can we follow such an approach? |
JS and CSS are implemented by having the HTML parser contain a couple of special rules surrounding when the |
I understand what you mean. But is there a way for me to provide linter support for crates like yew? And how to tell the editor to add a syntax hint to a scope. Can #7402 really do it all? |
I have opened a discussion thread in the Rust Internals Forum related to this issue. |
A lot of function-like procedural macros might have syntax alien to Rust (
html!
Yew macro comes to mind). Highlighing based on expansion is not always reliable as a lot of tokens might not end up in the final code.So instead of trying to handle every case, I believe there should be an official way to extend rust-analyzer with custom language services and syntax highlights, this would allow library authors to offer better DX for their custom macros.
Proposal
A TextMate scope for macros (VSCode)
A custom scope like
meta.macro-function.rust
would allow syntax highlighting coming from somewhere else, since scope names cannot be dynamic, the scope should span the entire macro invocation (my_macro!(...)
), this way rules can be matched based on the macro's name.Registering external macro LSPs
External LSPs could be registered for macros and rust-analyzer would forward requests to them. In VSCode, this could be done via the extension API based on this stack overflow answer.
This way rust-analyzer can decide not to forward known macros it can handle, and there are no multiple LSPs processing the same document simultaneously, potentially clashing with each other.
Macros would be processed in the following order:
println
)Unresolved questions
The text was updated successfully, but these errors were encountered: