Version: 1.37.0-insider (user setup)
Commit: 0bd57ac9efae79f9eb1aedc3818ebbb570b9bf6b
Date: 2019-08-02T21:22:13.578Z
Electron: 4.2.7
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Windows_NT x64 6.2.9200
Consider the following code:
Function Test-Stuff_1 {
#region Description
#region MISSING END REGION SECTION
#endregion
}
Function Test-Stuff_2 {
# Function not visible
}
Function Test-Stuff_3 {
# Function not visible
#Delete ticket
#endregion
}
Function Test-Stuff_4 {
# Function visible
}
When you select FOLD ALL or press CTRL+K and CTRL+0 you'll see that two functions are no longer visible:

This made me freak out at first as I thought I'd lost some of my code. The scope for checking opening and closing regions should be limited to the function itself.
@DarkLite1 thanks for opening this issue--I am able to reproduce this...interestingly it seems to be triggered by the comments in the first function i.e. I am unable to repro this without the first comment in the first function could be related to #2013
There's no reason a region can't start in one function and end in another. In a case like this, if we take an opinion on how bad input works, it will probably break another use case. Comparing this with something like HTML, if you don't close a tag, everything is subordinate to that, so I think we're consistent there and this is working by design.
@rjmholt I hear what you're saying. But there is nothing in the world that can convince me there's a reason to have an opening region in one function and a closing region in another function. So if this is the design, I think it should be reevaluated.
Would it be possible for the folding logic to first look at functions and handle them as one unit?
But Regions aren't a part of the language. They're there to help the developer group things together and collapse things they don't want to see in the moment. It's not for the extension to decide if someone's region layout makes sense.
Further: this is the same behavior you see with the ISE when you minimize the regions:

@corbob yeah I hear you.... It's hard to admit but you're right. If the PowerShell ISE does the same then I simply don't have a point anymore. It would've been a nice to have but I understand if this gets closed. Thanks for the feedback guys, appreciate it anyhow.
@DarkLite1 agree that it would be awesome if folding was smart enough to know what users are intending, but this is not an easy challenge and near impossible to get right 100% of the time...thanks for opening the discussion
If you thing this should be closed, feel free to do so. I'm ok with that. Thanks for clearing up the way I looked at this.
Most helpful comment
But Regions aren't a part of the language. They're there to help the developer group things together and collapse things they don't want to see in the moment. It's not for the extension to decide if someone's region layout makes sense.
Further: this is the same behavior you see with the ISE when you minimize the regions:
