diff options
| author | Gregory Anders <8965202+gpanders@users.noreply.github.com> | 2024-04-26 11:12:49 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-26 11:12:49 -0500 |
| commit | 688860741589b4583129e426f4df0523f9213275 (patch) | |
| tree | 68d68a6b1060f028a34317f0867017d6cb94e674 /runtime/doc | |
| parent | 9b028bd64f4260a3a5576a3632f95a44bd658615 (diff) | |
| download | rneovim-688860741589b4583129e426f4df0523f9213275.tar.gz rneovim-688860741589b4583129e426f4df0523f9213275.tar.bz2 rneovim-688860741589b4583129e426f4df0523f9213275.zip | |
feat(lsp): add more LSP defaults (#28500)
- crn for rename
- crr for code actions
- gr for references
- <C-S> (in Insert mode) for signature help
Diffstat (limited to 'runtime/doc')
| -rw-r--r-- | runtime/doc/change.txt | 4 | ||||
| -rw-r--r-- | runtime/doc/lsp.txt | 42 | ||||
| -rw-r--r-- | runtime/doc/news.txt | 11 | ||||
| -rw-r--r-- | runtime/doc/vim_diff.txt | 4 |
4 files changed, 34 insertions, 27 deletions
diff --git a/runtime/doc/change.txt b/runtime/doc/change.txt index 6d3efb4167..0f362c0cd4 100644 --- a/runtime/doc/change.txt +++ b/runtime/doc/change.txt @@ -281,6 +281,10 @@ gr{char} Replace the virtual characters under the cursor with that have a special meaning in Insert mode, such as most CTRL-keys, cannot be used. + *gr-default* + Mapped to |vim.lsp.buf.references()| by default. + |default-mappings| + *digraph-arg* The argument for Normal mode commands like |r| and |t| is a single character. When 'cpo' doesn't contain the 'D' flag, this character can also be entered diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt index a0d0b75407..b3f60ed41f 100644 --- a/runtime/doc/lsp.txt +++ b/runtime/doc/lsp.txt @@ -61,47 +61,41 @@ options are not restored when the LSP client is stopped or detached. - |K| is mapped to |vim.lsp.buf.hover()| unless |'keywordprg'| is customized or a custom keymap for `K` exists. + *crr* *v_crr* *crn* *i_CTRL-S* +Some keymaps are created unconditionally when Nvim starts: +- "crn" is mapped in Normal mode to |vim.lsp.buf.rename()| +- "crr" is mapped in Normal and Visual mode to |vim.lsp.buf.code_action()| +- "gr" is mapped in Normal mode to |vim.lsp.buf.references()| |gr-default| +- CTRL-S is mapped in Insert mode to |vim.lsp.buf.signature_help()| + +If not wanted, these keymaps can be removed at any time using +|vim.keymap.del()| or |:unmap|. + *lsp-defaults-disable* To override the above defaults, set or unset the options on |LspAttach|: >lua + vim.api.nvim_create_autocmd('LspAttach', { callback = function(ev) vim.bo[ev.buf].formatexpr = nil vim.bo[ev.buf].omnifunc = nil - vim.keymap.del("n", "K", { buffer = ev.buf }) + vim.keymap.del('n', 'K', { buffer = ev.buf }) end, }) -To use other LSP features like hover, rename, etc. you can set other keymaps -on |LspAttach|. Example: >lua - vim.api.nvim_create_autocmd('LspAttach', { - callback = function(args) - vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = args.buf }) - end, - }) - -The most common functions are: - -- |vim.lsp.buf.hover()| -- |vim.lsp.buf.format()| -- |vim.lsp.buf.references()| -- |vim.lsp.buf.implementation()| -- |vim.lsp.buf.code_action()| +To use other LSP features, set keymaps on |LspAttach|. Not all language +servers provide the same capabilities. To ensure you only set keymaps if the +language server supports a feature, guard keymaps behind capability checks. +Example: >lua - -Not all language servers provide the same capabilities. To ensure you only set -keymaps if the language server supports a feature, you can guard the keymap -calls behind capability checks: ->lua vim.api.nvim_create_autocmd('LspAttach', { callback = function(args) local client = vim.lsp.get_client_by_id(args.data.client_id) - if client.server_capabilities.hoverProvider then - vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = args.buf }) + if client.supports_method('textDocument/implementation') then + vim.keymap.set('n', 'g<C-I>', vim.lsp.buf.implementation, { buffer = args.buf }) end end, }) < - To learn what capabilities are available you can run the following command in a buffer with a started LSP client: >vim diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index 5881d90358..edf0b8fb7c 100644 --- a/runtime/doc/news.txt +++ b/runtime/doc/news.txt @@ -408,6 +408,10 @@ The following changes to existing APIs or features add new behavior. • 'comments' includes "fb:•". • 'shortmess' includes the "C" flag. • 'grepprg' defaults to using ripgrep if available. + • |crn| in Normal mode maps to |vim.lsp.buf.rename()|. + • |crr| in Normal and Visual mode maps to |vim.lsp.buf.code_action()|. + • "gr" in Normal mode maps to |vim.lsp.buf.references()| |gr-default| + • |i_CTRL-S| in Insert mode maps to |vim.lsp.buf.signature_help()| • Automatic linting of treesitter query files (see |ft-query-plugin|). Can be disabled via: >lua vim.g.query_lint_on = {} @@ -438,9 +442,10 @@ The following changes to existing APIs or features add new behavior. :call netrw#BrowseX(expand(exists("g:netrw_gx")? g:netrw_gx : '<cfile>'), netrw#CheckIfRemote())<CR> -• |vim.lsp.start()| now maps |K| to use |vim.lsp.buf.hover()| if the server - supports it, unless |'keywordprg'| was customized before calling - |vim.lsp.start()|. +• |vim.lsp.start()| now creates the following default keymaps (assuming the + server supports the feature): + - |K| in Normal mode maps to |vim.lsp.buf.hover()|, unless |'keywordprg'| + was customized before calling |vim.lsp.start()|. • Terminal buffers started with no arguments (and use 'shell') close automatically if the job exited without error, eliminating the (often diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index d426f8151f..c767c71523 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -137,6 +137,10 @@ of these in your config by simply removing the mapping, e.g. ":unmap Y". - * |v_star-default| - gc |gc-default| |v_gc-default| |o_gc-default| - gcc |gcc-default| +- |crn| +- |crr| +- gr |gr-default| +- <C-S> |i_CTRL-S| - Nvim LSP client defaults |lsp-defaults| - K |K-lsp-default| |