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

feat: Highlight Rust String interpolation macros #12768

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

nik-rev
Copy link
Contributor

@nik-rev nik-rev commented Feb 4, 2025

Hi, so I made a tree sitter grammar for rust format_args! which improves the Helix Rust experience, first of all by making it look prettier and easier to tell text apart from actual syntax

parser repo: tree-sitter-rustfmt: https://github.com/nik-rev/tree-sitter-rustfmt

Here's how it looks like:

Before

Image

After

Image

Notes

At the moment the PR injects this language into every string. What should be done instead is that it's injected into every string within a macro's arguments. I tried to do this, I'm not sure how to exactly. This was my best attempt, but it completely turned off syntax highlighting when I tried it:

(macro_invocation
  (string_content) @injection.content
  (#set! injection.language "rustfmt"))

Closes #5845

@@ -75,3 +75,7 @@
[(string_literal) (raw_string_literal)] @injection.content
)
(#set! injection.language "sql"))

; TODO: change this so it injects into all strings within a macro call
((string_content) @injection.content
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to be smarter here and match on the macro name

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I think just injecting it for stdlib and a few known crate macros (e.g. slog and tracing macros) would be a huge improvement already, and then you could always add more crates over time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Highlight for Rust string interpolation macros
3 participants