在Visual Studio代码扩展中添加设置

时间:2016-10-08 09:08:23

标签: visual-studio-code vscode-extensions

我尝试将设置添加到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)
    }
}

但是当我使用调试面板运行我的扩展程序然后启动时,我无法看到我的新证书&#34;设置PowerShell部分。

你知道我错过了吗?

1 个答案:

答案 0 :(得分:0)

是的,您缺少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": "..."
        }
      }
    },
    ...
  },
  ...
}