Multiple formatters in Visual Studio Code

末鹿安然 提交于 2021-01-27 22:15:08

问题


In my team, some people are using VS Code and others WebStorm. To align code format, I've written an extension for VS Code that adds some missing rules.

My plan was to run my extension along with the native formatters that ship with VS Code. I provide my edits using the API:

vscode.languages.registerDocumentFormattingEditProvider('typescript', {
    provideDocumentFormattingEdits(document: vscode.TextDocument) {
        const textEdit: vscode.TextEdit[];
        return textEdit;
    }
}

But it seems I can't run this along the native formatter, I have to chose either. Is it possible to run both using the above API?


回答1:


I found a way of running multiple formatters in VSCode. Just run the formatting command of one extension inside the your other extension.

Inside my own extention.ts:

const firstFormatter = commands.executeCommand('editor.action.formatDocument');

firstFormatter.then(() => myFormat());

Like this, any custom extension can sequentially format the document with multiple formatters.



来源:https://stackoverflow.com/questions/49428648/multiple-formatters-in-visual-studio-code

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