My extension creates a context menu in the explorer tree:
"contributes": {
"commands": [
...
{
"command": "myextension.mycommand",
"title": "Run my command"
}
],
"menus": {
"explorer/context": [{
"when": "resourceLangId == python",
"command": "myextension.mycommand",
"group": "MyGroup"
}]
}
}
In 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?
}));
I want to get the filename or file path of the file I've right click on the context menu when run my command. Can you tell me how? Thank you very much!
You can use the Find All References command to find where particular code elements are referenced throughout your codebase. The Find All References command is available on the context (right-click) menu of the element you want to find references to. Or, if you are a keyboard user, press Shift + F12.
The callback will receive an argument with a vscode.Uri
object:
vscode.commands.registerCommand('myextension.mycommand', (uri:vscode.Uri) => {
console.log(uri.fsPath);
});
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