您如何确定 VS Code 使用了哪个格式化程序?
How do you determine which formatter is being used for VS Code?
如果您安装了多个扩展程序,您如何确定文档中哪个格式器是 运行?
例如,我有几个 HTML 扩展可能会格式化 HTML 但我不确定实际上是哪个在格式化,或者是否有多个。老实说,我什至不确定哪些扩展可能对格式有贡献。最近 HTML 和 CSS 中的自动格式化以我不关心的方式改变了它们的格式化方式,我想知道哪个扩展正在执行此操作,以便我可以更改配置或禁用扩展。目前我有 80-90 个扩展,所以一个一个地进行是一个非常及时的过程,如果有一种程序化的方法来确定它,我想远离它。似乎扩展必须向格式化服务注册,以便它们可以进行自动格式化,但我不确定是否有调试、挂钩或查看这些的方法。
Starting with the 1.33 release (March 2019),尝试格式化已注册多个格式化程序的文件会出现如下弹出窗口:
请注意,如果格式化通过 "format on save" 或 "format on paste" 隐式发生,则通知为 "silent",这意味着您需要单击右下角的铃铛才能显示:
然后 Configure...
菜单会列出当前语言可用的所有格式化程序。可以选择其中之一作为 Format Document
和 Format Selection
:
的默认格式化程序
例如,在此处选择 "Prettier" 会导致将其添加到全局 settings.json
:
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
还有两个用于使用特定格式化程序格式化文件的新命令,Format Document With...
和 Format Selection With...
。这对于使用未设置为默认格式化程序的格式化程序格式化特定文件很有用。前者也可以从上下文菜单中获得:
加上Gama11给出的答案
您可以在给定路径
下方到达 settings.json
C:\Users\<username>\AppData\Roaming\Code\User\settings.json
我正在为我的 html
文件使用 "prettier"
格式化程序,
如果已配置,您还可以找到用于其他扩展的格式化程序。
看看https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
ctrl-shift-p > search "open json"
添加
{
"editor.defaultFormatter": null,
"[javascriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
}
rofrol's will soon be better managed, from issue 126187
中提到的默认级别格式化程序
It should be deprecated and banished for the sanity of developers everywhere.
Few days ago I ventured off the path of JS/TS/CSS/HTML/JSON and thought I try VScode with something new, ReScript.
I installed the plugin https://marketplace.visualstudio.com/items?itemName=chenglou92.rescript-vscode
But the formatting didn’t work.
Tried the same with a python formatter plugin, same problem.
After a little investigation I found that I had this configured at the top level of my settings.json
. It also has a nice GUI pulldown.
"editor.defaultFormatter": "esbenp.prettier-vscode",
And this was apparently overriding the ReScript and python plugins.
It might have been overriding ALL plugins, even for languages that prettier is not even registered to use, which is a diabolical thing to do.
After some googling I found that I could add this and fix my problem
"[rescript]": {
"editor.defaultFormatter": "chenglou92.rescript-vscode"
}
Or I could just set defaultFormatter
back to null
and let the plugins take over.
But I was wondering how many users have had this same problem? And how many plugins have to deal with this? And why did I think adding a defaultFormatter to the top level was a good idea?
嗯,在 VSCode 1.61(2021 年 9 月)中,现在将显示一个模式对话框。
“Configure
”操作将使您为该特定语言而非所有语言配置默认格式化程序。
参见 commit afc8ab1
如果您安装了多个扩展程序,您如何确定文档中哪个格式器是 运行?
例如,我有几个 HTML 扩展可能会格式化 HTML 但我不确定实际上是哪个在格式化,或者是否有多个。老实说,我什至不确定哪些扩展可能对格式有贡献。最近 HTML 和 CSS 中的自动格式化以我不关心的方式改变了它们的格式化方式,我想知道哪个扩展正在执行此操作,以便我可以更改配置或禁用扩展。目前我有 80-90 个扩展,所以一个一个地进行是一个非常及时的过程,如果有一种程序化的方法来确定它,我想远离它。似乎扩展必须向格式化服务注册,以便它们可以进行自动格式化,但我不确定是否有调试、挂钩或查看这些的方法。
Starting with the 1.33 release (March 2019),尝试格式化已注册多个格式化程序的文件会出现如下弹出窗口:
请注意,如果格式化通过 "format on save" 或 "format on paste" 隐式发生,则通知为 "silent",这意味着您需要单击右下角的铃铛才能显示:
然后 Configure...
菜单会列出当前语言可用的所有格式化程序。可以选择其中之一作为 Format Document
和 Format Selection
:
例如,在此处选择 "Prettier" 会导致将其添加到全局 settings.json
:
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
还有两个用于使用特定格式化程序格式化文件的新命令,Format Document With...
和 Format Selection With...
。这对于使用未设置为默认格式化程序的格式化程序格式化特定文件很有用。前者也可以从上下文菜单中获得:
加上Gama11给出的答案 您可以在给定路径
下方到达settings.json
C:\Users\<username>\AppData\Roaming\Code\User\settings.json
我正在为我的 html
文件使用 "prettier"
格式化程序,
如果已配置,您还可以找到用于其他扩展的格式化程序。
看看https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
ctrl-shift-p > search "open json"
添加
{
"editor.defaultFormatter": null,
"[javascriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
}
rofrol's
It should be deprecated and banished for the sanity of developers everywhere.
Few days ago I ventured off the path of JS/TS/CSS/HTML/JSON and thought I try VScode with something new, ReScript.
I installed the plugin https://marketplace.visualstudio.com/items?itemName=chenglou92.rescript-vscode
But the formatting didn’t work.
Tried the same with a python formatter plugin, same problem.After a little investigation I found that I had this configured at the top level of my
settings.json
. It also has a nice GUI pulldown."editor.defaultFormatter": "esbenp.prettier-vscode",
And this was apparently overriding the ReScript and python plugins.
It might have been overriding ALL plugins, even for languages that prettier is not even registered to use, which is a diabolical thing to do.After some googling I found that I could add this and fix my problem
"[rescript]": { "editor.defaultFormatter": "chenglou92.rescript-vscode" }
Or I could just set
defaultFormatter
back tonull
and let the plugins take over.But I was wondering how many users have had this same problem? And how many plugins have to deal with this? And why did I think adding a defaultFormatter to the top level was a good idea?
嗯,在 VSCode 1.61(2021 年 9 月)中,现在将显示一个模式对话框。
“Configure
”操作将使您为该特定语言而非所有语言配置默认格式化程序。
参见 commit afc8ab1