[英]Can a vscode extension create an explorer context menu for a specific file?
I'm writing a extension for vscode. 我正在为vscode编写扩展。 I just want my context menu just show on when I right click on my file (ex: my_special_name_1.py
). 我只希望右键单击文件时显示上下文菜单(例如: my_special_name_1.py
)。 So I added this contribution point to package.json
: 因此,我将此贡献点添加到package.json
:
"contributes": {
...,
"commands": [
{
"command": "command.hello",
"title": "Hello my file"
},
...
],
"menus": {
"explorer/context": [
{
"when": "resourceLangId == python",
"command": "command.hello"
}
]
},
...
}
But this will show my command "Hello my file" on all .py
files. 但这将在所有.py
文件中显示我的命令“ Hello my file”。 How to let it just be shown only on my files (ex: my_special_name_1.py
, my_special_name_2.py
, ...)? 如何让它仅显示在我的文件中(例如: my_special_name_1.py
, my_special_name_2.py
,...)? Thanks! 谢谢!
You can match the file name against a regex by using the =~
operator: 您可以使用=~
运算符将文件名与正则表达式匹配:
{
"when": "resourceLangId == python && resourceFilename =~ /my_special_name_[0-9]+\\.py/",
"command": "command.hello"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.