Skip to content

Commit 60c2bcb

Browse files
committed
Syntax: Add highlighting for extends values
Add special scopes for `extends`'s values to be able to provide completions and easily identify/find them.
1 parent db7bf1a commit 60c2bcb

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

Package/Sublime Text Syntax Definition/Sublime Text Syntax Definition.sublime-syntax

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ contexts:
133133
captures:
134134
1: string.unquoted.plain.out.yaml storage.type.extends.sublime-syntax
135135
2: punctuation.separator.key-value.yaml
136+
push: expect_extends_list
136137

137138
- match: ((?:hidden_)?file_extensions)\s*(:)(?=\s|$)
138139
captures:
@@ -162,6 +163,52 @@ contexts:
162163

163164
- include: scope:source.yaml
164165

166+
expect_extends_list:
167+
- meta_content_scope: meta.extends.sublime-syntax
168+
- include: comment
169+
- include: yaml-tags-anchors
170+
# array-like context list
171+
- match: \[
172+
scope: punctuation.definition.array.begin.sublime-syntax
173+
set:
174+
- meta_scope: meta.extends.sublime-syntax meta.flow-sequence.yaml
175+
- match: \]
176+
scope: punctuation.definition.array.end.sublime-syntax
177+
pop: true
178+
- match: ','
179+
scope: punctuation.separator.array-element.sublime-syntax
180+
- match: '{{plain_scalar_but_not_block_key}}'
181+
push: extended_syntax_file
182+
- include: comment
183+
- include: yaml-tags-anchors
184+
# multi-line context list
185+
- match: ^([ ]+)(?=-\s*{{plain_scalar_but_not_block_key}})
186+
set:
187+
- meta_scope: meta.extends.sublime-syntax meta.block-sequence.yaml
188+
# pop off at none-empty line with different indention than first item
189+
- match: ^(?!(\s*$|\1-))
190+
pop: true
191+
- match: '{{plain_scalar_but_not_block_key}}'
192+
push: extended_syntax_file
193+
- include: comment
194+
- include: yaml-block-sequence
195+
- match: \S.*$
196+
scope: invalid.illegal.extends.sublime-syntax
197+
# maybe single include
198+
- match: '{{plain_scalar_but_not_block_key}}'
199+
set:
200+
- meta_scope: meta.extends.sublime-syntax meta.path.sublime-syntax string.unquoted.plain.out.yaml
201+
- include: extended_syntax_file
202+
- match: ^\s*$
203+
pop: 1
204+
205+
extended_syntax_file:
206+
- meta_scope: meta.path.sublime-syntax string.unquoted.plain.out.yaml
207+
- match: '{{_flow_scalar_end_plain_in}}'
208+
pop: true
209+
- match: /
210+
scope: punctuation.separator.path.sublime-syntax
211+
165212
variables_block:
166213
- meta_scope: meta.block.variables.sublime-syntax
167214
- include: comment

Package/Sublime Text Syntax Definition/syntax_test_sublime-syntax.yaml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,26 @@ version: 2
1313
extends: Packages/Default/Text.sublime-syntax
1414
#^^^^^^ string.unquoted.plain.out.yaml storage.type.extends.sublime-syntax
1515
# ^ punctuation.separator.key-value.yaml
16-
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.unquoted.plain.out.yaml
16+
# ^ meta.extends - meta.path
17+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.extends.sublime-syntax meta.path.sublime-syntax string.unquoted.plain.out.yaml
18+
# ^ punctuation.separator.path.sublime-syntax
19+
# ^ punctuation.separator.path.sublime-syntax
20+
# ^ - meta.extends - meta.path
21+
extends: [ Text.sublime-syntax , Source.sublime-syntax ]
22+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.extends.sublime-syntax meta.flow-sequence.yaml
23+
# ^ - meta.path
24+
# ^^^^^^^^^^^^^^^^^^^ meta.path.sublime-syntax string.unquoted.plain.out.yaml
25+
# ^^^ - meta.path
26+
# ^^^^^^^^^^^^^^^^^^^^^ meta.path.sublime-syntax string.unquoted.plain.out.yaml
27+
# ^^ - meta.path
28+
extends:
29+
- Packages/Default/Text.sublime-syntax
30+
# <- meta.extends.sublime-syntax meta.block-sequence.yaml
31+
#^^^ meta.extends.sublime-syntax meta.block-sequence.yaml
32+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.extends.sublime-syntax meta.block-sequence.yaml meta.path.sublime-syntax string.unquoted.plain.out.yaml
33+
# ^ punctuation.separator.path.sublime-syntax
34+
# ^ punctuation.separator.path.sublime-syntax
35+
# ^ meta.extends.sublime-syntax meta.block-sequence.yaml - meta.path
1736
file_extensions: [a, b]
1837
#^^^^^^^^^^^^^^ string.unquoted.plain.out.yaml entity.name.tag.yaml
1938
# ^^^^^^ meta.flow-sequence.yaml, meta.sequence.flow.yaml

0 commit comments

Comments
 (0)