wkirschbaum / heex-ts-mode

Emacs Heex major mode using Treesitter for fontification, navigation and indentation
GNU General Public License v3.0
18 stars 2 forks source link

Font lock for embedded Elixir #2

Open hochata opened 1 year ago

hochata commented 1 year ago

Hi!

Currently, code in <%= "embedded expressions" > gets the default face. It would be nice to have Elixir syntax highlight in those blocks.

wkirschbaum commented 1 year ago

I agree :) but not sure how to approach this yet. We don't get much information from the tree-sitter-heex grammar as a directive ( embedded expressions ) might look like this:

(directive [1, 2] - [1, 19]
      (partial_expression_value [1, 5] - [1, 16]))
 ....
(directive [3, 2] - [3, 11]
   (ending_expression_value [3, 4] - [3, 8]))

where the directive neither encloses or reveals the content.

Another option would be to overlay elixir syntax on top of the heex syntax, but currently elixir-ts-mode requires heex-ts-mode, so then we fall into the circular dependency.

Unfortunately with the MELPA commit requirements we have to have 2 separate packages for these two modes, but we can combine elixir and heex-mode on emacs master ( only for emacs 30 ) and we can then overlay, but it will be at least a year from now, so will be nice to have an interim solution.

The option I am hoping for is to enhance the tree-sitter-heex grammar with enough information to apply some faces.

hochata commented 1 year ago

The option I am hoping for is to enhance the tree-sitter-heex grammar with enough information to apply some faces.

I think that is a good idea. To move all the common code (like queries and indentation rules) from elixir-ts-mode and heex-ts-mode into a common elixit-ts-base file so there are no cyclic depedencies.

KaranAhlawat commented 5 months ago

Could we do something like injecting the elixir grammar into the enclosed regions? From what I know injecting grammars into ranges is pretty common in the tree-sitter world, and last I checked it is supported in Emacs' tree-sitter (treesit) implementation as well.

KaranAhlawat commented 5 months ago

We can probably do something like this here. Neovim is able to take advantage of these injections.scm files, and I'm hopeful we can reproduce this (to the best of treesit's current capabilities) inside Emacs. https://github.com/phoenixframework/tree-sitter-heex/blob/main/queries/injections.scm

wkirschbaum commented 4 months ago

I pull request would be welcome, I won't be able to work on this in the near future.

KaranAhlawat commented 4 months ago

I'll try my hand at it then!