VSCode API:workspace.getConfiguration的section参数来源解析
VSCode API getConfiguration的section参数来源解析
- section参数本质是插件配置的根命名空间,它的定义不在单独的代码文件里,而是写在插件的
package.json的contributes.configuration字段中。 - 以你提到的
translatorHelper为例,这个section对应的是插件配置项的顶层前缀。在该仓库的package.json里,应该能找到类似这样的配置结构:"contributes": { "configuration": { "title": "Translator Helper", "properties": { "translatorHelper.apiKey": { "type": "string", "description": "API密钥" }, "translatorHelper.targetLanguage": { "type": "string", "default": "zh-CN" } } } } - 当调用
vscode.workspace.getConfiguration('translatorHelper')时,就能直接获取这个命名空间下的所有配置项,不用单独在代码里定义这个字符串常量(当然也可以定义,但不是必须的)。 - 你没找到相关定义的原因是这个section名称是和package.json里的配置结构绑定的,而非在ts文件中显式声明。
内容的提问来源于stack exchange,提问作者chiralcentre
相关产品推荐
相关产品推荐

