Добавление настроек в расширение кода Visual Studio

Я пытаюсь добавить настройки в расширение кода 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.

Знаете, чего мне не хватает?


person Rodolphe Beck    schedule 08.10.2016    source источник
comment
При удаче? Аналогичный минимально воспроизводимый пример работал у меня сегодня с использованием версии 1.36. Это довольно здорово, что вы можете использовать объект по умолчанию. ????   -  person Sean    schedule 07.07.2019


Ответы (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": "..."
        }
      }
    },
    ...
  },
  ...
}
person Scott McPeak    schedule 30.08.2019