英文:
How do I use path the to my VS Code extension's directory in a contributed setting's default value?
问题
我正在开发一个用于 Vale 风格检查的 VS Code 扩展。它包括一个名为 styles 的子目录,其中包含了各个风格规则的文件。在扩展内部,我在其 package.json 文件中覆盖了另一个扩展的配置选项:
"contributes": {
"configurationDefaults": {
"vale.valeCLI.config": ".vale.ini"
}
}
.vale.ini 文件包含在扩展的根目录中。是否有一个指向当前扩展的根目录的变量?或者有一种从扩展 ID 推导出它的方法吗?上述代码对我不起作用...
英文:
I am developing a VS Code extension for Vale style linting. It includes a styles sub-directory with files for individual style rules. Inside the extension, I'm overriding a config option from another extension in its package.json file:
"contributes": {
"configurationDefaults": {
"vale.valeCLI.config": ".vale.ini"
}
}
The .vale.ini file is included in the root directory of the extension itself. Is there a variable that points to the root directory of the current extension? Or a way derive it from an extension ID? The above code does not work for me...
答案1
得分: 0
I'm not aware of a variable for getting the path to an extension's installation directory in package.json.
I'd take a different approach: let the default setting value be null, and then in your extension's code, if the value is null, then use the default path. You can create a helper function that gets the value of the setting, and then if the value is not null, return that value, and if it is null, return the extensionPath property of the Extension type. Everywhere you want to use that setting's value, call that helper function.
英文:
I'm not aware of a variable for getting the path to an extension's installation directory in package.json.
I'd take a different approach: let the default setting value be null, and then in your extension's code, if the value is null, then use the default path. You can create a helper function that gets the value of the setting, and then if the value is not null, return that value, and if it is null, return the extensionPath property of the Extension type. Everywhere you want to use that setting's value, call that helper function.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论