【问题标题】:vscode: is there an api for accessing config values from a vscode extensionvscode:是否有用于从 vscode 扩展访问配置值的 api
【发布时间】:2017-05-24 07:26:14
【问题描述】:

我正在为 vscode 1.12.2 编写一个扩展,我正在尝试确定默认主题。 Atom Editor 有一个不错的API for accessing config values,例如:

atom.config.defaultSettings.core.themes[0]
"one-dark-ui"
atom.config.defaultSettings.core.themes[1]
"one-dark-syntax"

vscode 中有类似的东西吗?

我可以在~/AppData/Roaming/Code/User/settings.json 中看到值“workbench.colorTheme”:

   // "terminal.integrated.shell.windows": "/Program Files/Git/bin/bash.exe"
    "terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe",
    "terminal.integrated.shellArgs.windows": [
        "/k",
        "C:\\Program Files\\Git\\bin\\bash.exe"
    ],
    "workbench.colorTheme": "Default Light+" <-- here

但是,我宁愿不采用自定义解决方案,直接将配置文件读取为 JSON,特别是因为它允许非默认 JSON 值(例如 cmets),我大概必须预先解析出来。

虽然这个问题只针对确定主题,但它确实适用于任何配置参数。我在vscode html api 或浏览打字文件/c/Program Files (x86)/Microsoft VS Code/resources/app/out/vs/vscode.d.ts 中没有看到任何内容

【问题讨论】:

    标签: visual-studio-code vscode-extensions


    【解决方案1】:

    你试过了吗:

    const workbenchConfig = vscode.workspace.getConfiguration('workbench')
    const theme = workbenchConfig.get('colorTheme')
    

    这是关于配置对象的文档:https://code.visualstudio.com/docs/extensionAPI/vscode-api#WorkspaceConfiguration

    【讨论】:

    • 为我工作,就像你所有的答案一样。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-08
    • 1970-01-01
    • 2018-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多