ChatGPT解决这个技术问题 Extra ChatGPT

How to open the lightbulb via shortcut?

Some languages support code actions which display a lightbulb providing quick fixes for a warning/error (See https://code.visualstudio.com/docs/editor/editingevolved#_code-action for more information). I like this feature but I don't like to click on the lightbulb. Unfortunately I can't find a shortcut for opening the lightbulb at the current cursor position. How can I create such a shortcut?

I tried to create a shortcut for vscode.executeCodeActionProvider by creating a custom keybinding like this:

[{ "key": "alt+enter", "command": "vscode.executeCodeActionProvider"}]

But everytime I hit the shortcut I receive the warning

Running the contributed command:'vscode.executeCodeActionProvider' failed.


M
Mwiza

The correct command editor.action.quickFix. The default binding on Windows looks like this:

{ "key": "ctrl+.", "command": "editor.action.quickFix",
                   "when": "editorTextFocus" }

On Mac it's CMD + ..


Is this documented somewhere?
D
Drew Noakes

If you're a JetBrains junkie and can't imagine not hammering on Alt+Enter all day long, then you can re-map the default (Ctrl+.) easily enough.

Open the File menu and select Preferences then Keyboard Shortcuts.

Type editor.action.quickFix into the search box:

https://i.stack.imgur.com/vZJPs.png

Click the pen icon, or right-click and select Change Keybinding.

Enter your preferred shortcut into the dialog that appears, then press Enter.

https://i.stack.imgur.com/yfvqC.png

You should end up with something that looks like:

https://i.stack.imgur.com/YpKNJ.png


Great. exactly what I was looking for. After adding auto TS import, this is a really important milestone for vscode competing with webstorm/intellij in terms of js/ts ide. Thanks for sharing!
What do you mean with "not hammering on Alt+Enter all day long", is alt+enter the default to show quick fix?
@Timo in JetBrains products, Alt+Enter is a shortcut that invokes a lot of actions.