Skip to content

Commit 6bd8196

Browse files
authored
feat: introduce overflow in summary (#58)
Ref: #46
1 parent 8230d6b commit 6bd8196

File tree

7 files changed

+15430
-14931
lines changed

7 files changed

+15430
-14931
lines changed

corpus/body.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,19 @@ BREAKING-CHANGE: also valid
191191
(breaking_change
192192
(token)
193193
(value))))
194+
195+
================================================================================
196+
Overflowed summary
197+
================================================================================
198+
This is a simple subject
199+
200+
This is a simple body
201+
This is a simple body with so muche characters that it will overflow the summary limit
202+
This is a simple body
203+
--------------------------------------------------------------------------------
204+
205+
(source
206+
(subject)
207+
(message
208+
(overflow)))
209+

grammar.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const NEWLINE = /\r?\n/;
22
const ANYTHING = /[^\n\r]+/;
33
const SUBJECT = /[^\n\r]{1,49}/;
44
const NOT_A_COMMENT = /[^#]/;
5+
const SUMMARY = /[^\n\r]{1,72}/;
56
const SCISSORS = /# -+ >8 -+\r?\n/;
67
const BRANCH_NAME = /[^\s'»"]+/;
78
const COMMIT = /[0-9a-f]{7,40}/;
@@ -55,7 +56,8 @@ module.exports = grammar({
5556
_body_line: ($) =>
5657
choice($._message, $.breaking_change, $.trailer, $.comment, NEWLINE),
5758

58-
_message: () => seq(NOT_A_COMMENT, optional(ANYTHING)),
59+
_message: ($) =>
60+
seq(seq(NOT_A_COMMENT, SUMMARY), optional(alias(ANYTHING, $.overflow))),
5961

6062
trailer: ($) =>
6163
seq(alias(TRAILER_TOKEN, $.token), alias(TRAILER_VALUE, $.value)),

queries/highlights.scm

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,52 @@
11
(comment) @comment
2+
23
(generated_comment) @comment
3-
(title) @text.title
4-
(text) @text
5-
(branch) @text.reference
4+
5+
(title) @markup.heading
6+
7+
; (text) @none
8+
(branch) @markup.link
9+
610
(change) @keyword
7-
(filepath) @text.uri
11+
12+
(filepath) @string.special.url
13+
814
(arrow) @punctuation.delimiter
915

10-
(subject) @text.title
11-
(subject (overflow) @text)
12-
(prefix (type) @keyword)
13-
(prefix (scope) @parameter)
14-
(prefix [
15-
"("
16-
")"
17-
":"
18-
] @punctuation.delimiter)
19-
(prefix [
20-
"!"
21-
] @punctuation.special)
16+
(subject) @markup.heading @spell
2217

23-
(message) @text
18+
(subject
19+
(overflow) @none @spell)
2420

25-
(trailer (token) @keyword)
26-
(trailer (value) @text)
21+
(subject
22+
(subject_prefix) @function @nospell)
2723

28-
(breaking_change (token) @text.warning)
29-
(breaking_change (value) @text)
24+
(prefix
25+
(type) @keyword @nospell)
3026

31-
(scissor) @comment
32-
(subject_prefix) @keyword
27+
(prefix
28+
(scope) @variable.parameter @nospell)
3329

34-
(ERROR) @error
30+
(prefix
31+
[
32+
"("
33+
")"
34+
":"
35+
] @punctuation.delimiter)
36+
37+
(prefix
38+
"!" @punctuation.special)
39+
40+
(message) @spell
41+
42+
(trailer
43+
(token) @label)
44+
45+
; (trailer (value) @none)
46+
(breaking_change
47+
(token) @comment.error)
48+
49+
(breaking_change
50+
(value) @none @spell)
51+
52+
(scissor) @comment

queries/injections.scm

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
((diff) @injection.content
2-
(#set! injection.combined)
3-
(#set! injection.language "diff"))
2+
(#set! injection.language "diff"))
43

54
((rebase_command) @injection.content
6-
(#set! injection.combined)
7-
(#set! injection.language "git_rebase"))
8-
5+
(#set! injection.language "git_rebase"))

src/grammar.json

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,29 @@
276276
"type": "SEQ",
277277
"members": [
278278
{
279-
"type": "PATTERN",
280-
"value": "[^#]"
279+
"type": "SEQ",
280+
"members": [
281+
{
282+
"type": "PATTERN",
283+
"value": "[^#]"
284+
},
285+
{
286+
"type": "PATTERN",
287+
"value": "[^\\n\\r]{1,72}"
288+
}
289+
]
281290
},
282291
{
283292
"type": "CHOICE",
284293
"members": [
285294
{
286-
"type": "PATTERN",
287-
"value": "[^\\n\\r]+"
295+
"type": "ALIAS",
296+
"content": {
297+
"type": "PATTERN",
298+
"value": "[^\\n\\r]+"
299+
},
300+
"named": true,
301+
"value": "overflow"
288302
},
289303
{
290304
"type": "BLANK"

src/node-types.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@
153153
"type": "comment",
154154
"named": true
155155
},
156+
{
157+
"type": "overflow",
158+
"named": true
159+
},
156160
{
157161
"type": "trailer",
158162
"named": true

0 commit comments

Comments
 (0)