the-mikedavis / tree-sitter-diff

A tree-sitter grammar for `diff` output
https://the-mikedavis.github.io/tree-sitter-diff/
MIT License
37 stars 11 forks source link

Nodes hierarchy (addition, deletion and context's parents) #8

Closed samueloph closed 1 year ago

samueloph commented 1 year ago

addition, deletion and context are not parsed under index, file_change, new_file, old_file, location...

This makes it impossible (or at least hard) to add support for diff for the context plugin (https://github.com/nvim-treesitter/nvim-treesitter-context).

For reference: https://github.com/nvim-treesitter/nvim-treesitter-context/issues/302

Do you think it makes sense that addition, deletion and context should be child nodes of the diff's headers?

the-mikedavis commented 1 year ago

I was hoping to add some hierarchy, I've just been procrastinating 😄

I pushed 16d01ac5f22eb48f4c7b726a421bdc72ed4d4051 which organizes each dif --git a b section into a block node and introduces hunks which are a sequence of hunk. hunk is then a location and a changes node. That changes node groups together the addition, deletion and context nodes in that hunk.

What do you think, will this work for context?

samueloph commented 1 year ago

This is awesome! I can now get command and location in the context pop-up.

tree-sitter-diff-issue-8

This is the configuration I've used:

cat /home/samueloph/.local/share/nvim/site/pack/packer/start/nvim-treesitter-context/queries/diff/context.scm 
([
  (block)
  (hunk)
] @context)

Thank you!