vscode-explicit-folding icon indicating copy to clipboard operation
vscode-explicit-folding copied to clipboard

Document behavior of begin/end?

Open studyingegret opened this issue 3 years ago • 5 comments

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?

studyingegret avatar Aug 31 '22 05:08 studyingegret

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": "/// -"
},

daiyam avatar Aug 31 '22 06:08 daiyam

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?

studyingegret avatar Aug 31 '22 07:08 studyingegret

Yep, I did forgot to add that...

daiyam avatar Aug 31 '22 07:08 daiyam

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

{
    "begin": "///",
    "end": "/// -",
    "nested": false
}

studyingegret avatar Aug 31 '22 10:08 studyingegret

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...

studyingegret avatar Sep 01 '22 07:09 studyingegret