## make lsp server run automatically An LSP server is usually started when a file it should handle is opened, normally known from its extension. By using the `lsp` command, it's possible to automatically start an LSP server like that. For each LSP server you wish to register, add this to one of your config files: ``` lsp "lsp-server-command" "**/*.ext" ``` Where `"**/*.ext"` is a glob pattern that, when matched against a buffer just opened, will invoke the LSP server using `"lsp-server-command"`. In this case, whenever we open a buffer with the extension `.ext`. If you need to inspect/debug the protocol messages, they are logged to the editor log which you can open with the `open-log` command. ### Example of LSP server configurations ``` # rust-analyzer (rust) lsp rust-analyzer "**/*.rs" # clangd (c/cpp) lsp "clangd --offset-encoding=utf-8" "**/*.{c,cpp,h,hpp}" # omnisharp (c#) lsp "omnisharp -lsp --encoding utf-8" "**/*.cs" # zls (zig) lsp zls "**/*.zig" ``` ## bindings | binding | expands to | action | | --- | --- | --- | | `K` | `: lsp-hover` | display hover information (requires a running lsp server) | | `gd` | `: lsp-definition` | jumps to where the symbol under the cursor is defined (requires a running lsp server) | | `gr` | `: lsp-references -context=2` | lists all references of the symbol under the cursor with 2 lines of context (requires a running lsp server) | | `gs` | `: lsp-document-symbols` | lists all symbols in the buffer (requires a running lsp server) | | `rr` | `: lsp-rename` | rename the symbol under the cursor (requires a running lsp server) | | `ra` | `: lsp-code-action` | suggests possible refactors for the region under the cursor (requires a running lsp server) | | `rf` | `: lsp-format` | auto-format the buffer's content (requires a running lsp server) | ## commands ### `lsp` Automatically starts a lsp server (by running ``) when a buffer matching a glob `` is opened. The lsp command only runs if the server is not already running. - usage: `lsp ` ### `lsp-start` Manually starts a lsp server (by running ``). - usage: `lsp-start ` ### `lsp-stop` Stops the lsp server associated with the current buffer. - usage: `lsp-stop` ### `lsp-stop-all` Stops all lsp servers. usage: `lsp-stop-all` ### `lsp-hover` Displays lsp hover information for the item under the main cursor. - usage: `lsp-hover` ### `lsp-definition` Jumps to the location of the definition of the item under the main cursor. - usage: `lsp-definition` ### `lsp-declaration` Jumps to the location of the declaration of the item under the main cursor. - usage: `lsp-declaration` ### `lsp-implementation` Jumps to the location of the implementation of the item under the main cursor. - usage: `lsp-implementation` ### `lsp-references` Opens up a buffer with all references of the item under the main cursor. Optionally overrides the `` (default is `2`). That is: how many lines above and under each reference to show. - usage: `lsp-references []` ### `lsp-rename` Renames the item under the main cursor. - usage: `lsp-rename` ### `lsp-code-action` Lists and then performs a code action based on the main cursor context. - usage: `lsp-code-action` ### `lsp-document-symbols` Pick and jump to a symbol in the current buffer listed by the lsp server. - usage: `lsp-document-symbols` ### `lsp-workspace-symbols` Opens up a buffer with all symbols in the workspace found by the lsp server. Optionally pre-filters results with a ``. - usage: `lsp-workspace-symbols []` ### `lsp-format` Format the whole buffer. - usage: `lsp-format`