当用户右键单击 explorer/context 中的文件时,如何在 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);
});
我的扩展程序在资源管理器树中创建了一个上下文菜单:
"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);
});