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 1 commit
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
31 changes: 31 additions & 0 deletions Fold.tmPreferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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>punctuation.section.block.begin</string>
<key>end</key>
<string>punctuation.section.block.end</string>
</dict>
<dict>
<key>begin</key>
<string>punctuation.definition.comment.block.begin</string>
<key>end</key>
<string>punctuation.definition.comment.block.end</string>
</dict>
<dict>
<key>begin</key>
<string>punctuation.definition.string.begin</string>
<key>end</key>
<string>punctuation.definition.string.end</string>
</dict>
</array>
</dict>
</dict>
</plist>
15 changes: 15 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,17 @@ contexts:
- match: (?=\()
pop: true
- include: comment-line

regions:
- match: ^(#region\s*(.*))$
captures:
# Applying the punctuation.section.block.begin scope to the entire pattern
# allows Sublime Text to show the region name when it is folded.
1: punctuation.section.block.begin.powershell comment.line.powershell
2: meta.toc-list.powershell
- match: ^#endregion\b
scope: punctuation.section.block.end.powershell comment.line.powershell
push:
- meta_content_scope: comment.line.powershell
- include: pop-at-newline
- include: comment-embedded-docs
13 changes: 13 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,11 @@ function get-number {}
#<- comment.block comment.documentation.embedded punctuation.definition.keyword.documentation
#^^^^^^^^^^^^ keyword.other.documentation
#>

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