繁体   English   中英

当用户在资源管理器/上下文中右键单击文件时,如何在vscode扩展中获取文件名或路径?

[英]How to get file name or path in vscode extension when user right click on file in explorer/context?

我的扩展在资源管理器树中创建了一个上下文菜单:

"contributes": {
        "commands": [
            ...
            {
                "command": "myextension.mycommand",
                "title": "Run my command"
            }
        ],
        "menus": {
            "explorer/context": [{
                "when": "resourceLangId == python",
                "command": "myextension.mycommand",
                "group": "MyGroup"
          }]
        }
    }

extension.ts

export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.commands.registerCommand('myextension.mycommand', () => {
    //How to get the filename or file path here?
}));

我想获取文件的文件名或文件路径我在运行我的命令时右键单击上下文菜单。 你能告诉我怎么样吗? 非常感谢你!

回调函数将接收vscode.Uri对象的参数:

vscode.commands.registerCommand('myextension.mycommand', (uri:vscode.Uri) => {
    console.log(uri.fsPath);
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM