zokugun / vscode-explicit-folding

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

Feature Request: share folding rules between languages #112

Open juarezr opened 4 months ago

juarezr commented 4 months ago

Describe the issue

I would like to suggest adding a way to share folding rules between languages.

It can help when one is working on projects that use multiple languages and tools because many languages have the same patterns for folding.

This can be especially useful for region folding across languages that use the same line comment syntax:

Configuration Example

Suggestion 1. - clone from laguange

    "[shellscript]": {
        "explicitFolding.rules": [
            {
                "beginRegex": "#[\\s]*region[\\s]+([\\w]+)",
                "endRegex": "#[\\s]*endregion",
            }
        ]
    },
    "[dockerfile]": {
        "explicitFolding.sameRulesAs": [
            "shellscript"
        ],
    },
    "[dockercompose]": {
        "explicitFolding.sameRulesAs": [
            "dockerfile"
        ],
    },
    "[yaml]": {
        "explicitFolding.sameRulesAs": [
            "shellscript"
        ],
    },
    "[c]": {
        "explicitFolding.rules": [
            {
                "beginRegex": "#if(?:n?def)?",
                "middleRegex": "#el(?:se|if)",
                "endRegex": "#endif"
            }
        ]
    },
    "[cpp]": {
        "explicitFolding.sameRulesAs": [
            "c",
            "java"
        ],
    },

Suggestion 2. - clone from language

    "explicitFolding.sharedRules": [
        {
            "beginRegex": "#[\\s]*region[\\s]+([\\w]+)",
            "endRegex": "#[\\s]*endregion",
            "applyTo": [
                "shellscript",
                "yaml",
                "dockerfile",
                "dockercompose",
            ],
        },
    ],
daiyam commented 4 months ago

You can already do:

"explicitFolding.rules": {
    "*": [
        {
            "beginRegex": "#[\\s]*region[\\s]+([\\w]+)",
            "endRegex": "#[\\s]*endregion",
        },
    ]
},
juarezr commented 4 months ago

You can already do:

"explicitFolding.rules": {
    "*": [
        {
            "beginRegex": "#[\\s]*region[\\s]+([\\w]+)",
            "endRegex": "#[\\s]*endregion",
        },
    ]
},

@daiyam,

Thanks for your reply.

Maybe I'm missing something, but: