简体   繁体   English

VSCode命令行参数

[英]VSCode command line parameters

Can I access to VSCode command line parameters via extension? 我可以通过扩展名访问VSCode命令行参数吗? Eg, as Extension's predefined variable(like ${file}), as parameter for special constructor for Extension or auto-running task? 例如,作为扩展程序的预定义变量(例如$ {file}),作为扩展程序或自动运行任务的特殊构造函数的参数? For example, if I start VSCode like: 例如,如果我像这样启动VSCode:

code --myParam 10

Can I access the value of 'myParam' from my own extension or is there any other way to pass some parameter inside to the extension from command line options? 我可以从自己的扩展名访问'myParam'的值,还是可以通过命令行选项将其他参数传递给扩展名呢?

I found an answer by myself. 我自己找到了答案。 The secret was that VSCode can be launched by special URL, where you can add your own query parameters and then handle them in your extension. 秘密在于VSCode 可以通过特殊的URL 启动 ,您可以在其中添加自己的查询参数,然后在扩展名中对其进行处理 Example of the URL: URL的示例:

vscode://sergey.custom-plugin/customCommand?args={"param1":1, "param2":"cusomOption"}

Arguments can be passed at JSON format without any limitations. 可以以JSON格式传递参数而没有任何限制。 For this, we need to implement vscode.UriHandler . 为此,我们需要实现vscode.UriHandler Example of such a realization can be found here . 这种实现的示例可以在这里找到。 Hope this info can be helpful to someone. 希望此信息对某人有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM