Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code folding is confused by hash table definitions #1636

Closed
ThubLives opened this issue Dec 6, 2018 · 2 comments
Closed

Code folding is confused by hash table definitions #1636

ThubLives opened this issue Dec 6, 2018 · 2 comments
Labels

Comments

@ThubLives
Copy link

Issue Description

When a hash table is defined inside a function (whether a single- or multi-line definition), folding the function causes the fold to stop at the end of the hash table block rather than the end of the function block.

Reproducing the Issue

  1. Open the code below as a PowerShell script.
  2. Make sure configuration option "powershell.codeFolding.showLastLine" is set to true.
  3. Move the cursor to the function statement on line 3 and press <Ctrl>+<Shift>+[ (on Windows) to fold the whole function.
    Note that the fold ends at line 23 rather than line 28 as expected.
  4. Unfold the function line (<Ctrl>+<Shift>+] on Windows)
  5. Move the cursor to the hash table definition on line 18 and fold the multi-line definition.
    Note that the fold swallows the closing line 23 as well as the blank line 24 below it.

Code:

#region Region1
Write-Host "Hello."
function TestFunction {
  param (
    [Parameter(Mandatory = $true,
      Position = 0)]
    [string]$Param1
  )
  Write-Host "Testing..."

  $NewArray = @(
    ArrayValue1
    ArrayValue2
    ArrayValue3
    ArrayValue4
  )

  $NewHashTable = @{
    HashTableValue1 = 1
    HashTableValue2 = 2
    HashTableValue3 = 3
    HashTableValue4 = 4
  }

  if ($true) {
    Write-Host "True is $true"
  }
}
#endregion

Bonus Issue Test

  1. Put only the hash table definition in its own file (see code below).
    Note that nothing is marked as foldable and the keyboard or palette commands do nothing.

Code:

$NewHashTable = @{
  HashTableValue1 = 1
  HashTableValue2 = 2
  HashTableValue3 = 3
  HashTableValue4 = 4
}

Environment Information

Visual Studio Code

Name Version
Operating System Windows_NT x64 10.0.17134
VSCode 1.29.1
PowerShell Extension Version 1.10.0

PowerShell Information

Name Value
PSVersion 5.1.17134.407
PSEdition Desktop
PSCompatibleVersions 1.0 2.0 3.0 4.0 5.0 5.1.17134.407
BuildVersion 10.0.17134.407
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Visual Studio Code Extensions

Visual Studio Code Extensions(Click to Expand)
Extension Author Version
PowerShell ms-vscode 1.10.0
@rjmholt
Copy link
Contributor

rjmholt commented Dec 6, 2018

Thanks for opening an issue @ThubLives. This is being worked on in PowerShell/PowerShellEditorServices#805

@SydneyhSmith
Copy link
Collaborator

Closing as a duplicate of #1631

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

No branches or pull requests

3 participants