如何在贡献的设置默认值中使用路径指向我的VS Code扩展目录?

huangapple go评论65阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年5月26日 16:56:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76339219.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定