问题
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