我可以以编程方式更改 vscode 颜色主题吗?

Can I change vscode color theme programmatically?

vscode api 是否允许我们更改当前设置的颜色主题?

是的,这个有效:

let currentTheme = await vscode.workspace.getConfiguration().get("workbench.colorTheme");

await vscode.workspace.getConfiguration().update("workbench.colorTheme", "Red");

let newTheme = await vscode.workspace.getConfiguration().get("workbench.colorTheme");

Extension Development Host 中进行测试似乎有点古怪,但即使 currentTheme 可能 undefined 当前主题未由 workbench.colorTheme 设置(作为默认主题似乎不一定是)update() 仍然有效。

vscode.window.activeColorTheme 不获取活动主题名称,仅获取是否为 Dark/Light/HighContrast 且不可设置 - 但您可以看到用户当前对 dark/light/high 的偏好至少对比度。