From 5dc81628a7eed8fe66c63b8ec4f6e2953f8d62ae Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Thu, 23 Dec 2021 19:57:57 -0600 Subject: [PATCH 1/7] add submodule on tree-sitter-git-diff --- .gitmodules | 4 ++++ helix-syntax/languages/tree-sitter-git-diff | 1 + languages.toml | 9 +++++++++ 3 files changed, 14 insertions(+) create mode 160000 helix-syntax/languages/tree-sitter-git-diff diff --git a/.gitmodules b/.gitmodules index d5bd61c9e9dd..422671b4e729 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/helix-syntax/languages/tree-sitter-git-diff b/helix-syntax/languages/tree-sitter-git-diff new file mode 160000 index 000000000000..c12e6ecb5448 --- /dev/null +++ b/helix-syntax/languages/tree-sitter-git-diff @@ -0,0 +1 @@ +Subproject commit c12e6ecb54485f764250556ffd7ccb18f8e2942b diff --git a/languages.toml b/languages.toml index 616ef234e401..b3fd0fc648b2 100644 --- a/languages.toml +++ b/languages.toml @@ -481,3 +481,12 @@ roots = [] file-types = ["COMMIT_EDITMSG"] comment-token = "#" indent = { tab-width = 2, unit = " " } + +[[language]] +name = "git-diff" +scope = "git.diff" +roots = [] +file-types = ["diff"] +injection-regex = "diff" +comment-token = "#" +indent = { tab-width = 2, unit = " " } From 1571fde4707a0d72518ea626be71f4b558788aa5 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Thu, 23 Dec 2021 20:50:19 -0600 Subject: [PATCH 2/7] add git-diff highlights --- runtime/queries/git-diff/highlights.scm | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 runtime/queries/git-diff/highlights.scm diff --git a/runtime/queries/git-diff/highlights.scm b/runtime/queries/git-diff/highlights.scm new file mode 100644 index 000000000000..1c1a8829fb3f --- /dev/null +++ b/runtime/queries/git-diff/highlights.scm @@ -0,0 +1,6 @@ +[(addition) (new_file)] @diff.plus +[(deletion) (old_file)] @diff.minus + +(commit) @constant +(location) @attribute +(command) @markup.bold From 73c514f1722ee570abcc23171d3da3b70e24aaca Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Fri, 24 Dec 2021 18:57:48 -0600 Subject: [PATCH 3/7] inject git-diff into git-commit --- runtime/queries/git-commit/highlights.scm | 4 ---- runtime/queries/git-commit/injections.scm | 12 +++--------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/runtime/queries/git-commit/highlights.scm b/runtime/queries/git-commit/highlights.scm index a74bb3817c7c..ffcc31aef3e0 100644 --- a/runtime/queries/git-commit/highlights.scm +++ b/runtime/queries/git-commit/highlights.scm @@ -13,7 +13,3 @@ [":" "->"] @punctuation.delimeter (comment) @comment - -; once we have diff injections, @comment should become @none -((comment (scissors)) - (message)+ @comment) diff --git a/runtime/queries/git-commit/injections.scm b/runtime/queries/git-commit/injections.scm index 2837a586589c..1ed88153c3d1 100644 --- a/runtime/queries/git-commit/injections.scm +++ b/runtime/queries/git-commit/injections.scm @@ -1,12 +1,6 @@ -; 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.language "diff")) ; once a rebase grammar is available, we can inject rebase highlighting into ; interactive rebase summary sections like so: From bf51082619af606f2323461fd9694a181d620cf2 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Sat, 25 Dec 2021 13:26:34 -0600 Subject: [PATCH 4/7] update tree-sitter-git-commit with fix for bad diff case --- helix-syntax/languages/tree-sitter-git-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-syntax/languages/tree-sitter-git-commit b/helix-syntax/languages/tree-sitter-git-commit index 5cd4776c86c8..066e395e1107 160000 --- a/helix-syntax/languages/tree-sitter-git-commit +++ b/helix-syntax/languages/tree-sitter-git-commit @@ -1 +1 @@ -Subproject commit 5cd4776c86c82d9d6afdc8c73a47a08057aef618 +Subproject commit 066e395e1107df17183cf3ae4230f1a1406cc972 From 1c2b05e3dbc1213284043b8f36ee51ca249116b0 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Sat, 25 Dec 2021 13:43:00 -0600 Subject: [PATCH 5/7] add git-diff to language support docs --- book/src/generated/lang-support.md | 1 + 1 file changed, 1 insertion(+) diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 5d172751a070..91575c629ece 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -12,6 +12,7 @@ | elixir | ✓ | | | `elixir-ls` | | fish | ✓ | ✓ | ✓ | | | git-commit | ✓ | | | | +| git-diff | ✓ | | | | | glsl | ✓ | | ✓ | | | go | ✓ | ✓ | ✓ | `gopls` | | html | ✓ | | | | From 7cd606b05c10a9d7353b7e47a9c18c81dff43551 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Sun, 26 Dec 2021 11:26:09 -0600 Subject: [PATCH 6/7] 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 --- runtime/queries/git-commit/injections.scm | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/queries/git-commit/injections.scm b/runtime/queries/git-commit/injections.scm index 1ed88153c3d1..bd96f1de31d5 100644 --- a/runtime/queries/git-commit/injections.scm +++ b/runtime/queries/git-commit/injections.scm @@ -1,5 +1,6 @@ ((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 From 956397c58bcc34aa2db4349bcf733ace317282c2 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Mon, 27 Dec 2021 07:14:23 -0600 Subject: [PATCH 7/7] set diff language's scope as source.diff --- languages.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/languages.toml b/languages.toml index b3fd0fc648b2..c3ae9f628308 100644 --- a/languages.toml +++ b/languages.toml @@ -484,7 +484,7 @@ indent = { tab-width = 2, unit = " " } [[language]] name = "git-diff" -scope = "git.diff" +scope = "source.diff" roots = [] file-types = ["diff"] injection-regex = "diff"