Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Settings in a Visual Studio Code Extension

I'm trying to add settings to a Visual Studio Code Extension (vscode-powershell)

I edited the settings.ts file to add: A new Interface:

export interface ICertificateSettings {
    certificateSubject?: string;
}

I edited the ISettings interface to add my Interface

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

Then the load function to add my default settings and the return value:

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)
    }
}

But when I run my extension using the debug panel then launch, I can't see my new "certificate" setting in the PowerShell section.

Do you know what I am missing?

like image 863
Rodolphe Beck Avatar asked Oct 08 '16 09:10

Rodolphe Beck


People also ask

How do I sync Visual Studio code extensions and settings?

You can turn on Settings Sync using the Turn On Settings Sync... entry in the Manage gear menu at the bottom of the Activity Bar. You will be asked to sign in and what preferences you would like to sync; currently Settings, Keyboard Shortcuts, Extensions, User Snippets, and UI State are supported.


1 Answers

Yes, you're missing the additions to package.json, since that is what actually defines the configuration options. The Typescript code merely reads them out. Specifically, you need to add a contributes.configuration section. For an example, see the corresponding section in vscode-powershell/package.json.

Yours would be something like (untested):

{
  ...
  "contributes": {
    ...
    "configuration": {
      "type": "object",
      "title": "myPluginId",   // whatever it really is
      "properties": {
        "certificate.certificateSubject": {
          "type": ["string", "null"],
          "default": null,
          "description": "..."
        }
      }
    },
    ...
  },
  ...
}
like image 99
Scott McPeak Avatar answered Oct 04 '22 07:10

Scott McPeak