Skip to content

Commit

Permalink
feat: introduce overflow in summary
Browse files Browse the repository at this point in the history
Ref: #46
  • Loading branch information
gbprod committed Feb 29, 2024
1 parent 8230d6b commit 15e7610
Show file tree
Hide file tree
Showing 7 changed files with 15,430 additions and 14,931 deletions.
16 changes: 16 additions & 0 deletions corpus/body.txt
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,19 @@ BREAKING-CHANGE: also valid
(breaking_change
(token)
(value))))

================================================================================
Overflowed summary
================================================================================
This is a simple subject

This is a simple body
This is a simple body with so muche characters that it will overflow the summary limit
This is a simple body
--------------------------------------------------------------------------------

(source
(subject)
(message
(overflow)))

4 changes: 3 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const NEWLINE = /\r?\n/;
const ANYTHING = /[^\n\r]+/;
const SUBJECT = /[^\n\r]{1,49}/;
const NOT_A_COMMENT = /[^#]/;
const SUMMARY = /[^\n\r]{1,72}/;
const SCISSORS = /# -+ >8 -+\r?\n/;
const BRANCH_NAME = /[^\s'”»"“]+/;
const COMMIT = /[0-9a-f]{7,40}/;
Expand Down Expand Up @@ -55,7 +56,8 @@ module.exports = grammar({
_body_line: ($) =>
choice($._message, $.breaking_change, $.trailer, $.comment, NEWLINE),

_message: () => seq(NOT_A_COMMENT, optional(ANYTHING)),
_message: ($) =>
seq(seq(NOT_A_COMMENT, SUMMARY), optional(alias(ANYTHING, $.overflow))),

trailer: ($) =>
seq(alias(TRAILER_TOKEN, $.token), alias(TRAILER_VALUE, $.value)),
Expand Down
66 changes: 42 additions & 24 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,34 +1,52 @@
(comment) @comment

(generated_comment) @comment
(title) @text.title
(text) @text
(branch) @text.reference

(title) @markup.heading

; (text) @none
(branch) @markup.link

(change) @keyword
(filepath) @text.uri

(filepath) @string.special.url

(arrow) @punctuation.delimiter

(subject) @text.title
(subject (overflow) @text)
(prefix (type) @keyword)
(prefix (scope) @parameter)
(prefix [
"("
")"
":"
] @punctuation.delimiter)
(prefix [
"!"
] @punctuation.special)
(subject) @markup.heading @spell

(message) @text
(subject
(overflow) @none @spell)

(trailer (token) @keyword)
(trailer (value) @text)
(subject
(subject_prefix) @function @nospell)

(breaking_change (token) @text.warning)
(breaking_change (value) @text)
(prefix
(type) @keyword @nospell)

(scissor) @comment
(subject_prefix) @keyword
(prefix
(scope) @variable.parameter @nospell)

(ERROR) @error
(prefix
[
"("
")"
":"
] @punctuation.delimiter)

(prefix
"!" @punctuation.special)

(message) @spell

(trailer
(token) @label)

; (trailer (value) @none)
(breaking_change
(token) @comment.error)

(breaking_change
(value) @none @spell)

(scissor) @comment
7 changes: 2 additions & 5 deletions queries/injections.scm
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
((diff) @injection.content
(#set! injection.combined)
(#set! injection.language "diff"))
(#set! injection.language "diff"))

((rebase_command) @injection.content
(#set! injection.combined)
(#set! injection.language "git_rebase"))

(#set! injection.language "git_rebase"))
22 changes: 18 additions & 4 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,29 @@
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "[^#]"
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "[^#]"
},
{
"type": "PATTERN",
"value": "[^\\n\\r]{1,72}"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[^\\n\\r]+"
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[^\\n\\r]+"
},
"named": true,
"value": "overflow"
},
{
"type": "BLANK"
Expand Down
4 changes: 4 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@
"type": "comment",
"named": true
},
{
"type": "overflow",
"named": true
},
{
"type": "trailer",
"named": true
Expand Down
Loading

0 comments on commit 15e7610

Please sign in to comment.