I am building a VSCode-Extension
and I managed to call my function
via 'right-click' on the files.
This is my package.json
:
"main": "./extension.js",
"contributes": {
"commands": [{
"command": "flutter-localization-generator.create",
"title": "localize_it: create"
}],
"menus": {
"explorer/context": [{
"command": "flutter-localization-generator.create"
}]
}
The thing is that I need the URI
from where the user clicked on the method
. Is that possible? How do I access it inside the activate
?
function activate(context) {
console.log('Congratulations, your extension "flutter-localization-generator" is now active!');
let disposable = vscode.commands.registerCommand('flutter-localization-generator.create', function () {
console.log(context.globalStorageUri);
console.log(context.extensionUri);
console.log(context.extensionPath);
console.log(context.rootPath);
});
context.subscriptions.push(disposable);
}
I tried different of things but all of the above logs
do not get me the desired path
.
CodePudding user response:
Which file or files were selected and right-clicked will be passed to your context menu command, see more at https://stackoverflow.com/a/70307717/836330.
Add args
(any name you want) to your command callback - the information you want will automatically be passed as arguments there.
let disposable = vscode.commands.registerCommand('flutter-localization-generator.create', function (...args) {
Then args
will be an array containing in [0]
the file that was right-clicked on, and in [1]
all the files that might have been selected when one of them was right-clicked and your context menu function selected and run.