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"
}

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With