PowerShell / vscode-powershell

Provides PowerShell language and debugging support for Visual Studio Code
https://marketplace.visualstudio.com/items/ms-vscode.PowerShell
MIT License
1.71k stars 488 forks source link

orphan endregion disables folding. #1459

Closed ozu945 closed 6 years ago

ozu945 commented 6 years ago

System Details

Copy / paste the following commands into the PowerShell Integrated Console, and paste the output here:

code -v
1.25.1
1dfc5e557209371715f655691b1235b6b26a06be
x64

$pseditor.EditorServicesVersion
Major  Minor  Build  Revision
-----  -----  -----  --------
1      8      2      0

code --list-extensions --show-versions
alefragnani.numbered-bookmarks@0.11.1
chrmarti.regex@0.2.0
CoenraadS.bracket-pair-colorizer@1.0.59
DotJoshJohnson.xml@2.3.1
GrapeCity.gc-excelviewer@2.1.25
jasonlhy.hungry-delete@1.5.0
johnstoncode.svn-scm@1.31.0
jtr.vscode-position@1.0.1
ms-mssql.mssql@1.4.0
ms-python.python@2018.7.1
ms-vscode.csharp@1.15.2
ms-vscode.PowerShell@1.8.2
xyz.plsql-language@1.4.1

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

Issue Description

an orphan #endregion anywhere in the document will disable folding functionality. see exception below.

test case:

#endregion

begin {

}
process {

}

Attached Logs


[2018-08-01 14:35:48.703] [renderer1] [error] Cannot read property 'startIndex' of undefined: TypeError: Cannot read property 'startIndex' of undefined
    at LineNumberRange.fromTokenPair (C:\Users\<user>\.vscode\extensions\ms-vscode.powershell-1.8.2\out\src\features\Folding.js:33:51)
    at tokens.forEach (C:\Users\<user>\.vscode\extensions\ms-vscode.powershell-1.8.2\out\src\features\Folding.js:179:65)
    at Array.forEach (native)
    at FoldingProvider.matchScopeElements (C:\Users\<user>\.vscode\extensions\ms-vscode.powershell-1.8.2\out\src\features\Folding.js:174:16)
    at FoldingProvider.extractFoldableRegions (C:\Users\<user>\.vscode\extensions\ms-vscode.powershell-1.8.2\out\src\features\Folding.js:314:14)
    at FoldingProvider.<anonymous> (C:\Users\<user>\.vscode\extensions\ms-vscode.powershell-1.8.2\out\src\features\Folding.js:129:42)
    at Generator.next (<anonymous>)
    at C:\Users\<user>\.vscode\extensions\ms-vscode.powershell-1.8.2\out\src\features\Folding.js:10:71
    at Promise (<anonymous>)
    at __awaiter (C:\Users\<user>\.vscode\extensions\ms-vscode.powershell-1.8.2\out\src\features\Folding.js:6:12)
    at FoldingProvider.provideFoldingRanges (C:\Users\<user>\.vscode\extensions\ms-vscode.powershell-1.8.2\out\src\features\Folding.js:104:16)
    at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:730:368
    at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:109:515
    at new n.Class.derive._oncancel (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:84:560)
    at Object.t.asWinJsPromise (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:109:478)
    at e.provideFoldingRanges (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:730:322)
    at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:740:322
    at e._withAdapter (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:731:534)
    at e.$provideFoldingRanges (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:740:284)
    at e._doInvokeHandler (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:658:87)
    at e._invokeHandler (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:657:779)
    at e._receiveRequest (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:656:851)
    at e._receiveOneMessage (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:656:620)
    at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:655:544
    at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:658:673
    at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:96:599
    at e.fire (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:97:917)
    at u (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:159:721)
    at Socket.<anonymous> (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:159:898)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:191:7)
    at readableAddChunk (_stream_readable.js:178:18)
    at Socket.Readable.push (_stream_readable.js:136:10)
    at Pipe.onread (net.js:560:20)

Follow the instructions in the README about capturing and sending logs.

TylerLeonhardt commented 6 years ago

@glennsarti for awareness.

This is because of these lines of code:

https://github.com/PowerShell/vscode-powershell/blob/master/src/features/Folding.ts#L283-L288

The second if should probably be inside of the first if because we only want to consider the second "if" if we found what we were looking for in the first "if".

This is a trivial change if anyone wants the fame and fortune (ish) of contributing to you favorite extension 😊

TylerLeonhardt commented 6 years ago

Otherwise, we can take care of this as soon as we can.

glennsarti commented 6 years ago

Should there be tests for this?

TylerLeonhardt commented 6 years ago

Yeah definitely

glennsarti commented 6 years ago

PR is up with a test for it.