Skip to content

Commit 19dde50

Browse files
committed
Add support for syntax-based folding
Regions, comment blocks, and heredocs can now be folded. Additionally, Sublime Text now indexes region names as symbols.
1 parent 7b9767e commit 19dde50

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

Fold.tmPreferences

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<plist version="1.0">
3+
<dict>
4+
<key>scope</key>
5+
<string>source.powershell</string>
6+
<key>settings</key>
7+
<dict>
8+
<key>foldScopes</key>
9+
<array>
10+
<dict>
11+
<key>begin</key>
12+
<string>punctuation.section.block.begin</string>
13+
<key>end</key>
14+
<string>punctuation.section.block.end</string>
15+
</dict>
16+
<dict>
17+
<key>begin</key>
18+
<string>punctuation.definition.comment.block.begin</string>
19+
<key>end</key>
20+
<string>punctuation.definition.comment.block.end</string>
21+
</dict>
22+
<dict>
23+
<key>begin</key>
24+
<string>punctuation.definition.string.begin</string>
25+
<key>end</key>
26+
<string>punctuation.definition.string.end</string>
27+
</dict>
28+
</array>
29+
</dict>
30+
</dict>
31+
</plist>

PowerShell.sublime-syntax

+15
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ contexts:
3535
pop: true
3636

3737
main:
38+
- include: regions
3839
- include: comments
3940
- include: expressions
4041

@@ -808,3 +809,17 @@ contexts:
808809
- match: (?=\()
809810
pop: true
810811
- include: comment-line
812+
813+
regions:
814+
- match: ^(#region\s*(.*))$
815+
captures:
816+
# Applying the punctuation.section.block.begin scope to the entire pattern
817+
# allows Sublime Text to show the region name when it is folded.
818+
1: punctuation.section.block.begin.powershell comment.line.powershell
819+
2: meta.toc-list.powershell
820+
- match: ^#endregion
821+
scope: punctuation.section.block.end.powershell comment.line.powershell
822+
push:
823+
- meta_content_scope: comment.line.powershell
824+
- include: pop-at-newline
825+
- include: comment-embedded-docs

Tests/syntax_test_PowerShell.ps1

+12
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,11 @@ There is no @platting here!
469469
"@
470470
# <- string.quoted.double.heredoc
471471
# <- string.quoted.double.heredoc
472+
@'
473+
#<- meta.string string.quoted.single.heredoc punctuation.definition.string.begin
474+
A 'single quoted' "heredoc"
475+
'@
476+
#<- meta.string string.quoted.single.heredoc punctuation.definition.string.end
472477

473478
# Numeric constants
474479

@@ -1805,3 +1810,10 @@ function get-number {}
18051810
#<- comment.block comment.documentation.embedded punctuation.definition.keyword.documentation
18061811
#^^^^^^^^^^^^ keyword.other.documentation
18071812
#>
1813+
1814+
#region Test
1815+
#<- punctuation.section.block.begin comment.line
1816+
# ^^^^ meta.toc-list
1817+
#endregion (Text after #endregion is optional, but the ISE marks it as a comment as well)
1818+
#<- punctuation.section.block.end comment.line
1819+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line

0 commit comments

Comments
 (0)