我尝试在 Visual Studio 中格式化代码时遇到错误。我为我使用的语言安装了以下插件:
shell-format (bash)
Go (golang)
PyFormat (python)
我还设置了一个键绑定(bind) SHIFT+ALT+F 来格式化文件,并带有以下条件:
editorHasDocumentFormattingProvider && editorTextFocus && !editorReadonly
但是每当我使用此快捷方式(或在保存时使用自动格式)时,没有任何内容被格式化,并且我在底部的工具栏中看到此错误:
“扩展‘JSON 语言功能’无法格式化 [文件路径]”
我什至不知道这个扩展是什么,因为我没有安装任何基于 JSON 的扩展。
还有人见过类似的东西吗?
最佳答案
我刚刚用 Python 解决了这个问题,结果发现问题是我的设置中有这样一行:
"editor.defaultFormatter": "vscode.json-language-features",
因为我希望 Python 使用black
。那是行不通的,并给了我同样的错误消息,我更改了上面的行,因此它仅与 json
相关,并对其他语言的格式化程序进行了双重检查(不要不要忘记检查用户、远程和工作区的设置。
最后,我的默认格式设置如下所示:
"editor.formatOnSave": true,
"[python]": {
"editor.codeActionsOnSave": {
"source.organizeImports.python": true,
}
},
"[django-html]": {
"editor.formatOnSave": false,
},
"[vue]": {
"editor.defaultFormatter": "octref.vetur"
},
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features",
},
很快,我保存时的 Python 格式又恢复正常了。
我怀疑您的问题是相同的,但如果使 vscode.json-language-features
json
具体化,请发布您的 settings.json
不起作用...
关于visual-studio-code - 由于 "Extension ' JSON 语言功能“无法格式化文件”错误,Visual Studio Code 未格式化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61077014/