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

Font lock for embedded Elixir #2

Open
hochata opened this issue Mar 12, 2023 · 6 comments
Open

Font lock for embedded Elixir #2

hochata opened this issue Mar 12, 2023 · 6 comments

Comments

@hochata
Copy link

hochata commented Mar 12, 2023

Hi!

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

@wkirschbaum
Copy link
Owner

wkirschbaum commented Mar 12, 2023

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
Copy link
Author

hochata commented Mar 13, 2023

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
Copy link

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
Copy link

KaranAhlawat commented Apr 15, 2024

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
Copy link
Owner

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

@KaranAhlawat
Copy link

I'll try my hand at it then!

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

No branches or pull requests

3 participants