elixir-lang / tree-sitter-elixir

Elixir grammar for tree-sitter
https://elixir-lang.org/tree-sitter-elixir
Apache License 2.0
245 stars 24 forks source link

Add HEEx language injection for `~H` sigils #34

Closed connorlay closed 2 years ago

connorlay commented 2 years ago

See https://github.com/elixir-lang/tree-sitter-elixir/issues/2 and https://github.com/connorlay/tree-sitter-heex/pull/11

This PR adds tree-sitter-heex language injection into ~H sigils provided by Phoenix Live View.

Here is an example of syntax highlighting of https://github.com/fly-apps/live_beats/blob/master/lib/live_beats_web/live/layout_component.ex: image

the-mikedavis commented 2 years ago
This looks quite nice in Helix as well :) ![livebeats-helix](https://user-images.githubusercontent.com/21230295/163725616-bf403c63-6f16-430e-9382-1d6dec6bd0ca.png)

This is a bit off-topic for this PR, but what do you think about using @keyword for the captures of the templating tokens:

; https://github.com/the-mikedavis/helix/blob/b2e8c9188e83c95adf5e5cb9d63b487686d7f610/runtime/queries/heex/highlights.scm#L20-L28

; Non-comment or tag delimiters
[
  "{"
  "}"
  "<%"
  "<%="
  "<%%="
  "%>"
] @keyword

@keyword is a bit "loud" depending on how the capture is themed but it's in line with the ERB/EJS highlights: https://github.com/tree-sitter/tree-sitter-embedded-template/blob/d21df11b0ecc6fd211dbe11278e92ef67bd17e97/queries/highlights.scm