Wilfred / difftastic

a structural diff that understands syntax 🟥🟩
https://difftastic.wilfred.me.uk/
MIT License
21.1k stars 344 forks source link

Changes in Elixir HEEx sigils are not highlighted #784

Open crbelaus opened 3 hours ago

crbelaus commented 3 hours ago

When changing code inside an embedded HEEx sigil on Elixir, difftastic is not highlighting the changes but the whole sigil.

I have the following code:

  def render(assigns) do
    if assigns.count == 5 do
      raise "Crash on render"
    end

    ~H"""
    <span><%= @count %></span>
    <button phx-click="inc">+</button>
    <button phx-click="dec">-</button>
    <button phx-click="error">Crash on handle_event</button>

    <.link href="/?crash=mount">Crash on mount</.link>
    <.link patch="/?crash=handle_params">Crash on handle_params</.link>

    <style type="text/css">
      body { padding: 1em; }
    </style>
    """
  end

And I change it to (just added the new class to the first <span> element):

  def render(assigns) do
    if assigns.count == 5 do
      raise "Crash on render"
    end

    ~H"""
    <span class="new"><%= @count %></span>
    <button phx-click="inc">+</button>
    <button phx-click="dec">-</button>
    <button phx-click="error">Crash on handle_event</button>

    <.link href="/?crash=mount">Crash on mount</.link>
    <.link patch="/?crash=handle_params">Crash on handle_params</.link>

    <style type="text/css">
      body { padding: 1em; }
    </style>
    """
  end

When using basic git diff it highlights the changed line. On the other hand, difftastic highlights the whole block:

image

It is important to note that diffs are properly highlighted on HEEx files. The problem appears only on embedded HEEx blocks.

I am using latest difftastic on MacOS:

Difftastic 0.61.0

Toolchain: 1.82.0
System:    macos aarch64
crbelaus commented 3 hours ago

I believe that the involved tree sitter parsers are: