PowerShell / EditorSyntax

PowerShell syntax highlighting for editors (VS Code, Atom, SublimeText, TextMate, etc.) and GitHub!
MIT License
133 stars 45 forks source link

Label in front of Foreach, For, and While loop keyword is not highlighted #89

Open kborowinski opened 6 years ago

kborowinski commented 6 years ago

Environment

> code-insiders.cmd -v
1.24.0-insider
d29620f2ba89327f51bb6fb2f05dfdd65e2fcafe

> $psEditor.EditorServicesVersion
Major  Minor  Build  Revision
-----  -----  -----  --------
1      7      0      0

> code-insiders.cmd --list-extensions --show-versions
...
ms-vscode.PowerShell@1.7.0
...

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.17134.1
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17134.1
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Issue Description

Label in front of Foreach, For, and While loop is not highlighted:

image

Expected Behavior

Label should be highlighted

omniomi commented 6 years ago

Looks like the loop constructs are also not defined. Currently it's inheriting from:

<keyword match> <interpolatedStringContent> <
    scriptblock
>

Which is for obvious reasons not ideal. Will work something out tonight :)

msftrncs commented 5 years ago

@kborowinski, PR #156 demonstrates handling of label, but I made up a scope to assign to it, so without some support in the theme, it will still appear unhandled.

Anyone have any recommendations for scope for a label? I used 'entity.name.label.powershell' for both definition and use.

A caution: Labels also can be valid function names. TextMate is not sophisticated enough to handle all the possible situations that can arise, so PR #156 is confined to consider any construct that might be a valid label, as a label, if its the only thing that appears on the rest of the statement line. TextMate cannot make scoping decisions spanning more than one line; all decisions must be final at the end of the line.

FYI, in the code shown, the label is probably unneeded, as is the FOREACH loop, as SWITCH automatically performs expansion of a collection (but the result variable will be $_). Also, you might be interested to know, that quotes are not needed around the test value in SWITCH statements, when they are a simple word. The 'Subject' and 'Body' can be Subject and Body.