vscode 扩展可以为特定文件创建资源管理器上下文菜单吗? [英] Can a vscode extension create an explorer context menu for a specific file?

查看:43
本文介绍了vscode 扩展可以为特定文件创建资源管理器上下文菜单吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 vscode 编写一个扩展.我只想在我右键单击我的文件时显示我的上下文菜单(例如:my_special_name_1.py).所以我在 package.json 中添加了这个贡献点:

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"
                    }
                ]
            },
    ...
}

但这将在所有 .py 文件上显示我的命令Hello my file".如何让它只显示在我的文件上(例如:my_special_name_1.pymy_special_name_2.py、...)?谢谢!

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

这篇关于vscode 扩展可以为特定文件创建资源管理器上下文菜单吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆