[英]Adding Settings in a Visual Studio Code Extension
I'm trying to add settings to a Visual Studio Code Extension (vscode-powershell) 我正在尝试将设置添加到Visual Studio代码扩展(vscode-powershell)
I edited the settings.ts
file to add: A new Interface: 我编辑了
settings.ts
文件来添加:一个新的界面:
export interface ICertificateSettings {
certificateSubject?: string;
}
I edited the ISettings
interface to add my Interface 我编辑了
ISettings
界面以添加我的界面
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. 但是当我使用调试面板运行我的扩展然后启动时,我无法在PowerShell部分看到我的新“证书”设置。
Do you know what I am missing? 你知道我错过了什么吗?
Yes, you're missing the additions to package.json
, since that is what actually defines the configuration options. 是的,你错过了对
package.json
的补充,因为这是实际定义配置选项的内容。 The Typescript code merely reads them out. Typescript代码只是将它们读出来。 Specifically, you need to add a
contributes.configuration
section. 具体来说,您需要添加
contributes.configuration
部分。 For an example, see the corresponding section in vscode-powershell/package.json
. 有关示例,请参阅
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": "..."
}
}
},
...
},
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.