LSP
LSP copied to clipboard
Override built-in commands, instead of asking users to set up keybindings
The plugin is stabilizing with respect to its featureset, and perhaps the time has come to override the built-in commands, instead of asking users to set up keybindings.
For example, we can have an on_text_command + on_window_command callback that replaces various commands:
| ST command | LSP replacement | Requirements |
|---|---|---|
goto_definition |
lsp_symbol_definition |
definitionProvider |
goto_reference |
lsp_symbol_references |
referencesProvider |
show_overlay {"overlay": "goto", "text": "@"} |
lsp_document_symbols |
documentSymbolProvider |
expand_selection {"to": "smart" or "tag"} |
lsp_expand_selection |
selectionRangeProvider |
goto_symbol_in_project |
lsp_workspace_symbols |
workspaceSymbolProvider |
| N/A | lsp_symbol_type_definition |
typeDefinitionProvider |
| N/A | lsp_symbol_declaration |
declarationProvider |
| N/A | lsp_symbol_implementation |
implementationProvider |
| N/A | lsp_symbol_rename |
renameProvider |
reindent {"single_line": false} |
lsp_format_document |
documentFormattingProvider |
reindent {"single_line": true} (???) |
lsp_format_document_range |
rangeFormattingProvider |
| N/A | lsp_code_actions |
codeActionProvider |
paste_and_indent |
#1094 | rangeFormattingProvider |
(I've added all of our commands, even ones for which I couldn't immediately think of an ST-equivalent, feel free to suggest ST-equivalents)
The advantage to this is that it doesn't matter what the user has set up as his/her keybindings for the built-in commands.
One disadvantage is that a language server's capability for providing the feature may actually be worse than ST's. To overcome this, I would propose making the disabled_capabilities setting a per-server setting, instead of it now being a global setting that applies to all language server.
lsp_format_document is "reindent", "args": {"single_line": false},
(I know the scope of lsp_format_document is larger, e.g. adding spacing inside brackets, but I look at it this way: if I have access to lsp_format_document I never need to use reindent and therefore I have bound them to the same keybinding, overriding as you suggest should be the default behaviour.)
Where is "reindent" {"single_file": false} in the menu?
I managed to find "reindent {"single_line": true} in Edit > Line > Reindent, but I cannot find the "single_line": false one.
There's also a bare "reindent" in the default keybindings, without arguments:
{ "keys": ["tab"], "command": "reindent", "context":
[
{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "regex_match", "operand": "^$", "match_all": true },
{ "key": "following_text", "operator": "regex_match", "operand": "^$", "match_all": true }
]
},
There's also Edit > Paste And Indent (paste_and_indent) which we can probably rewrite to a new lsp_paste_and_format (#1094).
I think we should first check with the sublime text community if it ok if a plugin should override the default keybinding even if we override them only in certain circumstances(if we have a server has the given *Provider capability). We can discuss it on discord with Will Bond and the others.
I have mixed feeling about this one.
I think that it would be a better user experience if we override the defaults as I saw people reporting problems of lsp features not working. Like for example goto definition, or ctrl+r (to show symbol list in a document), because the haven't probably assigned the keybindings. Here is one example of that. https://forum.sublimetext.com/t/anyone-using-sublime-text-to-edit-typescript-code/51741?u=predragnikolic
Here are a few exceptions on why I don't think it would be ok to override the defaults.
- There are certain features that I think sublime does better than lsp,
- For me the
goto_symbol_in_projectmore intuitive thanlsp_workspace_symbols(because we can not re-query the server as we type in the ListInputHandler) - And I prefer sublime default ctrl+r(show symbols in document) than
lsp_document_symbols. (because the sublime command will show me the symbols instantly, while I notice a small delay when I triggerlsp_document_symbols, it's not a big delay, but I notice it). For this case I really prefer sublime fastness.
- What if multiple plugins want to override the sublime default commands? LSP is not the only plugin out there :)
Again, like I said I have mixed feeling, I don't know what feels right in this case.
One disadvantage is that a language server's capability for providing the feature may actually be worse than ST's. To overcome this, I would propose making the disabled_capabilities setting a per-server setting, instead of it now being a global setting that applies to all language server.
Although I see the benefit of having disabled capabilities on a per server basis, I would not add this code unless we conclude that it is really necessary. At the end I really would like to just keep writing less code. Code that doesn't exist is more maintainable, than code that does exist :)