Can you customize code folding?

故事扮演 提交于 2019-12-04 02:50:49
Tomáš Hübelbauer

FoldingRangeProvider can be used if you are looking to contribute custom folding logic in an extension.

Be sure to set your VS Code version in engines in package.json to 1.23, the version that introduced this.

Here's how you'd use one.

export function activate(context: ExtensionContext) {
    languages.registerFoldingRangeProvider({ scheme: 'file', language: 'markdown' }, new MyFoldingRangeProvider());
}

class MyFoldingRangeProvider implements FoldingRangeProvider {
    provideFoldingRanges(document: TextDocument, context: FoldingContext, token: CancellationToken): FoldingRange[] {
        return detectRanges().map(({ lineStart, lineEnd }) => new FoldingRange(lineStart, lineEnd));
    }
}

Unfortunately, not at the moment. There is a an open issue in github for this very topic.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!