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

Improve embedded HEEx and Surface syntax highlighting #570

Merged
merged 1 commit into from
Jul 1, 2024

Conversation

sodapopcan
Copy link
Collaborator

@sodapopcan sodapopcan commented Jun 16, 2024

Currently, embedded HEEx is simply highlighted as HTML. This breaks as soon as you have lines like :for={i <- @numbers} or :if={a > 2} where the < and > are treated as HTML. There are also other random things like {[ that completely break highlighting. I've been just silently dealing with this for four years now and figured I'd fix it anyway I could!

I saw the problem was mainly that you end up with a recursion error when you have syntax/elixir.vim calling syn import @EELIXIR syntax/eelixir.vim and syntax/eelixir.vim calling syn import @elixirTop syntax/elixir.vim. After trying trying to hack around this, I figured duplication was the best answer and it's worked quite nicely.

This PR does this following:

  • Properly highlight embedded HEEx (and Surface)
  • Re-name groups to favour HEEx naming (this would break any customizations people have done)
  • Add highlight group for phx- attributes
  • Add highlight group for heex attribute (eg, some_attr="some value")
  • Add highlight group for heex special attribute (ie, :if, :for, and :let)

I have not copied this stuff over to syntax/eelixir.vim as I wanted a review first. I can certainly roll back any of the breaking change stuff, but I don't know how many Elixirists still use vanilla Vim.

Thanks!

Closes #566

@sodapopcan sodapopcan force-pushed the improve-heex-highlighting branch 7 times, most recently from 8247413 to 0973550 Compare June 23, 2024 13:30
@sodapopcan sodapopcan marked this pull request as ready for review June 23, 2024 13:31
@sodapopcan
Copy link
Collaborator Author

This is ready.

I can't for the life of me figure out how to contain region delimiters within other regions. Is this even possible? In any event, template delimiters get matched inside elixir code, ie, outside of template sigils. This was mainly a problem for heex's {} as it was matching tuples. I got around this requiring a = before the start match.

* Properly highlight embedded HEEx (and Surface)
* Re-name groups to favour HEEx naming
* Add highlight group for `phx-` attributes
* Add highlight group for heex attribute (eg, `some_attr="some value"`)
* Add highlight group for heex special attribute (ie, `:if` and `:for`)
* Add heexComponentName group
* Add heexEndComponent group
@sodapopcan sodapopcan force-pushed the improve-heex-highlighting branch 2 times, most recently from 49f95d3 to 8377bd0 Compare June 23, 2024 16:27
Copy link
Collaborator

@jbodah jbodah left a comment

Choose a reason for hiding this comment

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

I have not had a chance to test this, however we can just iterate if there's follow-up

@jbodah jbodah merged commit c23000a into elixir-editors:master Jul 1, 2024
@sodapopcan
Copy link
Collaborator Author

Thank you!

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.

~H sigil syntax highlighting breaks on < and > inside embedded elixir tags
2 participants