Skip to content

Commit

Permalink
Add tree-sitter-git-diff (#1373)
Browse files Browse the repository at this point in the history
* 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 #1373 (comment)

* set diff language's scope as source.diff
  • Loading branch information
the-mikedavis authored Dec 29, 2021
1 parent 49444f9 commit bcf3808
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 14 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,7 @@
path = helix-syntax/languages/tree-sitter-git-commit
url = https://github.com/the-mikedavis/tree-sitter-git-commit.git
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
1 change: 1 addition & 0 deletions book/src/generated/lang-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
| elixir || | | `elixir-ls` |
| fish |||| |
| git-commit || | | |
| git-diff || | | |
| glsl || || |
| go |||| `gopls` |
| html || | | |
Expand Down
2 changes: 1 addition & 1 deletion helix-syntax/languages/tree-sitter-git-commit
1 change: 1 addition & 0 deletions helix-syntax/languages/tree-sitter-git-diff
Submodule tree-sitter-git-diff added at c12e6e
9 changes: 9 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -481,3 +481,12 @@ roots = []
file-types = ["COMMIT_EDITMSG"]
comment-token = "#"
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 = " " }
4 changes: 0 additions & 4 deletions runtime/queries/git-commit/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,3 @@

[":" "->"] @punctuation.delimeter
(comment) @comment

; once we have diff injections, @comment should become @none
((comment (scissors))
(message)+ @comment)
13 changes: 4 additions & 9 deletions runtime/queries/git-commit/injections.scm
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
; once a diff grammar is available, we can inject diff highlighting into the
; trailer after scissors (git commit --verbose)
; see https://github.com/helix-editor/helix/pull/1338#issuecomment-1000013539
;
; ((comment (scissors))
; (message) @injection.content
; (#set! injection.language "diff"))

; ---
((comment (scissors))
(message) @injection.content
(#set! injection.include-children)
(#set! injection.language "diff"))

; once a rebase grammar is available, we can inject rebase highlighting into
; interactive rebase summary sections like so:
Expand Down
6 changes: 6 additions & 0 deletions runtime/queries/git-diff/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[(addition) (new_file)] @diff.plus
[(deletion) (old_file)] @diff.minus

(commit) @constant
(location) @attribute
(command) @markup.bold

0 comments on commit bcf3808

Please sign in to comment.