Add tree-sitter-git-diff (#1373)

* add submodule on tree-sitter-git-diff

* add git-diff highlights

* inject git-diff into git-commit

* update tree-sitter-git-commit with fix for bad diff case

* add git-diff to language support docs

* include-children in diff injections

This ensures that children nodes of $.message are included in the
injection, such as $.user or issue/pr numbers. Without this change,
diffs containing '#' or '@' characters can trip up the injection and
be parsed separately.

See https://github.com/helix-editor/helix/pull/1373#issuecomment-1001215629

* set diff language's scope as source.diff
This commit is contained in:
Michael Davis 2021-12-29 09:31:23 -06:00 committed by GitHub
parent 49444f9c05
commit bcf3808e97
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 26 additions and 14 deletions

4
.gitmodules vendored
View file

@ -174,3 +174,7 @@
path = helix-syntax/languages/tree-sitter-git-commit path = helix-syntax/languages/tree-sitter-git-commit
url = https://github.com/the-mikedavis/tree-sitter-git-commit.git url = https://github.com/the-mikedavis/tree-sitter-git-commit.git
shallow = true shallow = true
[submodule "helix-syntax/languages/tree-sitter-git-diff"]
path = helix-syntax/languages/tree-sitter-git-diff
url = https://github.com/the-mikedavis/tree-sitter-git-diff.git
shallow = true

View file

@ -12,6 +12,7 @@
| elixir | ✓ | | | `elixir-ls` | | elixir | ✓ | | | `elixir-ls` |
| fish | ✓ | ✓ | ✓ | | | fish | ✓ | ✓ | ✓ | |
| git-commit | ✓ | | | | | git-commit | ✓ | | | |
| git-diff | ✓ | | | |
| glsl | ✓ | | ✓ | | | glsl | ✓ | | ✓ | |
| go | ✓ | ✓ | ✓ | `gopls` | | go | ✓ | ✓ | ✓ | `gopls` |
| html | ✓ | | | | | html | ✓ | | | |

@ -1 +1 @@
Subproject commit 5cd4776c86c82d9d6afdc8c73a47a08057aef618 Subproject commit 066e395e1107df17183cf3ae4230f1a1406cc972

@ -0,0 +1 @@
Subproject commit c12e6ecb54485f764250556ffd7ccb18f8e2942b

View file

@ -481,3 +481,12 @@ roots = []
file-types = ["COMMIT_EDITMSG"] file-types = ["COMMIT_EDITMSG"]
comment-token = "#" comment-token = "#"
indent = { tab-width = 2, unit = " " } indent = { tab-width = 2, unit = " " }
[[language]]
name = "git-diff"
scope = "source.diff"
roots = []
file-types = ["diff"]
injection-regex = "diff"
comment-token = "#"
indent = { tab-width = 2, unit = " " }

View file

@ -13,7 +13,3 @@
[":" "->"] @punctuation.delimeter [":" "->"] @punctuation.delimeter
(comment) @comment (comment) @comment
; once we have diff injections, @comment should become @none
((comment (scissors))
(message)+ @comment)

View file

@ -1,12 +1,7 @@
; once a diff grammar is available, we can inject diff highlighting into the ((comment (scissors))
; trailer after scissors (git commit --verbose) (message) @injection.content
; see https://github.com/helix-editor/helix/pull/1338#issuecomment-1000013539 (#set! injection.include-children)
; (#set! injection.language "diff"))
; ((comment (scissors))
; (message) @injection.content
; (#set! injection.language "diff"))
; ---
; once a rebase grammar is available, we can inject rebase highlighting into ; once a rebase grammar is available, we can inject rebase highlighting into
; interactive rebase summary sections like so: ; interactive rebase summary sections like so:

View file

@ -0,0 +1,6 @@
[(addition) (new_file)] @diff.plus
[(deletion) (old_file)] @diff.minus
(commit) @constant
(location) @attribute
(command) @markup.bold