elixir-tools / elixir-tools.nvim

Neovim plugin for Elixir
MIT License
403 stars 30 forks source link

No leex or ~L highlighting #83

Closed zolrath closed 1 year ago

zolrath commented 1 year ago

Hello! After replacing my custom Elixir setup using lazy.vim with the instructions in the readme of this repo, I do not have syntax highlighting for the "eelixir" filetype.

ft=eelixir

image

ft=heex

image

Co-located in a LiveView

image

mhanberg commented 1 year ago

You'll need to use nvim-treesitter for highlighting. TSInstall eex

zolrath commented 1 year ago

In my original lazy.vim config I have:

  -- add elixir to treesitter
  {
    "nvim-treesitter/nvim-treesitter",
    opts = function(_, opts)
      vim.list_extend(opts.ensure_installed, { "elixir", "eex" })
    end,
  }

which ensures that both eex and elixir are installed.

After adding that back I can confirm that a fresh install will have leex highlighting!

mhanberg commented 1 year ago

84 will solve for this I think

zolrath commented 1 year ago

Sounds good!

image

The heex rendering definitely has an advantage in that the HTML is properly highlighted as well.

I seem to remember having html highlighting with leex, was that just prior to treesitter or does your leex look like the heex example?

mhanberg commented 1 year ago

That was prior to treesitter.

leex and eex highlighting as provided by vim-elixir is "html with elixir inside the <% %>", whereas eex with treesitter is just "elixir inside the <% %>".

this is currently a treesitter/nvim-treesitter limitation. ERB from ruby has the same drawback.

It's because eex is not HTML specific, you can use it with any plaintext document.

a lot of people change the filetype detection of html.eex and html.leex templates to use the heex parser, even tho it might technically be wrong sometimes (like when you put the embedded elixir inside an opening tag <div class="<%= @class %>"></div>

I personally have only used heex and surface at work recently, and when i've used eex within my open source, it has been *.ex.eex templates.

mhanberg commented 1 year ago

https://github.com/nvim-treesitter/nvim-treesitter/issues/1352

zolrath commented 1 year ago

Thought that might be the case, thanks for the detail!

Hopefully there's some movement on that issue someday, interesting to see work being done on compatible grammars like https://github.com/rockerBOO/tree-sitter-html-eex/ if treesitter itself doesn't end up supporting embedded templates.