[英]How do I set indenting options for a language in a VSCode extension?
我正在为Dart开发VS Code扩展。 Dart的约定是缩进2个空格(嗯,我也很讨厌),所以我想在用户打开Dart文件而不是使用其默认值时自动设置它。
在FormattingOptions
类中有一个insertSpaces
属性,但尚不清楚如何设置它,也不是做到这一点的最佳方法(例如,在语言级别进行设置比在每次打开文档时都保持设置更好。 )。
更新:请参阅下面的答案,该答案适用于VS Code的较新版本。
为了使用FormattingOptions
,在扩展程序的activate()
函数中为vscode.window.onDidChangeActiveTextEditor()
设置一个回调:
let disposable = vscode.window.onDidChangeActiveTextEditor((editor) => {
if(!editor) {
return;
}
if (editor.document.languageId != "your_id_here") {
return;
}
editor.options = {
cursorStyle: editor.options.cursorStyle,
insertSpaces: true,
tabSize: 2
};
});
context.subscriptions.push(disposable);
VS Code现在支持每种语言的缩进设置,您可以在package.json
设置默认值:
"configurationDefaults": {
"[dart]": {
"editor.tabSize": 2,
"editor.insertSpaces": true
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.