Skip to content

Implement InvokeRegisteredEditorCommand #919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 23, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/features/ExtensionCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,14 @@ export interface StatusBarMessageDetails {
message: string;
timeout?: number;
}
interface InvokeRegisteredEditorCommandParameter{
commandName : string
}

export class ExtensionCommandsFeature implements IFeature {

private command: vscode.Disposable;
private command2: vscode.Disposable;
private languageClient: LanguageClient;
private extensionCommands: ExtensionCommand[] = [];

Expand All @@ -191,6 +195,21 @@ export class ExtensionCommandsFeature implements IFeature {

this.showExtensionCommands(this.languageClient);
});
this.command2 = vscode.commands.registerCommand('PowerShell.InvokeRegisteredEditorCommand',(param : InvokeRegisteredEditorCommandParameter) => {
if(this.extensionCommands.length == 0){
return;
}

let commandToExecute = this.extensionCommands.find(x => x.name === param.commandName);

if(commandToExecute){
this.languageClient.sendRequest(
InvokeExtensionCommandRequest.type,
{ name: commandToExecute.name,
context: this.getEditorContext() });
}
});

}

public setLanguageClient(languageclient: LanguageClient) {
Expand Down Expand Up @@ -248,6 +267,7 @@ export class ExtensionCommandsFeature implements IFeature {

public dispose() {
this.command.dispose();
this.command2.dispose();
}

private addExtensionCommand(command: ExtensionCommandAddedNotificationBody) {
Expand Down