Skip to content

Commit

Permalink
Fixes for automatic variables (#166)
Browse files Browse the repository at this point in the history
* 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 $$, $^, $?
  • Loading branch information
msftrncs authored and TylerLeonhardt committed May 8, 2019
1 parent f33f44c commit 6e2fb74
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
6 changes: 3 additions & 3 deletions PowerShellSyntax.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@
<key>0</key>
<dict>
<key>name</key>
<string>support.constant.automatic.powershell</string>
<string>support.variable.automatic.powershell</string>
</dict>
<key>1</key>
<dict>
Expand All @@ -1013,7 +1013,7 @@
<key>comment</key>
<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>
<key>match</key>
<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>
<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>
</dict>
<dict>
<key>captures</key>
Expand Down Expand Up @@ -1297,7 +1297,7 @@
<key>comment</key>
<string>Automatic variables are not constants, but they are read-only...</string>
<key>match</key>
<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>
<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>
</dict>
<dict>
<key>captures</key>
Expand Down
6 changes: 3 additions & 3 deletions spec/testfiles/syntax_test_Class.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class TypeName
# ^ punctuation.section.group.end.powershell
$this.P1 = $s
# <- punctuation.definition.variable.powershell
# ^ support.constant.automatic.powershell
# ^ support.variable.automatic.powershell
# ^^ variable.other.member.powershell
# ^ keyword.operator.assignment.powershell
# ^ punctuation.definition.variable.powershell
Expand Down Expand Up @@ -110,15 +110,15 @@ class TypeName
# ^ punctuation.section.group.end.powershell
$this.P3 = $i
# <- punctuation.definition.variable.powershell
# ^ support.constant.automatic.powershell
# ^ support.variable.automatic.powershell
# ^^ variable.other.member.powershell
# ^ keyword.operator.assignment.powershell
# ^ punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
return $this.P3
# <- keyword.control.powershell
# ^ punctuation.definition.variable.powershell
# ^^^^ support.constant.automatic.powershell
# ^^^^ support.variable.automatic.powershell
# ^^ variable.other.member.powershell
}
}
4 changes: 2 additions & 2 deletions spec/testfiles/syntax_test_Function.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ function Verb-Noun {
# ^ meta.attribute.powershell meta.scriptblock.powershell
# ^^^^^^^^^ meta.scriptblock.powershell support.function.powershell
# ^ meta.scriptblock.powershell punctuation.definition.variable.powershell
# ^ meta.scriptblock.powershell support.constant.automatic.powershell
# ^ meta.scriptblock.powershell support.variable.automatic.powershell
# ^ meta.attribute.powershell meta.scriptblock.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
Expand Down Expand Up @@ -359,7 +359,7 @@ function Verb-Noun {
# <- keyword.control.powershell
# ^ punctuation.section.group.begin.powershell
# ^ punctuation.definition.variable.powershell
# ^^^^^^^^ support.constant.automatic.powershell
# ^^^^^^^^ support.variable.automatic.powershell
# ^^^^^^^^^^^^^ variable.other.member.powershell
# ^ punctuation.section.group.begin.powershell
# ^ punctuation.section.group.end.powershell
Expand Down
22 changes: 17 additions & 5 deletions spec/testfiles/syntax_test_TheBigTestFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,18 @@ throw "Do not run this file!"
# ^^ ^^ ^^ ^^ ^ ^ string.unquoted.powershell

# Automatic variables
$_
$_, $$, $^, $?
# <- punctuation.definition.variable.powershell
# <- support.constant.automatic.powershell
# <- support.variable.automatic.powershell
# ^ punctuation.definition.variable.powershell
# ^ support.variable.automatic.powershell
# ^ punctuation.definition.variable.powershell
# ^ support.variable.automatic.powershell
# ^ punctuation.definition.variable.powershell
# ^ support.variable.automatic.powershell
$args
# <- punctuation.definition.variable.powershell
# ^ support.constant.automatic.powershell
# ^ support.variable.automatic.powershell
$error
# <- punctuation.definition.variable.powershell
# ^ support.constant.variable.powershell
Expand All @@ -103,7 +109,7 @@ $home
# ^ support.constant.variable.powershell
$foreach
# <- punctuation.definition.variable.powershell
# ^ support.constant.automatic.powershell
# ^ support.variable.automatic.powershell

# Normal variables
$variable
Expand Down Expand Up @@ -179,6 +185,12 @@ $variable.Name
# ^ not:punctuation.definition.variable.powershell
# ^ not:variable.other.readwrite.powershell

# double check scopes for automatic variables in strings
"$_ $$ $Pwd"
# ^ support.variable.automatic.powershell
# ^ support.variable.automatic.powershell
# ^ support.variable.automatic.powershell

# Single quotes string
'This is a string'
# <- punctuation.definition.string.begin.powershell string.quoted.single.powershell
Expand Down Expand Up @@ -912,7 +924,7 @@ class Vehicle {
# ^ variable.other.readwrite.powershell
$this.Mileage += $NumberOfMiles
# ^ punctuation.definition.variable.powershell
# ^^^^ support.constant.automatic.powershell
# ^^^^ support.variable.automatic.powershell
# ^ variable.other.member.powershell
# ^^ keyword.operator.assignment.powershell

Expand Down

0 comments on commit 6e2fb74

Please sign in to comment.