-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
Support onDidExecuteCommand #1431
Comments
This is currently supported by calling this method: vscode.commands.getCommands(filterInternal?: boolean): Thenable<string[]>; Does this unblock you? |
Not quite. From what I can tell in the docs, this function will return a list of commands. What I want is to listen to commands as they happen. My specific use case is:
|
Got it, this is currently not supported. |
I would also like to see this feature. I am writing an extension that needs to monitor cursor movements and make slight cursor position adjustments on occasion. The only way I've found to do this is to override the keybinding for e.g. 'left', call 'cursorLeft' from my command, and then validate the cursor's position. Even without validation, intercepting 'left' and then immediately calling 'cursorLeft' from an extension causes the UI to be much less responsive than binding directly 'left' to 'cursorLeft'. (Because extensions are given low priority.) |
@johnfn for the VIM extension do you need |
@jrieken I assume this is for tab complete? If so, post-trigger would be the most useful. |
@jrieken we will benefit a lot with // Remove words which are wrong. |
@jrieken A common user case is like:
Since the only user does is pressing So if we can bind handlers to |
@rebornix I am not convinced that "spying" on commands will help you in any meaningful way. For example, in the example you make, where a user types But IMHO this does not help you to repeat the action, as the command Perhaps |
@alexandrudima Thanks for your input. I agree that
|
@rebornix My question stands: "Perhaps There are a lot of commands in VSCode out of the box and even more from extensions. Types of commands that I can think of:
There are also edits to the document that don't stem from a command (e.g. format on type) The commands are not categorized statically in any meaningful way. They execute and they do something. Sometimes, that results in a document edit (that can be observed via Also note the Is it possible to point me to an example/explanation of how |
The big thing we need is the ability to know that an action such as tab complete or snippet insert or any other sort of text change has taken place. If you guys can't figure out exactly how to let us repeat it, that's okay; we can just manually diff the document and figure out what happened (most of the time). Quick explanation for .: The idea is that it allows you to repeat an action somewhere else in the document. So if you inserted some text on the first line, then navigated to the last line, . would add the text down there. If you tab-completed a word on the first line and hit . on the last line, it'd insert the full word. etc, etc. |
Isn't that an argument for the |
@jrieken 👍 However, the source is currently a string (not an enum) and at least for edits coming from the extension host the source is set to |
As long as the strings being sort well defined we can do something like this |
Most (not sure if all) should be named |
Pushed up my work and opened up a RFC/WIP PR of what I came up with. Interesting enough, none of the internal commands actually go through the event emitter in the command service, so they don't surface on the extension side. I verified that internal commands were firing, just not through the emitters. Interested if there are any performance implications with talking between the two processes like this. Possible enhancement would be to allow a glob/regex/array of strings/wildcard as the first param that would act as a filter for what events surface to the extension. |
This PR is merged but there is some little (design) work left
|
Closing this for July testing |
This seems to work well, but I'm seeing the event get triggered twice when running this hello world command: export function activate(context: vscode.ExtensionContext) {
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "helloworld-sample" is now active!');
// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
const disposables: vscode.Disposable[] = [];
disposables.push(vscode.commands.registerCommand('extension.helloWorld', () => {
// The code you place here will be executed every time your command is executed
// Display a message box to the user
vscode.window.showInformationMessage('Hello World!');
}));
disposables.push(vscode.commands.onDidExecuteCommand((e: vscode.CommandExecutionEvent) => {
console.log(e.command);
}));
context.subscriptions.push(...disposables);
} The command isn't actually running twice, but the listener for Bug: #78274 |
We have decided against this API: #78091 (comment) |
I am building an extension for VS Code. My extension will show the key bindings associated to a recently action (I am a fan of this for helping me learn key bindings).
Looking through the documentation there seems to be a way to access the commands in the editor, but no way that I can find to listen for actions / commands as they are invoked.
I would like the ability to listen for all user actions and then react to their actions.
The text was updated successfully, but these errors were encountered: