Visual Studio Code中的多个格式化程序 [英] Multiple formatters in Visual Studio Code

查看:221
本文介绍了Visual Studio Code中的多个格式化程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的团队中,有些人正在使用VS Code,而另一些人正在使用WebStorm.为了对齐代码格式,我编写了VS Code扩展,其中添加了一些缺少的规则.

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.

我的计划是将扩展程序与VS Code一起提供的本机格式化程序一起运行.我使用API​​提供了修改内容:

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;
    }
}

但是似乎我不能沿着本机格式化程序运行它,我必须选择其中一个.是否可以同时使用上述API来运行两者?

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?

推荐答案

我发现了一种在VSCode中运行多个格式化程序的方法.只需在另一个扩展程序中运行一个扩展程序的格式命令即可.

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

在我自己的extension.ts中:

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.

这篇关于Visual Studio Code中的多个格式化程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆