zokugun / vscode-explicit-folding

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

Rule priority #104

Open riley-x opened 1 year ago

riley-x commented 1 year ago

Is there a way to define which fold takes precedence when there are multiple matches in one line? For example, looking at the debug output I see

[main] line: 273, offset: 0, type: BEGIN, match: ***, regex: 0
[main] line: 273, offset: 12, type: BEGIN, match: ***, regex: 1
[main] line: 277, offset: 0, type: END, match: ***, regex: 1
[main] line: 290, offset: 0, type: END, match: ***, regex: 0
[document] foldings: [{"start":272,"end":276,"kind":3},{"start":272,"end":289,"kind":3}]

When I click the fold icon in VS code, it only folds between lines [272, 276]. Instead I would like for it to prioritize the second fold, between [272, 289].

daiyam commented 1 year ago

You could use nested but that will depend on your usage. Can you provide an example (code & rules)?

riley-x commented 1 year ago

Silly example:

function t1() { // {{{

}

function t2() {

} // }}}

with rules

{ 
    "begin": "{",
    "end": "}",
},
{
    "begin": "{{{",
    "end": "}}}",
},

VS code folds function t1 on the first line instead of the entire {{{}}} block. I know here you could just move the location of the comments, but in my use case it doesn't always apply/is ideal.

daiyam commented 1 year ago

Try

{
    "begin": "{{{",
    "end": "}}}",
    "nested": [
{ 
    "begin": "{",
    "end": "}",
},
// your other rules
    ]
},
riley-x commented 1 year ago

This folds the function t1 line above correctly now, but now function t2 is not foldable.

Actually I think just by exchanging the rule order in my above example does what I want:

{
    "begin": "{{{",
    "end": "}}}",
},
{
    "begin": "{",
    "end": "}",
},

Is this expected behavior?