Open bitwes opened 4 years ago
I was able to create a "non-user" command and kick it off in another command.
public activate() {
const command = 'myExtension.sayHello';
const commandHandler = (name: string = 'world') => {
console.log(`Hello ${name}!!!`);
};
this.context.subscriptions.push(vscode.commands.registerCommand(command, commandHandler));
}
This command won't show up in the command palette but is available to be used in other methods. I called it from within my own plugin but I was able to kick off a godot-tool command with: vscode.commands.executeCommand('godot-tool.open_editor');
. So it should be usable by anything.
vscode.commands.executeCommand('myExtension.sayHello');
vscode.commands.executeCommand('myExtension.sayHello', 'buddy');
I don't know if palette methods can take optional parameters, so maybe it wouldn't have to be a "non . user" command.
I think I'm going to start working on this. My approach will be to wrap private run_editor(params = "")
with a command and try to leverage that in my plugin. I knew as . soon . as . I asked . I would . get more curious and . start . digging . deeper. (please excuse all . the . "." in this last part, my mac keyboard is adding e xtra . spaces and I've . grown too aggravated with backspacing).
EDIT reference links: https://code.visualstudio.com/api/extension-guides/command https://stackoverflow.com/questions/41559471/is-it-possible-to-call-commands-between-extensions-in-vscode/46001467#46001467
Got it working! I was able to add the godot-tool.run_godot
command, deploy it locally, then use it in my plugin to launch Godot to run GUT.
This is the first TypeScript
that I've done and I'm not super up on Promises
in general. Both of these implementations work but I'm not sure which is more right. Also I'm not sure if I should be doing something with the returned Promise
in my code if that is how it should work.
const command = 'godot-tool.run_godot';
const commandHandler = (params: string = '') => {
this.run_editor(params)
};
this.context.subscriptions.push(vscode.commands.registerCommand(command, commandHandler));
or with a Promise
const command = 'godot-tool.run_godot';
const commandHandler = (params: string = '') => {
return new Promise((resolve, reject) => {
this.run_editor(params).then(()=>resolve()).catch(err=>{
reject(err);
});
});
};
this.context.subscriptions.push(vscode.commands.registerCommand(command, commandHandler));
In my plugin I just do:
vscode.commands.executeCommand('godot-tool.run_godot', opts);
If you let me know the right way then I will tidy things up and make the PR.
Thanks for making this plugin, I'm brand new to making VSCode plugins and it has been very useful . as a reference. I've started creating a plugin for the GUT unit testing framework. Would it be possible to use your methods in my own plugin? Right now I've got everything working but it is pretty much hardcoded to work on Macs. I'm using the godot-vscode-plugin property for the path to Godot but I would rather not have to duplicate all the work you've already done for multi-platform support. I could just copy your code but that isn't elegant and I have to test it on all the different platforms. I'd much rather just require this plugin instead.
If this is possible then I'm more than willing to help implement the solution. I'm just not that versed in the best practices with these plugins. Here's my extension for reference, it's still very early in development.
https://github.com/bitwes/gut-extension/tree/master