Skip to content
This repository was archived by the owner on Jun 2, 2023. It is now read-only.

Where/Foreach-object breaks syntax hightlighting #53

Closed
oivindoh opened this issue Sep 13, 2016 · 4 comments
Closed

Where/Foreach-object breaks syntax hightlighting #53

oivindoh opened this issue Sep 13, 2016 · 4 comments

Comments

@oivindoh
Copy link

$SomeComputer = 'localhost'
$RemoteServicePS = @{
  'VMware' = @{
    'Service' = $(get-service -verbose:$false -computername $SomeComputer -displayName 'VMware Tools');
    'EndpointContracts' = @('ISimService','IServiceBroker');
    'Identity' = '';
    };
  }
$ServicesToSkip = @()

$RemoteServiceCIM = @{}; $HasServicePrincipalNames = @{}
$RemoteServicePS.GetEnumerator() | % {
  $thisServiceKey = $_.Key
  if ($_.Value.Service -ne $null){

    $thisCIMService = $(get-ciminstance win32_service -verbose:$false -computername $_.Value.Service.MachineName -filter "name='$($_.Value.Service.ServiceName)'")
    $thisCIMServiceUser = $thisCIMService.StartName
    write-host $thisCIMServiceUser
    # etc.
  }
}

After updating language-powershell to the most recent release the following from the code above breaks code highlighting for me:

$thisCIMService = $(get-ciminstance win32_service -verbose:$false -computername $_.Value.Service.MachineName -filter "name='$($_.Value.Service.ServiceName)'")

The same also appears to be the case for the following little snippet (code hightlighting continues as before if commented out):

        $thisBitVersionMatches = $FilesPresent | where {$_.FullName -match "^(?=.*$thisVersion)((?=.*$thisBitness)|(?=.*$thisSupportBit))(?=.*redist).*$"}

I also see the issue in places such as this:

  foreach ($Tool in $Tools){
    $ToolFromWhere.Keys | % {
      if (($_ -match $Tool) -and -not ($ToolsToDownload -contains $ToolFromWhere."$($_)")){
        write-verbose ('Fetching {0} from {1}' -f $_, $ToolFromWhere."$($_)")
        $ToolsToDownload += $ToolFromWhere."$($_)"
        [URI]$thisURI = $ToolFromWhere."$($_)"
        $thisFileName = $thisURI.Segments[-1]
        $thisTempFile = join-path -path $env:TEMP -childpath $thisFileName
        start-bitstransfer -source $thisURI -destination $thisTempFile

Where if I comment out lines [3-6] highlighting continues.

Another example where the Where line breaks highlighting:

Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse |
  Get-ItemProperty -name Version,Release -EA 0 |
    Where { $_.PSChildName -match '^(?!S)\p{L}'} |
      Select PSChildName, Version, Release, @{
        name="Product"
        expression={
          switch($_.Release) {

My gut feeling says it's related to PR50 since it's all directly after a foreach/where, but I'm not really sure. Is there anything I can do to provide a clearer report/exclude other potential sources of the issue?

@oivindoh oivindoh changed the title Shorthand Where-Object broken Where/Foreach-object breaks syntax hightlighting Sep 13, 2016
@jrsconfitto
Copy link
Owner

Thanks for the report! This is also related to PR #52, this package is adopting the syntax grammar put out by the PowerShell team and i think this may be a regression due to that move.

i think i'll forward this one on to the PowerShell/EditorSyntax repository and we'll see what they say. Maybe it will be possible to apply changes similar to #50 in their language file?

@jrsconfitto
Copy link
Owner

This issue was moved to PowerShell/EditorSyntax#24

@jrsconfitto
Copy link
Owner

Hi! i've reverted back to the previous grammar file, so things should be back where they were. If they aren't, please let me know!

Thanks for your patience with me as i fix this, and i'm so sorry you hit up against problems. It wasn't a wise decision for me to rush into bumping the grammar versions 😨

@jrsconfitto
Copy link
Owner

Fixed by #65, thanks for your patience.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants