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

Add support for syntax-based folding #191

Merged
merged 5 commits into from
Jan 12, 2025
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
59 changes: 59 additions & 0 deletions Fold.tmPreferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>scope</key>
<string>source.powershell</string>
<key>settings</key>
<dict>
<key>foldScopes</key>
<array>
<dict>
<key>begin</key>
<string>meta.fold.begin</string>
<key>end</key>
<string>meta.fold.end</string>
</dict>
<dict>
<key>begin</key>
<string>punctuation.definition.comment.block.begin</string>
<key>end</key>
<string>punctuation.definition.comment.block.end</string>
<key>excludeTrailingNewlines</key>
<false/>
</dict>
<dict>
<key>begin</key>
<string>string.quoted.double.heredoc punctuation.definition.string.begin</string>
<key>end</key>
<string>string.quoted.double.heredoc punctuation.definition.string.end</string>
<key>excludeTrailingNewlines</key>
<false/>
</dict>
<dict>
<key>begin</key>
<string>string.quoted.single.heredoc punctuation.definition.string.begin</string>
<key>end</key>
<string>string.quoted.single.heredoc punctuation.definition.string.end</string>
<key>excludeTrailingNewlines</key>
<false/>
</dict>
<dict>
<key>begin</key>
<string>punctuation.section.group.begin</string>
<key>end</key>
<string>punctuation.section.group.end</string>
<key>excludeTrailingNewlines</key>
<false/>
</dict>
<dict>
<key>begin</key>
<string>punctuation.section.braces.begin</string>
<key>end</key>
<string>punctuation.section.braces.end</string>
<key>excludeTrailingNewlines</key>
<false/>
</dict>
</array>
</dict>
</dict>
</plist>
16 changes: 16 additions & 0 deletions PowerShell.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ contexts:
pop: true

main:
- include: regions
- include: comments
- include: expressions

Expand Down Expand Up @@ -808,3 +809,18 @@ contexts:
- match: (?=\()
pop: true
- include: comment-line

regions:
- match: ^\s*((#)\s*(region\b)(?:\s*(\S.*))?(\n?))
captures:
1: comment.line.powershell
2: punctuation.definition.comment.powershell
3: keyword.other.region.begin.powershell
4: meta.toc-list.powershell entity.name.section.powershell
5: meta.fold.begin.powershell
- match: ^\s*((#)\s*(endregion\b).*(\n?))
captures:
1: comment.line.powershell
2: punctuation.definition.comment.powershell
3: keyword.other.region.end.powershell
4: meta.fold.end.powershell
29 changes: 29 additions & 0 deletions Tests/syntax_test_PowerShell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,11 @@ There is no @platting here!
"@
# <- string.quoted.double.heredoc
# <- string.quoted.double.heredoc
@'
#<- meta.string string.quoted.single.heredoc punctuation.definition.string.begin
A 'single quoted' "heredoc"
'@
#<- meta.string string.quoted.single.heredoc punctuation.definition.string.end

# Numeric constants

Expand Down Expand Up @@ -1805,3 +1810,27 @@ function get-number {}
#<- comment.block comment.documentation.embedded punctuation.definition.keyword.documentation
#^^^^^^^^^^^^ keyword.other.documentation
#>

#region Test
#<- punctuation.definition.comment
#^^^^^^ keyword.other.region.begin
#<- comment.line.powershell
# ^^^^ meta.toc-list entity.name.section
# @@@@ local-definition
# ^ meta.fold.begin
#endregion (More comments)
#<- punctuation.definition.comment.powershell
#^^^^^^^^^ keyword.other.region.end.powershell
#<- comment.line
# ^ meta.fold.end

#region
#<- punctuation.definition.comment
#^^^^^^ keyword.other.region.begin
#<- comment.line.powershell
# ^ meta.fold.begin
#endregion (More comments)
#<- punctuation.definition.comment.powershell
#^^^^^^^^^ keyword.other.region.end.powershell
#<- comment.line
# ^ meta.fold.end
Loading