From 44293dfd2248d82f39bb8e5b91cbb1daf2e24290 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Fri, 27 Jun 2025 10:39:38 -0400 Subject: [PATCH] Change tree-sitter parser for Git commit message files The gbprod grammar is more complete and featureful than mine, and more actively maintained. I will archive my tree-sitter-git-commit in favor of gbprod's. The new queries are based on the ones in the repo upstream but I modified them to look similar to the highlights before this commit. Also I've updated the tab-width so that change nodes in the generated message are indented correctly. --- languages.toml | 7 +++--- runtime/queries/git-commit/highlights.scm | 30 +++++++++++------------ runtime/queries/git-commit/injections.scm | 4 +-- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/languages.toml b/languages.toml index 63b538420..a2dc2053d 100644 --- a/languages.toml +++ b/languages.toml @@ -1859,13 +1859,14 @@ name = "git-commit" scope = "git.commitmsg" file-types = [{ glob = "COMMIT_EDITMSG" }, { glob = "MERGE_MSG" }] comment-token = "#" -indent = { tab-width = 2, unit = " " } +indent = { tab-width = 4, unit = " " } rulers = [51, 73] text-width = 72 +grammar = "gitcommit" [[grammar]] -name = "git-commit" -source = { git = "https://github.com/the-mikedavis/tree-sitter-git-commit", rev = "6f193a66e9aa872760823dff020960c6cedc37b3" } +name = "gitcommit" +source = { git = "https://github.com/gbprod/tree-sitter-gitcommit", rev = "a716678c0f00645fed1e6f1d0eb221481dbd6f6d" } [[language]] name = "diff" diff --git a/runtime/queries/git-commit/highlights.scm b/runtime/queries/git-commit/highlights.scm index 319d76569..bc84d0371 100644 --- a/runtime/queries/git-commit/highlights.scm +++ b/runtime/queries/git-commit/highlights.scm @@ -1,18 +1,18 @@ +[(comment) (generated_comment) (scissor)] @comment (subject) @markup.heading -(path) @string.special.path (branch) @string.special.symbol -(commit) @constant -(item) @markup.link.url -(header) @tag +(filepath) @string.special.path +(arrow) @punctuation.delimiter +(subject (subject_prefix) @function) +(prefix (type) @keyword) +(prefix (scope) @variable.parameter) +(prefix [ "(" ")" ":" ] @punctuation.delimiter) +(prefix "!" @punctuation.special) +(trailer (token) @variable.other.member) +(trailer (value) @string) +(breaking_change (token) @special) -(change kind: "new file" @diff.plus) -(change kind: "deleted" @diff.minus) -(change kind: "modified" @diff.delta) -(change kind: "renamed" @diff.delta.moved) - -(trailer - key: (trailer_key) @variable.other.member - value: (trailer_value) @string) - -[":" "=" "->" (scissors)] @punctuation.delimiter -(comment) @comment +(change kind: (new)) @diff.plus +(change kind: (deleted)) @diff.minus +(change kind: (modified)) @diff.delta +(change kind: [(renamed) (typechange)]) @diff.delta.moved diff --git a/runtime/queries/git-commit/injections.scm b/runtime/queries/git-commit/injections.scm index 79f7691a9..823188e01 100644 --- a/runtime/queries/git-commit/injections.scm +++ b/runtime/queries/git-commit/injections.scm @@ -1,6 +1,4 @@ -(((scissors) - (message) @injection.content) - (#set! injection.include-children) +((diff) @injection.content (#set! injection.language "diff")) ((rebase_command) @injection.content