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

10
我的扩展程序在资源管理器树中创建了一个上下文菜单:
"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?
}));

当我运行命令时,我想要获取右键上下文菜单中所点击文件的文件名或文件路径。你能告诉我如何做吗?非常感谢!


如何创建一组命令 - ihappyk
1个回答

17

回调函数将接收一个带有vscode.Uri对象的参数:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接