Sublime Forum

Turn LSP on/off with keyboard shortcut

#1

I have stared using LSP-s for python. I have installed: LSP, LSP-pyright, LPS-file-watcher-chokidar and LSP-json. It’s all running with no issues.

I would like to set up a shortcut key that will automatically turn LSP server on/off. I have bound lsp_enable_language_server_globally to f10, but it requires one more window:

image

I’m trtying to add argument, but can’t figure our what to put instead of key:

{
“keys”: [“f10”], “command”: “lsp_enable_language_server_globally”, “args”: {“key”: “LSP-pyright”}
},

0 Likes

#2

This is not possible at the moment because the quick panel is hardcoded in the run method of these commands.

Could you explain why or how exactly you would use this? I’m asking because many servers need to read and index all the relevant files in the workspace in the background after starting (in the case of Pyright, LSP-json on the other hand probably doesn’t need that because JSON files are typically standalone files). So there would likely be significant overhead / performance drawbacks from starting and stopping servers often.

Some features (code lenses, inlay hints and hover popups) can already be toggled dynamically per window from the View main menu or command palette and there are corresponding commands that can be bound to a key. If the same would be useful for other features too, we could think about adding more such toggle options.

If you really still need a key binding for enabling/disabling the language servers, could you please open an issue in the LSP repo on GitHub? It shouldn’t be too difficult to modifiy the commands to use InputHandlers instead of show_quick_panel, which would then allow to pass a config name as an argument directly (personally I perfer using InputHandlers anyway).

1 Like

#3

It would be nice to have this as a option. I will check it on the repo as you said.

0 Likes