Can you customize code folding?

后端 未结 3 1333
栀梦
栀梦 2021-02-14 03:58

Is it possible to customize the way code folding works in Visual Studio Code?

I use a common pattern of defining regions of code across a variety of different document

3条回答
  •  花落未央
    2021-02-14 04:19

    Now, there are three ways to achieve customized folding in a VSCode extension.

    1. Can define regex as folding markers in [language-name].configuration.json file. (However, we cannot have much customization with this approach)

    {
      "folding": {
        "markers": {
          "start": "starting regex",
          "end": "ending regex"
        }
      }
    }

    1. Can define a FoldingRangeProvider from the extension side as described in this answer. FoldingRange in vscode package supports folding customization with startLine, endLine, and foldingKind.

    2. Can use Language Server support with textDocument/foldingRange. FoldingRange in vscode-languageserver-protocol supports folding customization with startLine, endLine, startCharacter, endCharacter, and foldingKind.

    Check this for more details.

提交回复
热议问题