Skip to content
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

Add option to end region when indentation level does not match #107

Open
DeltaRazero opened this issue Oct 7, 2023 · 4 comments
Open

Add option to end region when indentation level does not match #107

DeltaRazero opened this issue Oct 7, 2023 · 4 comments
Assignees

Comments

@DeltaRazero
Copy link

Describe the issue

I use a certain way to split my code into regions which doesn't use explicit region endings. I use the 'seperatorRegex' function for this, and this works well in general. However, there is one drawback with this, and that is that indentation levels are ignored with this (see the code example and current behaviour).

I would suggest adding an option to end the region when a line — that includes non-whitespace/tab characters — has less indentation than the line on which the region was started.

This could potentially also be implemented for when begin/end parameters are being instead, but that is not my current use-case though.

To reproduce

  • VSCode: 1.82.3
  • Explicit Folding: 0.23.1
  • Language: python, cpp, virtually all I guess

Code Example

Python Example
class Foo:

    # :: REGION 01 :: #

    def function_01(self):
        pass

    def function_02(self):
        pass

    # :: REGION 02 :: #

    def function_03(self):
        pass

    def function_04(self):
        pass


class Bar:

    # :: REGION 03 :: #

    def function_05(self):
        pass

    def function_06(self):
        pass

    # :: REGION 04 :: #

    def function_07(self):
        pass

    def function_08(self):
        pass
C++ Example
class Foo
{

    // :: REGION 01 :: //

    void function_01()
    {}

    void function_02()
    {}

    // :: REGION 02 :: //

    void function_03()
    {}

    void function_04()
    {}
}

class Bar
{

    // :: REGION 03 :: //

    void function_05()
    {}

    void function_06()
    {}

    // :: REGION 04 :: //

    void function_07()
    {}

    void function_08()
    {}
}

Settings

"editor.foldingStrategy": "auto",
"editor.defaultFoldingRangeProvider": "zokugun.explicit-folding",
"explicitFolding.rules": {
    "*":
        {
            "separatorRegex": "([a-zA-Z@&]+.*? :: )",
            "indentation": true // I propose to add this option
        },
},

Expected behavior

Python Example
class Foo:

    # :: REGION 01 :: #

    def function_01(self):
        pass

    def function_02(self):
        pass

    # :: REGION 02 :: #    # Folded
class Bar:

    # :: REGION 03 :: #

    def function_05(self):
        pass

    def function_06(self):
        pass

    # :: REGION 04 :: #

    def function_07(self):
        pass

    def function_08(self):
        pass
C++ Example
class Foo
{

    // :: REGION 01 :: //

    void function_01()
    {}

    void function_02()
    {}

    // :: REGION 02 :: //    // Folded
}

class Bar
{

    // :: REGION 03 :: //

    void function_05()
    {}

    void function_06()
    {}

    // :: REGION 04 :: //

    void function_07()
    {}

    void function_08()
    {}
}

Current behavior

Python Example
class Foo:

    # :: REGION 01 :: #

    def function_01(self):
        pass

    def function_02(self):
        pass

    # :: REGION 02 :: #    # Folded
    # :: REGION 03 :: #

    def function_05(self):
        pass

    def function_06(self):
        pass

    # :: REGION 04 :: #

    def function_07(self):
        pass

    def function_08(self):
        pass
C++ Example
class Foo
{

    // :: REGION 01 :: //

    void function_01()
    {}

    void function_02()
    {}

    // :: REGION 02 :: //    // Folded
    // :: REGION 03 :: //

    void function_05()
    {}

    void function_06()
    {}

    // :: REGION 04 :: //

    void function_07()
    {}

    void function_08()
    {}
}
@daiyam
Copy link
Member

daiyam commented Oct 7, 2023

I could modify begin/while to capture groups so you could do:

{
    "beginRegex": "^(\\s*)(?:#|\\/\\/)\\s*[a-zA-Z@&]+.*? :: ",
    "whileRegex": "^\\1"
},

@DeltaRazero
Copy link
Author

That would probably work perfectly fine for me

@daiyam daiyam self-assigned this Oct 26, 2024
daiyam added a commit that referenced this issue Oct 28, 2024
@daiyam
Copy link
Member

daiyam commented Oct 28, 2024

In the next version, you will be able to do:

"explicitFolding.rules": [
	{
		"indentation": true,
		"nested": [
			{
				"separatorRegex": "#\\s+::\\s+",
				"foldBOF": false,
			},
		],
	},
],

which will give you the result you are expecting.

@daiyam
Copy link
Member

daiyam commented Oct 29, 2024

The feature is available in the newest version.

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