From b33d90e32f79f24a426726dd3ba347c3988c2468 Mon Sep 17 00:00:00 2001 From: msftrncs Date: Sat, 27 Apr 2019 00:14:22 -0500 Subject: [PATCH 1/3] fixes #133 corrects scope mismatch between #variable and #variableNoProperty for automatics and fixes REGEX for $$, $^, and $? --- PowerShellSyntax.tmLanguage | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PowerShellSyntax.tmLanguage b/PowerShellSyntax.tmLanguage index 43adbba..ea85f28 100644 --- a/PowerShellSyntax.tmLanguage +++ b/PowerShellSyntax.tmLanguage @@ -1042,7 +1042,7 @@ 0 name - support.constant.automatic.powershell + support.variable.automatic.powershell 1 @@ -1058,7 +1058,7 @@ comment 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. match - (\$)(?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 + (\$)((?:[$^?])|(?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)? captures @@ -1342,7 +1342,7 @@ comment Automatic variables are not constants, but they are read-only... match - (\$)(?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 + (\$)((?:[$^?])|(?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) captures From 968a47d301bfa0409cb28c7b64591c8eb508a430 Mon Sep 17 00:00:00 2001 From: msftrncs Date: Sat, 27 Apr 2019 00:27:24 -0500 Subject: [PATCH 2/3] fix tests for automatic variable scope change --- spec/testfiles/syntax_test_Class.ps1 | 6 +++--- spec/testfiles/syntax_test_Function.ps1 | 4 ++-- spec/testfiles/syntax_test_TheBigTestFile.ps1 | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/testfiles/syntax_test_Class.ps1 b/spec/testfiles/syntax_test_Class.ps1 index 662c488..27db15c 100644 --- a/spec/testfiles/syntax_test_Class.ps1 +++ b/spec/testfiles/syntax_test_Class.ps1 @@ -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 @@ -110,7 +110,7 @@ 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 @@ -118,7 +118,7 @@ class TypeName return $this.P3 # <- keyword.control.powershell # ^ punctuation.definition.variable.powershell - # ^^^^ support.constant.automatic.powershell + # ^^^^ support.variable.automatic.powershell # ^^ variable.other.member.powershell } } diff --git a/spec/testfiles/syntax_test_Function.ps1 b/spec/testfiles/syntax_test_Function.ps1 index c297d21..187dab1 100644 --- a/spec/testfiles/syntax_test_Function.ps1 +++ b/spec/testfiles/syntax_test_Function.ps1 @@ -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 @@ -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 diff --git a/spec/testfiles/syntax_test_TheBigTestFile.ps1 b/spec/testfiles/syntax_test_TheBigTestFile.ps1 index 340e685..9a0be1c 100644 --- a/spec/testfiles/syntax_test_TheBigTestFile.ps1 +++ b/spec/testfiles/syntax_test_TheBigTestFile.ps1 @@ -91,10 +91,10 @@ throw "Do not run this file!" # Automatic variables $_ # <- punctuation.definition.variable.powershell - # <- support.constant.automatic.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 @@ -103,7 +103,7 @@ $home # ^ support.constant.variable.powershell $foreach # <- punctuation.definition.variable.powershell -# ^ support.constant.automatic.powershell +# ^ support.variable.automatic.powershell # Normal variables $variable @@ -912,7 +912,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 From 421a44c65662ac2e9e720dfd818bece1d7db1420 Mon Sep 17 00:00:00 2001 From: msftrncs Date: Sat, 27 Apr 2019 00:46:27 -0500 Subject: [PATCH 3/3] add tests for $$, $^, $? --- spec/testfiles/syntax_test_TheBigTestFile.ps1 | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/testfiles/syntax_test_TheBigTestFile.ps1 b/spec/testfiles/syntax_test_TheBigTestFile.ps1 index 9a0be1c..7d16fbf 100644 --- a/spec/testfiles/syntax_test_TheBigTestFile.ps1 +++ b/spec/testfiles/syntax_test_TheBigTestFile.ps1 @@ -89,9 +89,15 @@ throw "Do not run this file!" # ^^ ^^ ^^ ^^ ^ ^ string.unquoted.powershell # Automatic variables -$_ +$_, $$, $^, $? # <- punctuation.definition.variable.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.variable.automatic.powershell @@ -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