首页 > 解决方案 > 无法写入工作区设置,因为 .. 不是注册配置

问题描述

我正在尝试使用配置和工作区更新 VScode Setting.json 中的状态栏颜色。但是当代码尝试更新时,我收到以下错误:

Error: Unable to write to Workspace Settings because workbench.colorCustomizations.statusBar.background is not a registered configuration.

这是我的代码:

const conf = workspace.getConfiguration("workbench.colorCustomizations");
console.log('config-->'+JSON.stringify(conf));
await conf.update( "statusBar.background", "#00AA00");

在 GetConfiguration 上,我得到了现有的 StatusBar 颜色值,但无法更新它。

标签: node.jstypescriptvisual-studio-code

解决方案


也许它默认为工作区。如果您想更新它,即使您还没有打开工作区,也可以指定全局。

如果不指定目标,它可能会这样做:

await conf.update("statusBar.background", "#00AA00", vscode.ConfigurationTarget.Workspace);

您可能想要这样做:

await conf.update("statusBar.background", "#00AA00", vscode.ConfigurationTarget.Global);

推荐阅读