Skip to content

Rule priority #104

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

Open
riley-x opened this issue Jun 14, 2023 · 5 comments
Open

Rule priority #104

riley-x opened this issue Jun 14, 2023 · 5 comments

Comments

@riley-x
Copy link

riley-x commented Jun 14, 2023

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

daiyam commented Jun 14, 2023

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

@riley-x
Copy link
Author

riley-x commented Jun 14, 2023

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

daiyam commented Jun 14, 2023

Try

{
    "begin": "{{{",
    "end": "}}}",
    "nested": [
{ 
    "begin": "{",
    "end": "}",
},
// your other rules
    ]
},

@riley-x
Copy link
Author

riley-x commented Jun 14, 2023

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?

@daiyam
Copy link
Member

daiyam commented Oct 26, 2024

Is this expected behavior?

Yes because if { is at the beginning, it will always match the {{{ 3 times.
Passing {{{ before { will ensure that {{{ is matched before {.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants