Skip to content

Commit

Permalink
[D] Add bracket fold rules and reenable indentation folding (sublimeh…
Browse files Browse the repository at this point in the history
…q#3879)

* [D] Add syntax based fold rules for brackets

Fixes sublimehq#3878

Thus commit scopes sections in brackets `meta.brackets` and adds
corresponding fold rules to enable scope based folding.

Note: Meta scopes are required to ensure subsequent brackets (e.g.: [[`)
are correctly tokenized individually.

* [D] Reenable indentation folding

Required to allow folding of code sections not covered by scope based folding.
  • Loading branch information
deathaxe authored Apr 30, 2024
1 parent bcc7c6f commit 8af9b40
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions D/D.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -815,11 +815,13 @@ contexts:
- match: '(?=\S)'
pop: true
basic-type2-after-brackets:
- meta_scope: meta.brackets.d
- match: '\]'
scope: punctuation.section.brackets.end.d
pop: true
- include: not-whitespace-illegal-pop
basic-type2-after-parens:
- meta_scope: meta.parens.d
- match: '\)'
scope: punctuation.section.parens.end.d
pop: true
Expand Down Expand Up @@ -1111,11 +1113,13 @@ contexts:
- match: '(?=\S)'
set: [value-list-after, value-after]
first-value-bracket-after:
- meta_scope: meta.brackets.d
- match: '\]'
scope: punctuation.section.brackets.end.d
set: first-value-after
- include: not-whitespace-illegal-pop
first-value-parens-after:
- meta_scope: meta.parens.d
- match: '\)'
scope: punctuation.section.parens.end.d
set: first-value-after
Expand Down Expand Up @@ -1496,6 +1500,7 @@ contexts:
set: value-after
- include: not-whitespace-illegal-pop
value-bracket-after:
- meta_scope: meta.brackets.d
- match: '\]'
scope: punctuation.section.brackets.end.d
set: value-after
Expand Down
10 changes: 9 additions & 1 deletion D/Fold.tmPreferences
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<key>settings</key>
<dict>
<key>indentationFoldingEnabled</key>
<false/>
<true/>
<key>foldScopes</key>
<array>
<dict>
Expand All @@ -15,6 +15,14 @@
<key>end</key>
<string>punctuation.section.block.end</string>
</dict>
<dict>
<key>begin</key>
<string>punctuation.section.brackets.begin</string>
<key>end</key>
<string>punctuation.section.brackets.end</string>
<key>excludeTrailingNewlines</key>
<false/>
</dict>
</array>
</dict>
</dict>
Expand Down
11 changes: 11 additions & 0 deletions D/tests/syntax_test_d.d
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ extern(1)
// ^ keyword.operator.assignment.d
// ^^^^^ storage.modifier.d
// ^^^ storage.type.d
// ^^^^^^^^ meta.brackets.d
// ^ punctuation.section.brackets.begin.d
// ^^^^^^ support.type.builtin-alias.d
// ^ punctuation.section.brackets.end.d
Expand All @@ -598,6 +599,7 @@ extern(1)
//^^^^^ keyword.control.alias.d
// ^^^^^ storage.modifier.d
// ^^^ storage.type.d
// ^^^^^^^^ meta.brackets.d
// ^ punctuation.section.brackets.begin.d
// ^^^^^^ support.type.builtin-alias.d
// ^ punctuation.section.brackets.end.d
Expand Down Expand Up @@ -648,6 +650,7 @@ extern(1)
// ^ punctuation.terminator.d
foo[string] b = 123;
//^^^ storage.type.d
// ^^^^^^^^ meta.brackets.d
// ^ punctuation.section.brackets.begin.d
// ^^^^^^ support.type.builtin-alias.d
// ^ punctuation.section.brackets.end.d
Expand All @@ -667,6 +670,7 @@ extern(1)
// ^ punctuation.terminator.d
foo[BAR] baz;
//^^^ storage.type.d
// ^^^^^ meta.brackets.d
// ^ punctuation.section.brackets.begin.d
// ^^^ variable.other.d
// ^ punctuation.section.brackets.end.d
Expand Down Expand Up @@ -995,6 +999,7 @@ extern(1)
//^^^^ keyword.declaration.enum.d
// ^ punctuation.separator.mapping.d
// ^^^ storage.type.d
// ^^^^^^^^ meta.brackets.d
// ^ punctuation.section.brackets.begin.d
// ^^^^^^ support.type.builtin-alias.d
// ^ punctuation.section.brackets.end.d
Expand Down Expand Up @@ -1277,6 +1282,7 @@ extern(1)
int[string] foo() {}
//^^^ storage.type.d
// ^^^^^^^^ meta.brackets.d
// ^ punctuation.section.brackets.begin.d
// ^^^^^^ support.type.builtin-alias.d
// ^ punctuation.section.brackets.end.d
Expand Down Expand Up @@ -2289,6 +2295,7 @@ extern(1)
// ^^^^^ string.quoted.double.d
// ^ punctuation.section.parens.end.d
// ^^^^^^ support.type.builtin-alias.d
// ^^^^ meta.brackets.d
// ^ punctuation.section.brackets.begin.d
// ^^ meta.number.integer.decimal.d
// ^ punctuation.section.brackets.end.d
Expand Down Expand Up @@ -2320,6 +2327,7 @@ extern(1)
// ^ meta.number.integer.decimal.d
// ^ punctuation.section.parens.end.d
// ^^^^^^ support.type.builtin-alias.d
// ^^^^ meta.brackets.d
// ^ punctuation.section.brackets.begin.d
// ^^ meta.number.integer.decimal.d
// ^ punctuation.section.brackets.end.d
Expand Down Expand Up @@ -2430,6 +2438,7 @@ extern(1)
// ^^^ variable.other.d
// ^ keyword.operator.arithmetic.d
// ^^^ variable.other.d
// ^^^^^^^^^^ meta.brackets.d
// ^ punctuation.section.brackets.begin.d
// ^^^ variable.other.d
// ^ keyword.operator.arithmetic.d
Expand Down Expand Up @@ -3156,6 +3165,7 @@ extern(1)
void[int**]* foo;
//^^^^ storage.type.d
// ^^^^^^^ meta.brackets.d
// ^ punctuation.section.brackets.begin.d
// ^^^ storage.type.d
// ^^ keyword.operator.pointer.d
Expand All @@ -3180,6 +3190,7 @@ extern(1)
// ^ punctuation.section.block.end.d
a[b] * c;
//^ meta.path.d variable.other.d
// ^^^ meta.brackets.d
// ^ punctuation.section.brackets.begin.d
// ^ meta.path.d variable.other.d
// ^ punctuation.section.brackets.end.d
Expand Down

0 comments on commit 8af9b40

Please sign in to comment.