From 741c3b655c24513a50af1188787d2438d1afbb35 Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Thu, 29 Jan 2026 13:46:10 -0500 Subject: [PATCH 1/2] Allow regions anywhere comments are permitted Technically regions are only valid at BOL https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comments but since they're not interpreted by Pwsh itself, we're lenient See #216 --- PowerShell.sublime-syntax | 4 +-- tests/syntax_test_PowerShell.ps1 | 54 ++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index aedeb16..c210897 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -19,6 +19,7 @@ first_line_match: |- contexts: prototype: + - include: regions - include: comments main: @@ -76,7 +77,6 @@ contexts: expressions-without-commands: # Meta - include: labels - - include: regions - include: requires-directives - include: escape-sequences @@ -580,7 +580,7 @@ contexts: - meta_scope: meta.block.parameters.powershell - match: \) scope: punctuation.section.block.end.powershell - pop: 1 + pop: 2 - include: comma-separators - include: attributes - include: types-without-members diff --git a/tests/syntax_test_PowerShell.ps1 b/tests/syntax_test_PowerShell.ps1 index d8721da..b08ee33 100644 --- a/tests/syntax_test_PowerShell.ps1 +++ b/tests/syntax_test_PowerShell.ps1 @@ -2370,6 +2370,8 @@ $a3[1..2] # ^^^^ meta.toc-list entity.name.section # @@@@ local-definition # ^ meta.fold.begin + Do-Stuff +# @@@@@@@@ reference #endregion (More comments) #<- punctuation.definition.comment.powershell #^^^^^^^^^ keyword.other.region.end.powershell @@ -2386,3 +2388,55 @@ $a3[1..2] #^^^^^^^^^ keyword.other.region.end.powershell #<- comment.line # ^ meta.fold.end + +function Process-DeploymentConfig { +# @@@@@@@@@@@@@@@@@@@@@@@@ definition + [CmdletBinding()] + param ( + [Parameter(Mandatory=$true)] + [string]$ConfigJson, + + [Parameter(Mandatory=$true)] + [hashtable]PathVariables + ) + + #region Helper function for path resolution +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.powershell +# ^ punctuation.definition.comment +# ^^^^^^ keyword.other.region.begin +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.toc-list entity.name.section +# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ local-definition +# ^ meta.fold.begin + + function Resolve-ConfigPath { +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell meta.function.powershell +# ^^^^^^^^ keyword.declaration.function.powershell +# ^^^^^^^^^^^^^^^^^^ entity.name.function.powershell +# @@@@@@@@@@@@@@@@@@ definition +# ^ punctuation.section.block.begin.powershell + [CmdletBinding()] + param ( + [Parameter(Mandatory=$true)] + [string]$Path, + + [Parameter(Mandatory=$true)] + [hashtable]$PathVariables + ) + + $Private:ResolvedPath = $Path + foreach ($key in $PathVariables.Keys) { + $ResolvedPath = $ResolvedPath.Replace($key, $PathVariables[$key]) +# @@@@@@@ reference + } + return $ResolvedPath + } + #endregion +# ^^^^^^^^^^^ comment.line.powershell +# ^ punctuation.definition.comment.powershell +# ^^^^^^^^^ keyword.other.region.end.powershell +# ^ meta.fold.end + + + Resolve-ConfigPath -Path "Foo" -PathVariables $PathVariables +# @@@@@@@@@@@@@@@@@@ reference +} From b9127bd6d78ba81e299dff6ac909116e167d0f34 Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Thu, 29 Jan 2026 14:01:57 -0500 Subject: [PATCH 2/2] fixup for broken symbol tests Apparently the current stable trims internal spaces --- tests/syntax_test_PowerShell.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/syntax_test_PowerShell.ps1 b/tests/syntax_test_PowerShell.ps1 index b08ee33..469bfc6 100644 --- a/tests/syntax_test_PowerShell.ps1 +++ b/tests/syntax_test_PowerShell.ps1 @@ -2400,13 +2400,13 @@ function Process-DeploymentConfig { [hashtable]PathVariables ) - #region Helper function for path resolution -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.powershell + #region PathHelper +# ^^^^^^^^^^^^^^^^^^^ comment.line.powershell # ^ punctuation.definition.comment # ^^^^^^ keyword.other.region.begin -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.toc-list entity.name.section -# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ local-definition -# ^ meta.fold.begin +# ^^^^^^^^^^ meta.toc-list entity.name.section +# @@@@@@@@@@ local-definition +# ^ meta.fold.begin function Resolve-ConfigPath { #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell meta.function.powershell