Skip to content

Commit 6e2fb74

Browse files
msftrncsTylerLeonhardt
authored andcommitted
Fixes for automatic variables (#166)
* fixes #133 corrects scope mismatch between #variable and #variableNoProperty for automatics and fixes REGEX for $$, $^, and $? * fix tests for automatic variable scope change * add tests for $$, $^, $?
1 parent f33f44c commit 6e2fb74

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

PowerShellSyntax.tmLanguage

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@
997997
<key>0</key>
998998
<dict>
999999
<key>name</key>
1000-
<string>support.constant.automatic.powershell</string>
1000+
<string>support.variable.automatic.powershell</string>
10011001
</dict>
10021002
<key>1</key>
10031003
<dict>
@@ -1013,7 +1013,7 @@
10131013
<key>comment</key>
10141014
<string>Automatic variables are not constants, but they are read-only. In monokai (default) color schema support.variable doesn't have color, so we use constant.</string>
10151015
<key>match</key>
1016-
<string>(\$)(?i:(\$|\^|\?|_|Args|ConsoleFileName|Event|EventArgs|EventSubscriber|ForEach|Input|LastExitCode|Matches|MyInvocation|NestedPromptLevel|Profile|PSBoundParameters|PsCmdlet|PsCulture|PSDebugContext|PSItem|PSCommandPath|PSScriptRoot|PsUICulture|Pwd|Sender|SourceArgs|SourceEventArgs|StackTrace|Switch|This))((?:\.(?:\p{L}|\d|_)+)*\b)?\b</string>
1016+
<string>(\$)((?:[$^?])|(?i:_|Args|ConsoleFileName|Event|EventArgs|EventSubscriber|ForEach|Input|LastExitCode|Matches|MyInvocation|NestedPromptLevel|Profile|PSBoundParameters|PsCmdlet|PsCulture|PSDebugContext|PSItem|PSCommandPath|PSScriptRoot|PsUICulture|Pwd|Sender|SourceArgs|SourceEventArgs|StackTrace|Switch|This)\b)((?:\.(?:\p{L}|\d|_)+)*\b)?</string>
10171017
</dict>
10181018
<dict>
10191019
<key>captures</key>
@@ -1297,7 +1297,7 @@
12971297
<key>comment</key>
12981298
<string>Automatic variables are not constants, but they are read-only...</string>
12991299
<key>match</key>
1300-
<string>(\$)(?i:(\$|\^|\?|_|Args|ConsoleFileName|Event|EventArgs|EventSubscriber|ForEach|Input|LastExitCode|Matches|MyInvocation|NestedPromptLevel|Profile|PSBoundParameters|PsCmdlet|PsCulture|PSDebugContext|PSItem|PSCommandPath|PSScriptRoot|PsUICulture|Pwd|Sender|SourceArgs|SourceEventArgs|StackTrace|Switch|This))\b</string>
1300+
<string>(\$)((?:[$^?])|(?i:_|Args|ConsoleFileName|Event|EventArgs|EventSubscriber|ForEach|Input|LastExitCode|Matches|MyInvocation|NestedPromptLevel|Profile|PSBoundParameters|PsCmdlet|PsCulture|PSDebugContext|PSItem|PSCommandPath|PSScriptRoot|PsUICulture|Pwd|Sender|SourceArgs|SourceEventArgs|StackTrace|Switch|This)\b)</string>
13011301
</dict>
13021302
<dict>
13031303
<key>captures</key>

spec/testfiles/syntax_test_Class.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class TypeName
6363
# ^ punctuation.section.group.end.powershell
6464
$this.P1 = $s
6565
# <- punctuation.definition.variable.powershell
66-
# ^ support.constant.automatic.powershell
66+
# ^ support.variable.automatic.powershell
6767
# ^^ variable.other.member.powershell
6868
# ^ keyword.operator.assignment.powershell
6969
# ^ punctuation.definition.variable.powershell
@@ -110,15 +110,15 @@ class TypeName
110110
# ^ punctuation.section.group.end.powershell
111111
$this.P3 = $i
112112
# <- punctuation.definition.variable.powershell
113-
# ^ support.constant.automatic.powershell
113+
# ^ support.variable.automatic.powershell
114114
# ^^ variable.other.member.powershell
115115
# ^ keyword.operator.assignment.powershell
116116
# ^ punctuation.definition.variable.powershell
117117
# ^ variable.other.readwrite.powershell
118118
return $this.P3
119119
# <- keyword.control.powershell
120120
# ^ punctuation.definition.variable.powershell
121-
# ^^^^ support.constant.automatic.powershell
121+
# ^^^^ support.variable.automatic.powershell
122122
# ^^ variable.other.member.powershell
123123
}
124124
}

spec/testfiles/syntax_test_Function.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ function Verb-Noun {
305305
# ^ meta.attribute.powershell meta.scriptblock.powershell
306306
# ^^^^^^^^^ meta.scriptblock.powershell support.function.powershell
307307
# ^ meta.scriptblock.powershell punctuation.definition.variable.powershell
308-
# ^ meta.scriptblock.powershell support.constant.automatic.powershell
308+
# ^ meta.scriptblock.powershell support.variable.automatic.powershell
309309
# ^ meta.attribute.powershell meta.scriptblock.powershell
310310
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
311311
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
@@ -359,7 +359,7 @@ function Verb-Noun {
359359
# <- keyword.control.powershell
360360
# ^ punctuation.section.group.begin.powershell
361361
# ^ punctuation.definition.variable.powershell
362-
# ^^^^^^^^ support.constant.automatic.powershell
362+
# ^^^^^^^^ support.variable.automatic.powershell
363363
# ^^^^^^^^^^^^^ variable.other.member.powershell
364364
# ^ punctuation.section.group.begin.powershell
365365
# ^ punctuation.section.group.end.powershell

spec/testfiles/syntax_test_TheBigTestFile.ps1

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,18 @@ throw "Do not run this file!"
8989
# ^^ ^^ ^^ ^^ ^ ^ string.unquoted.powershell
9090

9191
# Automatic variables
92-
$_
92+
$_, $$, $^, $?
9393
# <- punctuation.definition.variable.powershell
94-
# <- support.constant.automatic.powershell
94+
# <- support.variable.automatic.powershell
95+
# ^ punctuation.definition.variable.powershell
96+
# ^ support.variable.automatic.powershell
97+
# ^ punctuation.definition.variable.powershell
98+
# ^ support.variable.automatic.powershell
99+
# ^ punctuation.definition.variable.powershell
100+
# ^ support.variable.automatic.powershell
95101
$args
96102
# <- punctuation.definition.variable.powershell
97-
# ^ support.constant.automatic.powershell
103+
# ^ support.variable.automatic.powershell
98104
$error
99105
# <- punctuation.definition.variable.powershell
100106
# ^ support.constant.variable.powershell
@@ -103,7 +109,7 @@ $home
103109
# ^ support.constant.variable.powershell
104110
$foreach
105111
# <- punctuation.definition.variable.powershell
106-
# ^ support.constant.automatic.powershell
112+
# ^ support.variable.automatic.powershell
107113

108114
# Normal variables
109115
$variable
@@ -179,6 +185,12 @@ $variable.Name
179185
# ^ not:punctuation.definition.variable.powershell
180186
# ^ not:variable.other.readwrite.powershell
181187

188+
# double check scopes for automatic variables in strings
189+
"$_ $$ $Pwd"
190+
# ^ support.variable.automatic.powershell
191+
# ^ support.variable.automatic.powershell
192+
# ^ support.variable.automatic.powershell
193+
182194
# Single quotes string
183195
'This is a string'
184196
# <- punctuation.definition.string.begin.powershell string.quoted.single.powershell
@@ -912,7 +924,7 @@ class Vehicle {
912924
# ^ variable.other.readwrite.powershell
913925
$this.Mileage += $NumberOfMiles
914926
# ^ punctuation.definition.variable.powershell
915-
# ^^^^ support.constant.automatic.powershell
927+
# ^^^^ support.variable.automatic.powershell
916928
# ^ variable.other.member.powershell
917929
# ^^ keyword.operator.assignment.powershell
918930

0 commit comments

Comments
 (0)