Skip to content
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

Highlight for Rust string interpolation macros #5845

Open
nikvoid opened this issue Feb 6, 2023 · 4 comments
Open

Highlight for Rust string interpolation macros #5845

nikvoid opened this issue Feb 6, 2023 · 4 comments
Labels
A-language-support Area: Support for programming/text languages C-enhancement Category: Improvements upstream

Comments

@nikvoid
Copy link

nikvoid commented Feb 6, 2023

String literals in macros, which allow interpolation (println!, write!, panic!, etc.) could be highlighted similar to Python format strings.
image

Example for Rust (using injection of svelte):
image

Possible solution is to write small separate tree-sitter grammar for this case (maybe I will do that later...)

@nikvoid nikvoid added the C-enhancement Category: Improvements label Feb 6, 2023
@kirawi
Copy link
Member

kirawi commented Feb 6, 2023

Waiting on tree-sitter/tree-sitter-rust#164

@kirawi kirawi added upstream A-language-support Area: Support for programming/text languages labels Feb 6, 2023
@musjj
Copy link

musjj commented Oct 8, 2023

It got rejected, unfortunately. So we need to wait for semantic tokens to be implemented: #5589

@the-mikedavis
Copy link
Member

I like amaanq's take about this: tree-sitter/tree-sitter-rust#164 (comment). There's really no need for it to be built into tree-sitter-rust. It can be done with a separate very small grammar that parses Rust format strings that we can inject into any macro call who's first argument is a string.

@pascalkuthe
Copy link
Member

We could go one step further and whitelist macrso which are known to accept format specifiers. That would mean it won't work for custom macros that call format_args! internally but I am fine with that (false negatives > false positives). They tend to be rather rare and we can likely cover almost all cases by adding macros from popular crates like defmt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-language-support Area: Support for programming/text languages C-enhancement Category: Improvements upstream
Projects
None yet
Development

No branches or pull requests

5 participants