【问题标题】:Is there a way to select/set a theme through the VS Code extension API?有没有办法通过 VS Code 扩展 API 选择/设置主题?
【发布时间】:2019-08-14 09:32:42
【问题描述】:

我希望能够通过扩展 API 在给定时间设置/选择主题。

示例: 6:00 PM — Set theme "OneDark Pro"

到目前为止,我一直在阅读扩展 API 文档,但没有找到可以以这种方式帮助我的信息。

这将是我的第一个扩展和 Typescript 项目,所以我确定我可能遗漏了一个明显的点。

vscode.ThemeColor.set('themeName');

【问题讨论】:

    标签: typescript visual-studio-code vscode-extensions


    【解决方案1】:

    有一个"workbench.colorTheme" 设置(请注意,它仅适用于工作区本地settings.json 文件)。此外,还有一个API to read and modify settings。这意味着您可以执行以下操作:

    var folders = vscode.workspace.workspaceFolders;
    if (folders !== undefined) {
      vscode.workspace.getConfiguration('workbench', folders[0].uri)
          .update(
              'colorTheme', 'themeName', vscode.ConfigurationTarget.Workspace);
    }
    

    注意:此逻辑已简化并假设工作区仅包含单个文件夹/不适用于multi-root workspaces

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-13
      • 2018-04-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多