我正在为vscode编写扩展。我只希望右键单击文件(例如:my_special_name_1.py
)时显示上下文菜单。因此,我将此贡献点添加到package.json
:
"contributes": {
...,
"commands": [
{
"command": "command.hello",
"title": "Hello my file"
},
...
],
"menus": {
"explorer/context": [
{
"when": "resourceLangId == python",
"command": "command.hello"
}
]
},
...
}
但这将在所有.py
文件上显示我的命令“ Hello my file”。如何让它仅显示在我的文件中(例如:my_special_name_1.py
,my_special_name_2.py
,...)?谢谢!
答案 0 :(得分:3)
您可以使用=~
运算符将文件名与正则表达式进行匹配:
{
"when": "resourceLangId == python && resourceFilename =~ /my_special_name_[0-9]+\\.py/",
"command": "command.hello"
}