Skip to content

Add support for syntax-based folding #191

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

Merged
merged 5 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
51 changes: 51 additions & 0 deletions Fold.tmPreferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?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>punctuation.definition.string.begin</string>
<key>end</key>
<string>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>
17 changes: 17 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,19 @@ contexts:
- match: (?=\()
pop: true
- include: comment-line

regions:
- match: ^\s*(#)\s*(region)\b\s*(\S.*)
captures:
1: punctuation.definition.comment.powershell
2: comment.line.powershell
3: meta.toc-list.powershell meta.fold.begin.powershell entity.name.section.powershell
- match: '^\s*(#)\s*(region)\b\s*'
captures:
1: punctuation.definition.comment.powershell
2: comment.line.powershell meta.fold.begin.powershell
- match: '^\s*(#)\s*(endregion\b[^\S\n]*.*)($\n?)'
captures:
1: punctuation.definition.comment.powershell
2: comment.line.powershell
3: meta.fold.end.powershell
14 changes: 14 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,12 @@ function get-number {}
#<- comment.block comment.documentation.embedded punctuation.definition.keyword.documentation
#^^^^^^^^^^^^ keyword.other.documentation
#>

#region Test
#<- punctuation.definition.comment
#^^^^^^ comment.line.powershell
# ^^^^ meta.toc-list meta.fold.begin entity.name.section
# @@@@ local-definition
#endregion (Text after #endregion is optional, but the ISE marks it as a comment as well)
#<- punctuation.definition.comment.powershell
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line
Loading