[英]VSCode formatting being overrided
我正在使用Angular进行开发,经过将近一年的完美格式化,我的vscode才刚刚起步。 更具体地说,当我单击“格式文档”时。 它缩进2个空格而不是4个空格。如何解决此问题,或检查什么覆盖了我的设置?
我的用户和工作区设置(它们相同):
{
"editor.fontSize": 16,
"editor.tabSize": 4,
"editor.insertSpaces": true,
"editor.wordWrap": "off",
"workbench.iconTheme": "material-icon-theme",
"editor.detectIndentation": true,
"prettier.bracketSpacing": true,
"prettier.eslintIntegration": true,
"prettier.singleQuote": true,
"prettier.tabWidth": 4,
"prettier.useTabs": false,
}
我的扩展程序列表:
Angular Essentials (注意更漂亮是一个依赖项,并且已安装所有其他dep)
支架对 着色器语言-vscode-javascript-angular2
编辑:
同样,它在我的编辑器底部显示缩进2个空格,当我单击它并单击4个空格时,它表示已配置的选项卡大小。 如果不是默认文件,为什么不为每个文件设置呢?
我相信这是因为Angular Essentials Prettier插件默认缩进2,因此您必须为Prettier创建一个单独的配置才能正常工作。
看来这可能是两件事的结果:
首先,注释中提到的.editorconfig
文件是Angular生成的单独文件(特别是与VSCode不相关)。 它可作为任何编辑者阅读和服从的指南,允许开发人员以相同的样式处理同一个项目,但可以选择多个IDE /编辑器。 它看起来应该像这样:
# Editor configuration, see https://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
max_line_length = off
trim_trailing_whitespace = false
正如评论中已经指出的那样,可以在https://editorconfig.org上找到更多信息。
在您的情况下,您需要将indent_size = 2
行更改为indent_size = 4
。
如果这样做不能解决问题,也可能是Angular CLI正在生成具有2个空格的文件,而VSCode正在根据"editor.detectIndentation": true
设置检测到该缩进。 这已经是一段时间的热门话题了 ,应该可以解决这个问题 ,但是根据这个评论似乎没有帮助。
我使用VSCode中的“ 语言特定设置”修复了此问题。 我选择将制表符的大小强制设置为4,并对Angular生成的所有文件类型禁用缩进检测。 您可以将其放在VSCode用户设置中,或按照以下说明进行操作 ,以获取“正确”的路由。
{
"[typescript]": {
"editor.tabSize": 4,
"editor.detectIndentation": false
},
"[javascript]": {
"editor.tabSize": 4,
"editor.detectIndentation": false
},
"[html]": {
"editor.tabSize": 4,
"editor.detectIndentation": false
},
"[json]": {
"editor.tabSize": 4,
"editor.detectIndentation": false
},
"[jsonc]": {
"editor.tabSize": 4,
"editor.detectIndentation": false
}
}
添加"editor.formatOnSave": true
或只是在任何地方都按Ctrl + Shift + I (格式化文档)即可。
"editor.formatOnPaste": true
如果经常粘贴2个空格的示例代码,则"editor.formatOnPaste": true
可能也很有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.