Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JSON] Fix comment punctuation scopes #3870

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 43 additions & 18 deletions JSON/JSON.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,53 @@ contexts:
scope: invalid.illegal.expected-sequence-separator.json

comments:
- match: /\*\*(?!/)
scope: punctuation.definition.comment.json
push:
- meta_scope: comment.block.documentation.json
- meta_include_prototype: false
- match: \*/
pop: 1
- match: ^\s*(\*)(?!/)
captures:
1: punctuation.definition.comment.json
- include: block-comments
- include: line-comments

block-comments:
# empty block comments
- match: /\*\*+/
scope: comment.block.empty.json punctuation.definition.comment.json
# documentation block comments
- match: /\*\*+
scope: punctuation.definition.comment.begin.json
push: block-comment-documentation-body
# normal block comments
- match: /\*
scope: punctuation.definition.comment.json
push:
- meta_scope: comment.block.json
- meta_include_prototype: false
- match: \*/
pop: 1
- match: (//).*$\n?
scope: comment.line.double-slash.js
scope: punctuation.definition.comment.begin.json
push: block-comment-body

block-comment-documentation-body:
- meta_include_prototype: false
- meta_scope: comment.block.documentation.json
- match: \*+/
scope: punctuation.definition.comment.end.json
pop: 1
- match: ^\s*(\*)(?![*/])
captures:
1: punctuation.definition.comment.json

block-comment-body:
- meta_include_prototype: false
- meta_scope: comment.block.json
- match: \*/
scope: punctuation.definition.comment.end.json
pop: 1
- match: ^\s*(\*)(?![*/])
captures:
1: punctuation.definition.comment.json

line-comments:
- match: //
scope: punctuation.definition.comment.json
push: line-comment-body

line-comment-body:
- meta_include_prototype: false
- meta_scope: comment.line.double-slash.json
- match: $\n?
pop: 1

constant:
- match: \b(?:false|true)\b
scope: constant.language.boolean.json
Expand Down
39 changes: 32 additions & 7 deletions JSON/syntax_test_json.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
// SYNTAX TEST "Packages/JSON/JSON.sublime-syntax"

/* comment */
// ^^^^^^^^^^^^^ comment.block.json
// ^^ punctuation.definition.comment.begin.json
// ^^ punctuation.definition.comment.end.json

/**
*
// ^ comment.block.documentation.json punctuation.definition.comment.json
*/
// <- comment.block.documentation.json
//^^ comment.block.documentation.json punctuation.definition.comment.end.json

/**/
// <- comment.block.empty.json punctuation.definition.comment.json
//^^ comment.block.empty.json punctuation.definition.comment.json

/********/
// <- comment.block.empty.json punctuation.definition.comment.json
//^^^^^^^^ comment.block.empty.json punctuation.definition.comment.json

/**************
// <- comment.block.documentation.json punctuation.definition.comment.begin.json
//^^^^^^^^^^^^^ comment.block.documentation.json punctuation.definition.comment.begin.json
**************/
// <- comment.block.documentation.json punctuation.definition.comment.end.json
//^^^^^^^^^^^^^ comment.block.documentation.json punctuation.definition.comment.end.json

{
// <- meta.mapping.json punctuation.section.mapping.begin.json
"bool": false,
Expand Down Expand Up @@ -32,7 +59,7 @@
"array": [ /**/ ],
// ^^^^^^^^ meta.mapping.value.json meta.sequence.json
// ^ punctuation.section.sequence.begin.json
// ^^^^ comment.block.json
// ^^^^ comment.block.empty.json punctuation.definition.comment.json
// ^ punctuation.section.sequence.end.json

"dict": {"foo": },
Expand All @@ -52,13 +79,15 @@
"foo": "bar"
// comment
// ^ - invalid
// ^^^^^^^^^^ comment.line.double-slash.js
// ^^^^^^^^^^ comment.line.double-slash.json
,
// ^ punctuation.separator.sequence.json
"foo": "bar"
/* comment */
// ^ - invalid
// ^^^^^^^^^^^^^ comment.block.json
// ^^ punctuation.definition.comment.begin.json
// ^^ punctuation.definition.comment.end.json
},
//^ punctuation.section.mapping.end.json
// ^ punctuation.separator.sequence.json
Expand Down Expand Up @@ -96,7 +125,7 @@
// <- - string

/**/: "test",
// ^ meta.mapping.json comment.block.json
// ^ meta.mapping.json comment.block.empty.json
// ^ punctuation.separator.key-value.json - comment
// ^^^^^^ meta.mapping.value.json string.quoted.double.json

Expand All @@ -116,8 +145,4 @@
"ke//y": "value"
//^^^^^^^ meta.mapping.key.json string.quoted.double.json - comment

/**
*
// ^ meta.mapping.json comment.block.documentation.json punctuation.definition.comment.json
*/
}