Skip to content

Commit fa0fde5

Browse files
committed
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
1 parent 23a9808 commit fa0fde5

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

PowerShell.sublime-syntax

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ first_line_match: |-
1919
2020
contexts:
2121
prototype:
22+
- include: regions
2223
- include: comments
2324

2425
main:
@@ -76,7 +77,6 @@ contexts:
7677
expressions-without-commands:
7778
# Meta
7879
- include: labels
79-
- include: regions
8080
- include: requires-directives
8181

8282
- include: escape-sequences
@@ -580,7 +580,7 @@ contexts:
580580
- meta_scope: meta.block.parameters.powershell
581581
- match: \)
582582
scope: punctuation.section.block.end.powershell
583-
pop: 1
583+
pop: 2
584584
- include: comma-separators
585585
- include: attributes
586586
- include: types-without-members

tests/syntax_test_PowerShell.ps1

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,6 +2370,8 @@ $a3[1..2]
23702370
# ^^^^ meta.toc-list entity.name.section
23712371
# @@@@ local-definition
23722372
# ^ meta.fold.begin
2373+
Do-Stuff
2374+
# @@@@@@@@ reference
23732375
#endregion (More comments)
23742376
#<- punctuation.definition.comment.powershell
23752377
#^^^^^^^^^ keyword.other.region.end.powershell
@@ -2386,3 +2388,56 @@ $a3[1..2]
23862388
#^^^^^^^^^ keyword.other.region.end.powershell
23872389
#<- comment.line
23882390
# ^ meta.fold.end
2391+
2392+
function Process-DeploymentConfig {
2393+
# @@@@@@@@@@@@@@@@@@@@@@@@ definition
2394+
[CmdletBinding()]
2395+
param (
2396+
[Parameter(Mandatory=$true)]
2397+
[string]$ConfigJson,
2398+
2399+
[Parameter(Mandatory=$true)]
2400+
[hashtable]PathVariables
2401+
)
2402+
2403+
#region Helper function for path resolution
2404+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.powershell
2405+
# ^ punctuation.definition.comment
2406+
# ^^^^^^ keyword.other.region.begin
2407+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.toc-list entity.name.section
2408+
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ local-definition
2409+
# ^ meta.fold.begin
2410+
2411+
function Resolve-ConfigPath {
2412+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell meta.function.powershell
2413+
# ^^^^^^^^ keyword.declaration.function.powershell
2414+
# ^^^^^^^^^^^^^^^^^^ entity.name.function.powershell
2415+
# @@@@@@@@@@@@@@@@@@ definition
2416+
# ^ punctuation.section.block.begin.powershell
2417+
[CmdletBinding()]
2418+
param (
2419+
[Parameter(Mandatory=$true)]
2420+
[string]$Path,
2421+
2422+
[Parameter(Mandatory=$true)]
2423+
[hashtable]$PathVariables
2424+
)
2425+
2426+
$Private:ResolvedPath = $Path
2427+
foreach ($key in $PathVariables.Keys) {
2428+
$ResolvedPath = $ResolvedPath.Replace($key, $PathVariables[$key])
2429+
# @@@@@@@ reference
2430+
}
2431+
return $ResolvedPath
2432+
}
2433+
#endregion
2434+
2435+
# ^^^^^^^^^^^ comment.line.powershell
2436+
# ^ punctuation.definition.comment.powershell
2437+
# ^^^^^^^^^ keyword.other.region.end.powershell
2438+
# ^ meta.fold.end
2439+
2440+
2441+
Resolve-ConfigPath -Path "Foo" -PathVariables $PathVariables
2442+
# @@@@@@@@@@@@@@@@@@ reference
2443+
}

0 commit comments

Comments
 (0)