I'm writing a extension for vscode. I just want my context menu just show on when I right click on my file (ex: my_special_name_1.py
). So I added this contribution point to 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. How to let it just be shown only on my files (ex: 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"
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.