Skip to content
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

GH-8413: Execute the command if has active handler #8420

Merged
merged 2 commits into from
Aug 28, 2020
Merged

Conversation

kittaakos
Copy link
Contributor

@kittaakos kittaakos commented Aug 24, 2020

What it does

How to test

  • Reset your workbench layout.
  • Toggle the bottom panel: Ctrl/Cmd+J.
  • Close the Problems view.
  • Toggle the bottom panel: Ctrl/Cmd+J
  • You must not see the error:
root ERROR Failed to execute command: Error: The command 'core.toggle.bottom.panel' cannot be executed. There are no active handlers available for the command. (args: [null])
    at CommandRegistry.<anonymous> (file:///Users/akos.kitta/git/theia/examples/electron/lib/bundle.js:134569:45)
    at step (file:///Users/akos.kitta/git/theia/examples/electron/lib/bundle.js:134338:23)
    at Object.next (file:///Users/akos.kitta/git/theia/examples/electron/lib/bundle.js:134319:53)
    at file:///Users/akos.kitta/git/theia/examples/electron/lib/bundle.js:134313:71
    at new Promise (<anonymous>)
    at ../../packages/core/lib/common/command.js.__awaiter (file:///Users/akos.kitta/git/theia/examples/electron/lib/bundle.js:134309:12)
    at CommandRegistry.../../packages/core/lib/common/command.js.CommandRegistry.executeCommand (file:///Users/akos.kitta/git/theia/examples/electron/lib/bundle.js:134551:16)
    at KeybindingRegistry.../../packages/core/lib/browser/keybinding.js.KeybindingRegistry.executeKeyBinding (file:///Users/akos.kitta/git/theia/examples/electron/lib/bundle.js:111317:38)
    at KeybindingRegistry.../../packages/core/lib/browser/keybinding.js.KeybindingRegistry.run (file:///Users/akos.kitta/git/theia/examples/electron/lib/bundle.js:111409:22)
    at HTMLDocument.<anonymous> (file:///Users/akos.kitta/git/theia/examples/electron/lib/bundle.js:109575:35)
  • Reset your workbench layout.
  • Open one or two editors.
  • Close the editors in the main area: Ctrl/Cmd+K Ctrl/Cmd+W in electron or Alt+Shift+W in browser.
  • Editors are closed.
  • Close the editors in the main area: Ctrl/Cmd+K Ctrl/Cmd+W in electron or Alt+Shift+W in browser.
  • You must not see the errors:
root ERROR Failed to execute command: Error: The command 'core.close.all.tabs' cannot be executed. There are no active handlers available for the command. (args: [null])
    at CommandRegistry.<anonymous> (file:///Users/akos.kitta/git/theia/examples/electron/lib/bundle.js:134569:45)
    at step (file:///Users/akos.kitta/git/theia/examples/electron/lib/bundle.js:134338:23)
    at Object.next (file:///Users/akos.kitta/git/theia/examples/electron/lib/bundle.js:134319:53)
    at file:///Users/akos.kitta/git/theia/examples/electron/lib/bundle.js:134313:71
    at new Promise (<anonymous>)
    at ../../packages/core/lib/common/command.js.__awaiter (file:///Users/akos.kitta/git/theia/examples/electron/lib/bundle.js:134309:12)
    at CommandRegistry.../../packages/core/lib/common/command.js.CommandRegistry.executeCommand (file:///Users/akos.kitta/git/theia/examples/electron/lib/bundle.js:134551:16)
    at KeybindingRegistry.../../packages/core/lib/browser/keybinding.js.KeybindingRegistry.executeKeyBinding (file:///Users/akos.kitta/git/theia/examples/electron/lib/bundle.js:111317:38)
    at KeybindingRegistry.../../packages/core/lib/browser/keybinding.js.KeybindingRegistry.run (file:///Users/akos.kitta/git/theia/examples/electron/lib/bundle.js:111409:22)
    at HTMLDocument.<anonymous> (file:///Users/akos.kitta/git/theia/examples/electron/lib/bundle.js:109575:35)

Review checklist

Reminder for reviewers

Akos Kitta added 2 commits August 24, 2020 11:33
Before executing the command via a keybinding, we check if the command
has an active handler.

Closes #8413.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
@akosyakov
Copy link
Member

akosyakov commented Aug 24, 2020

It breaks lazy activation of VS Code extensions on command. When a command is about to execute it fires onWillExecuteCommand event which gives a chance to participate other clients (like plugin system) and contribute handlers:

await this.fireWillExecuteCommand(commandId, args);

this.commands.onWillExecuteCommand(event => this.ensureCommandHandlerRegistration(event));

Ignore, I will test it. It seems the plugin system contributes fake handler anyway.

@kittaakos
Copy link
Contributor Author

breaks lazy activation of VS Code extensions on command

I did not know this. Any recommendations on how to fix the bug?

@akosyakov
Copy link
Member

I did not know this. Any recommendations on how to fix the bug?

Ignore it. Plugin system contributes the stub handler so it should be fine. Checked with python extension it is good.

if (this.isPseudoCommand(binding.command)) {
/* Don't do anything, let the event propagate. */
} else {
const command = this.commandRegistry.getCommand(binding.command);
if (command) {
this.commandRegistry.executeCommand(binding.command, binding.args)
.catch(e => console.error('Failed to execute command:', e));
if (this.commandRegistry.isEnabled(binding.command, binding.args)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only wonder whether it is a proper place. We have a method isEnabled in this class, which actually used to match keybindings. I am not sure whether it should be moved there? i.e. if keybinding is matching, but there is no active handler, should we skip keybinding and try next? With current proposal we pick keybinding and do nothing. There is also isActive method which is not used anymore. Maybe during refactoring we lost it and the actual fix is to call isActive from isEnabled if keybinding is matching.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is fair reasoning.

With current proposal we pick keybinding and do nothing

Well, with the master state, we pick the keybinding, and we equally do nothing as an error is thrown.

With the proposed change:

  • we do not fire the fireWillExecuteCommand if there are no active handlers. (same on master)
  • we preventDefault and stopPropagation no matter there were any active handlers or not. (same as on master)

The only behavioral change is that we do not throw an error.

Maybe during refactoring we lost it

OK, I will look into the commit history.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, let's try

@akosyakov akosyakov added the keybindings issues related to keybindings label Aug 24, 2020
Copy link
Member

@akosyakov akosyakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems to be minimal change

@vince-fugnitto
Copy link
Member

@kittaakos @akosyakov do we merge for the release?

@kittaakos
Copy link
Contributor Author

@kittaakos @akosyakov do we merge for the release?

No.

@kittaakos kittaakos merged commit ca6754e into master Aug 28, 2020
@kittaakos kittaakos deleted the GH-8413 branch August 28, 2020 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keybindings issues related to keybindings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[shell] Error when toggling the bottom panel with Cltr/Cmd+j when there isn't any views in the bottom panel
3 participants