vscode-explicit-folding icon indicating copy to clipboard operation
vscode-explicit-folding copied to clipboard

Feature Request: share folding rules between languages

Open juarezr opened this issue 4 months ago • 2 comments

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:

  • C, C++, java, javascript, and other curly braces languages:
    • //region and //endregion
  • shell, dockerfile, yaml, python
    • #region and #endregion

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",
            ],
        },
    ],

juarezr avatar Mar 07 '24 20:03 juarezr