我试图提供使用用户定义的首选引用样式设置(配置)来自定义 VS Code 扩展的选项。我已经在我的中配置了它package.json:
"contributes": {
"configuration": {
"type": "object",
"title": "Jasmine code snippets configuration",
"properties": {
"jasmineSnippets.quoteStyle": {
"type": "string",
"enum": [
"'",
"\"",
"`"
],
"default": "'",
"description": "Code snippets quote style"
}
}
}
},
Run Code Online (Sandbox Code Playgroud)
settings.json并可以像这样在我的中访问它:
"jasmineSnippets.quoteStyle": "`"
Run Code Online (Sandbox Code Playgroud)
我现在如何在我的snippets.json文件中使用该值?例如,对于此代码片段,我想将硬编码的 ` 更改为配置的属性。
"it": {
"prefix": "it",
"body": "it(`${1:should behave...}`, () => {\n\t$2\n});",
"description": "creates a test method",
"scope": "source.js"
},
Run Code Online (Sandbox Code Playgroud)
我从文档中找到的所有内容都没有帮助,因为它假设您是从 JavaScript 文件而不是 JSON 文件中读取它:
您可以使用从扩展程序读取这些值
vscode.workspace.getConfiguration('myExtension')。