zokugun / vscode-explicit-folding

Customize your Folding for Visual Studio Code
MIT License
95 stars 14 forks source link

Document behavior of begin/end? #91

Open studyingegret opened 1 year ago

studyingegret commented 1 year ago

VSCode: 1.70.1 Explicit Folding: 0.21.0 Language: C

I'm trying to fold code with sections like this:

/// Section A
a
b
/// ---

/// Section B
c
d
/// ---

into this:

/// Section A ...

/// Section B ...

When I use:

"explicitFolding.rules": {
    "c": [
        {
            "begin": "///",
            "end": "///"
        },
    ]
}

the folding ranges appear correctly.

But when I use:

"explicitFolding.rules": {
    "c": [
        {
            "begin": "///",
            "end": "/// -"
        },
    ]
}

no folding ranges appear.

Did I misunderstand anything?

daiyam commented 1 year ago

You can use "explicitFolding.debug": true, to print some info in the output panel.

With the non-working rule, you will get:

[main] regex: /(?<_0_0>\/\/\/)|(?<_2_0>\/\/\/ \-)|(?<_0_1>\{\{\{)|(?<_2_1>\}\}\})/g
[main] line: 43, offset: 0, type: BEGIN, match: ///, regex: 0
[main] line: 46, offset: 0, type: BEGIN, match: ///, regex: 0
[main] line: 48, offset: 0, type: BEGIN, match: ///, regex: 0
[main] line: 51, offset: 0, type: BEGIN, match: ///, regex: 0
[document] foldings: []

The begin is matching both markers...

With the following rule, it is working as you intended:

{
    "beginRegex": "\\/\\/\\/(?! -)",
    "end": "/// -"
},
studyingegret commented 1 year ago

Thanks. It looks like the begin pattern and the end pattern must have no overlap, or the begin pattern will take precedence.

What about noting this in the documentation?

daiyam commented 1 year ago

Yep, I did forgot to add that...

studyingegret commented 1 year ago

Another solution is to use "nested": false to disable nesting, which will make the rule truly unambiguous (tested).

{
    "begin": "///",
    "end": "/// -",
    "nested": false
}
studyingegret commented 1 year ago

But "nested": false disables all other folding ranges within the folding ranges created by this rule, which means code in sections cannot be further folded. So your solution is the ultimate solution.

I guess beginners will be confused by this for a while...