Skip to content

orphan endregion disables folding. #1459

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

Closed
ozu945 opened this issue Aug 1, 2018 · 5 comments · Fixed by #1461
Closed

orphan endregion disables folding. #1459

ozu945 opened this issue Aug 1, 2018 · 5 comments · Fixed by #1461
Labels

Comments

@ozu945
Copy link

ozu945 commented Aug 1, 2018

System Details

  • Operating system name and version: Win 7
  • VS Code version: 1.25.1
  • PowerShell extension version: 5.1.14409.1012
  • Output from $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

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
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

$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
Copy link
Member

@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
Copy link
Member

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

@glennsarti
Copy link
Contributor

Should there be tests for this?

@TylerLeonhardt
Copy link
Member

Yeah definitely

glennsarti added a commit to glennsarti/vscode-powershell that referenced this issue Aug 2, 2018
… region tokens

Previously the folding provider would crash with an error if the document
contained mismatched begin and end region comments e.g. If the document
started with `# endregion`.  This was due to the token stack code always
assuming there was at least one element in the stack.  This commit modifies
the end region detection to only trigger if there was a previous begin region.
@glennsarti
Copy link
Contributor

PR is up with a test for it.

TylerLeonhardt pushed a commit that referenced this issue Aug 3, 2018
…kens (#1461)

Previously the folding provider would crash with an error if the document
contained mismatched begin and end region comments e.g. If the document
started with `# endregion`.  This was due to the token stack code always
assuming there was at least one element in the stack.  This commit modifies
the end region detection to only trigger if there was a previous begin region.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants