zokugun / vscode-explicit-folding

Customize your Folding for Visual Studio Code
MIT License
103 stars 15 forks source link

Incorrect matching / folding when using other folding extensions #118

Open edgimar opened 1 month ago

edgimar commented 1 month ago

Describe the issue

When using an extension like Better Folding or rust-analyzer, it can happen that you end up with folds in your file that do not originate from the explicit folding extension. When I define folds using the explicit folding extension, these are typically larger-scale folds that describe a kind of nested outline of the code, and I would like to be able to fold these defined folds independent of the folds coming from other sources.

I am using explicitfolding.rules with several nested separatorRegex rules to match lines staring with //| and having varying numbers of * characters to indicate nesting level. Specifically, I am using this:

    "explicitFolding.rules": {
        "rust": {
            "separatorRegex": "\\s*\\/\\/\\| \\*(?=\\s|$)",
            "strict": "never",
            "nested": [
                {
                    "separatorRegex": "\\s*\\/\\/\\| \\*\\*(?=\\s|$)",
                    "nested": [
                        {
                            "separatorRegex": "\\s*\\/\\/\\| \\*\\*\\*(?=\\s|$)",
                            "nested": [
                                {
                                    "separatorRegex": "\\s*\\/\\/\\| \\*\\*\\*\\*(?=\\s|$)",
                                    "nested": [
                                        {
                                            "separatorRegex": "\\s*\\/\\/\\| \\*\\*\\*\\*\\*(?=\\s|$)",
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    },

Two concerns:

  1. as mentioned above, it would be nice if there were commands available to fold/unfold (e.g. recursively) ONLY the folds that correspond to any of the regexes, ignoring all other sources of folding.
  2. It appears that there is some kind of interaction with Better Folding and/or rust-analyzer that prevents the regex from reliably being detected. See the following image that demonstrates this:

image

daiyam commented 1 month ago

Have you tried to check if your config does what you want by using the setting "editor.defaultFoldingRangeProvider": "zokugun.explicit-folding", and disabling those extensions?

edgimar commented 1 month ago

Have you tried to check if your config does what you want by using the setting "editor.defaultFoldingRangeProvider": "zokugun.explicit-folding", and disabling those extensions?

Yes, that is what I'm currently doing, but I see it as a workaround, since it shouldn't be required to disable the folding provided by rust-analyzer in order to use explicit folding (which appears to be what the effect of setting editor.defaultFoldingRangeProvider is).

daiyam commented 1 month ago

Can you give me an example? So that I can test and see how I can fix it.

daiyam commented 1 month ago

+1