如何在 vscode 扩展中获取 vscode 主题颜色?

How to get the vscode theme color in vscode extensions?

我想在我的扩展程序中使用当前 vscode 主题中使用的一些颜色。我如何获得颜色?

换句话说,我想在运行-扩展时将使用原始颜色的扩展颜色与基础vscode windows相匹配。

当您在 VS Code 实例中拥有所需的配色方案时,运行 Developer: Generate Color Theme From Current Settings 命令。这将生成一个颜色主题文件,然后您可以在自己的扩展中发布该文件

可以参考workbench colors:

const color = new vscode.ThemeColor('badge.background');

这将为您提供当前主题徽章颜色的参考。

请注意,您不能引用 TM 范围项目:#32813

https://code.visualstudio.com/docs/extensionAPI/vscode-api#_a-namethemecoloraspan-classcodeitem-id244themecolorspan

为了访问 WebView 上下文中的主题颜色,为所有 theme colors 生成了 css 个变量。例如,获取:

editor.background

您可以使用 css 变量:

var(--vscode-editor-background)