【问题标题】:Adding Settings in a Visual Studio Code Extension在 Visual Studio 代码扩展中添加设置
【发布时间】:2016-10-08 09:08:23
【问题描述】:

我正在尝试将设置添加到 Visual Studio 代码扩展 (vscode-powershell)

我编辑了settings.ts 文件以添加: 新界面:

export interface ICertificateSettings {
    certificateSubject?: string;
}

我编辑了ISettings 接口以添加我的接口

export interface ISettings {
    useX86Host?: boolean,
    enableProfileLoading?: boolean,
    scriptAnalysis?: IScriptAnalysisSettings,
    developer?: IDeveloperSettings,
    certificate?: ICertificateSettings
}

然后加载函数添加我的默认设置和返回值:

export function load(myPluginId: string): ISettings {
    let configuration = vscode.workspace.getConfiguration(myPluginId);

    let defaultScriptAnalysisSettings = {
        enable: true,
        settingsPath: ""
    };

    let defaultDeveloperSettings = {
        powerShellExePath: undefined,
        bundledModulesPath: "../modules/",
        editorServicesLogLevel: "Normal",
        editorServicesWaitForDebugger: false
    };

    let defaultCertificateSettings = {
        certificateSubject: ""
    };

    return {
        useX86Host: configuration.get<boolean>("useX86Host", false),
        enableProfileLoading: configuration.get<boolean>("enableProfileLoading", false),
        scriptAnalysis: configuration.get<IScriptAnalysisSettings>("scriptAnalysis", defaultScriptAnalysisSettings),
        developer: configuration.get<IDeveloperSettings>("developer", defaultDeveloperSettings),
        certificate: configuration.get<ICertificateSettings>("certificate", defaultCertificateSettings)
    }
}

但是当我使用调试面板运行我的扩展程序然后启动时,我在 PowerShell 部分看不到我的新“证书”设置。

你知道我错过了什么吗?

【问题讨论】:

  • 运气好吗?今天使用 v1.36 为我提供了一个类似的最小可重现示例。这很酷,您可以使用默认对象。 ??????

标签: visual-studio-code vscode-extensions


【解决方案1】:

是的,您缺少对package.json 的添加,因为这是实际定义配置选项的内容。 Typescript 代码只是将它们读出。具体来说,您需要添加一个contributes.configuration 部分。例如,请参阅vscode-powershell/package.json 中的相应部分。

你的会是这样的(未经测试):

{
  ...
  "contributes": {
    ...
    "configuration": {
      "type": "object",
      "title": "myPluginId",   // whatever it really is
      "properties": {
        "certificate.certificateSubject": {
          "type": ["string", "null"],
          "default": null,
          "description": "..."
        }
      }
    },
    ...
  },
  ...
}

【讨论】:

    猜你喜欢
    • 2022-11-14
    • 1970-01-01
    • 1970-01-01
    • 2022-11-30
    • 1970-01-01
    • 2015-07-22
    • 2011-09-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多