Wilfred / difftastic

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

tree-sitter-lua is out-dated #701

Closed Ordoviz closed 5 months ago

Ordoviz commented 5 months ago

I was diffing Lua files and got this warning: 6 Lua parse errors, exceeded DFT_PARSE_ERROR_LIMIT. This is because the tree-sitter grammar used by difftastic fails to parse if next({})

$ echo -e 'if next({}) then\nend' | difft --dump-ts /dev/stdin --override='*:lua'
program (0, 0) - (2, 0)
  if_statement (0, 0) - (1, 3)
    if (0, 0) - (0, 2) "if"
    ERROR (0, 3) - (0, 7)
      next (0, 3) - (0, 7) "next"
    condition_expression (0, 7) - (0, 11)
      ( (0, 7) - (0, 8) "("
      table (0, 8) - (0, 10)
        { (0, 8) - (0, 9) "{"
        } (0, 9) - (0, 10) "}"
      ) (0, 10) - (0, 11) ")"
    then (0, 12) - (0, 16) "then"
    end (1, 0) - (1, 3) "end"

A better alternative is https://github.com/tree-sitter-grammars/tree-sitter-lua, which is used by the Helix text editor and NeoVim.

You would probably only need to update the vendored_parsers/tree-sitter-lua subtree and change scanner.cc in https://github.com/Wilfred/difftastic/blob/f52ca706f3a6c6fb31ea31856534a8b56c153095/build.rs#L224 to scanner.c.