在 Visual Studio Code 扩展中添加设置

7

我正在尝试为 Visual Studio Code 扩展 (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测试了一个类似的最小可重现示例,效果很好。你可以使用默认对象,这非常酷。 - Sean
1个回答

3
是的,你错过了对于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": "..."
        }
      }
    },
    ...
  },
  ...
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接