You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've created an extension which automatically brings imports when you copy and paste between files. However, in order to do this I had to override the default cut/copy/paste hotkeys.
In each of my commands I call the default editor.action.clipboard*Action and then do the things specific to my plugin. Here's the relevant snippet:
However, sometimes vscode doesn't call extension commands, which makes my extension break copy/paste.
I would like to either be able respond to the built in commands rather than overriding the hotkeys, or allow the default hotkey to run if vscode decides to skip my extension defined command.
I don't know under which circumstances vscode doesn't run commands defined in extensions, sometimes it seems to be random and if I reload the window it starts to work again.
One place I've found it to be very reproducible is when you open very large documents. Even if you do ctrl+a and then delete, the hotkeys that should be running commands defined in extensions don't work.
open it in vscode and none of the hotkeys that I have hooked up to extensions work. With copy with imports installed I cannot copy/paste with this file, and with Cursor move installed, ctrl+left, ctrl+right do not move the cursor.
I've defined a hotkey to call my extension's version of copy/paste when you do ctrl+c/ctrl+v but since my extension commands aren't called, and I've overridden the default hotkey, nothing happens when those hotkeys are pressed.
So that makes my extension sometimes completely break copy/paste. This is a very poor experience and I'd like some kind of work around.
The ideas I can think of are either:
let me subscribe to when copy/cut/paste happen so I can enhance those features with my extension but not override the default hotkeys.
Have some way to conditionally override hotkeys. If vscode decides not to give my extension access to the file then fallback to the default hotkey. This would probably need to be opt-in when registering the command, give the fallback built in command to call when the extension is disabled by vscode.
Right, so I can do that to figure out which my the extensions I am running may be using the compute power. But this isn't a reasonable workaround for my extension to perform properly for other people.
There ought to be a way for my extension to have a degraded condition where it still allows basic editing abilities (copy/paste) even when other extensions are going crazy.
There ought to be a way for my extension to have a degraded condition where it still allows basic editing
Yeah, the unfortunate reality of JavaScript. What we can do is detect that a command wanted to run but that the request never made it over the wire. We can then show a message and our assumption is that such a case is rare. What we cannot do is run another command because it is hard for us to figure-out what other command is appropriate
So I'm proposing a couple of options that would make my use case work:
add an API like vscode.workspace.onBeforeCommand(commandName, handler) and vscode.workspace.onAfterCommand(commandName, handler) where I could respond to the built in command running. Then I don't have to override the default hotkeys. This is probably the ideal solution.
when I register a command, I could supply a fallback built in command to run in the case that vscode fails to call my extension (whether because the file is too big or another extension is using too much cpu.)
Do you think either of these would work?
Reacted by Shepelev Stas, Nate Bross and Andrew Head
Option №1 makes more sense, I would want it too! I also made an extension that overrides the native copy and cut commands. That means I can not use any other extension that is intended to work on copy and cut commands execution. Attaching a handler to native command instead of overriding it would solve the problem.
Thanks for creating this issue! We figured it's covering the same as another one we already have. Thus, we closed this one as a duplicate. You can search for existing issues here. See also our issue reporting guidelines.
Activity
jrieken commentedon Feb 27, 2018
Can you specify that?
stringham commentedon Feb 27, 2018
I don't know under which circumstances vscode doesn't run commands defined in extensions, sometimes it seems to be random and if I reload the window it starts to work again.
One place I've found it to be very reproducible is when you open very large documents. Even if you do
ctrl+aand then delete, the hotkeys that should be running commands defined in extensions don't work.For example, download and uncompress this file:
large-file.json.gz
open it in vscode and none of the hotkeys that I have hooked up to extensions work. With copy with imports installed I cannot copy/paste with this file, and with Cursor move installed,
ctrl+left,ctrl+rightdo not move the cursor.jrieken commentedon Feb 28, 2018
Yeah, that's the designed behaviour because for performance reasons we don't let extensions know about very large documents.
When you say that do you mean nothing happens or that the extension behaviour doesn't happen?
stringham commentedon Feb 28, 2018
I've defined a hotkey to call my extension's version of copy/paste when you do
ctrl+c/ctrl+vbut since my extension commands aren't called, and I've overridden the default hotkey, nothing happens when those hotkeys are pressed.So that makes my extension sometimes completely break copy/paste. This is a very poor experience and I'd like some kind of work around.
The ideas I can think of are either:
let me subscribe to when copy/cut/paste happen so I can enhance those features with my extension but not override the default hotkeys.
Have some way to conditionally override hotkeys. If vscode decides not to give my extension access to the file then fallback to the default hotkey. This would probably need to be opt-in when registering the command, give the fallback built in command to call when the extension is disabled by vscode.
jrieken commentedon Feb 28, 2018
Ok, when dealing with large documents (>50MB) that's a known limitation. Are there other scenarios you know when your command should run but doesn't?
stringham commentedon Feb 28, 2018
It happens periodically, it seems to be when the vscode process is using high CPU. However, I haven't been able to consistently reproduce it.
Copy/paste will break, I'll reload vscode and it will work again.
jrieken commentedon Feb 28, 2018
Likely when an extension goes crazy and taking away all compute from other extensions. When that happens, please profile running extensions. Do so by pressing F1 > Running Extensions > Hit the Red button: https://github.com/Microsoft/vscode/wiki/Performance-Issues#profile-the-running-extensions
stringham commentedon Feb 28, 2018
Right, so I can do that to figure out which my the extensions I am running may be using the compute power. But this isn't a reasonable workaround for my extension to perform properly for other people.
There ought to be a way for my extension to have a degraded condition where it still allows basic editing abilities (copy/paste) even when other extensions are going crazy.
Thoughts?
jrieken commentedon Mar 1, 2018
Yeah, the unfortunate reality of JavaScript. What we can do is detect that a command wanted to run but that the request never made it over the wire. We can then show a message and our assumption is that such a case is rare. What we cannot do is run another command because it is hard for us to figure-out what other command is appropriate
stringham commentedon Mar 2, 2018
So I'm proposing a couple of options that would make my use case work:
add an API like
vscode.workspace.onBeforeCommand(commandName, handler)andvscode.workspace.onAfterCommand(commandName, handler)where I could respond to the built in command running. Then I don't have to override the default hotkeys. This is probably the ideal solution.when I register a command, I could supply a fallback built in command to run in the case that vscode fails to call my extension (whether because the file is too big or another extension is using too much cpu.)
Do you think either of these would work?
DanTup commentedon Mar 12, 2018
I requested the same thing in #30066. My analysis server can bring imports with copy/pastes but currently I can't participate in the actions :(
Overriding hotkeys doesn't seem like a good solution since users can change them.
shepelevstas commentedon Apr 7, 2018
Option №1 makes more sense, I would want it too! I also made an extension that overrides the native copy and cut commands. That means I can not use any other extension that is intended to work on copy and cut commands execution. Attaching a handler to native command instead of overriding it would solve the problem.
jrieken commentedon Jul 23, 2019
/duplicate of #30066
vscodebot commentedon Jul 23, 2019
Thanks for creating this issue! We figured it's covering the same as another one we already have. Thus, we closed this one as a duplicate. You can search for existing issues here. See also our issue reporting guidelines.
Happy Coding!