Home Explore Blog CI



neovim

4th chunk of `runtime/doc/lsp.txt`
1c054cc73d917fd578d1d37f0bb280aae371a02d1ba5867f0000000100000fb2
 bufnr = args.buf, id = client.id, timeout_ms = 1000 })
            end,
          })
        end
      end,
    })
<
To see the capabilities for a given server, try this in a LSP-enabled buffer: >vim

    :lua =vim.lsp.get_clients()[1].server_capabilities

================================================================================
FAQ                                                     *lsp-faq*

- Q: How to force-reload LSP?
- A: Stop all clients, then reload the buffer. >vim
     :lua vim.lsp.stop_client(vim.lsp.get_clients())
     :edit

- Q: Why isn't completion working?
- A: In the buffer where you want to use LSP, check that 'omnifunc' is set to
     "v:lua.vim.lsp.omnifunc": `:verbose set omnifunc?`
     - Some other plugin may be overriding the option. To avoid that you could
       set the option in an |after-directory| ftplugin, e.g.
       "after/ftplugin/python.vim".

- Q: How do I run a request synchronously (e.g. for formatting on file save)?
- A: Check if the function has an `async` parameter and set the value to
  false. E.g. code formatting: >vim

     " Auto-format *.rs (rust) files prior to saving them
     " (async = false is the default for format)
     autocmd BufWritePre *.rs lua vim.lsp.buf.format({ async = false })
<
                                                        *lsp-vs-treesitter*
- Q: How do LSP, Treesitter and Ctags compare?
- A: LSP requires a client and language server. The language server uses
     semantic analysis to understand code at a project level. This provides
     language servers with the ability to rename across files, find
     definitions in external libraries and more.

     |treesitter| is a language parsing library that provides excellent tools
     for incrementally parsing text and handling errors. This makes it a great
     fit for editors to understand the contents of the current file for things
     like syntax highlighting, simple goto-definitions, scope analysis and
     more.

     A |ctags|-like program can generate a |tags| file that allows Nvim to
     jump to definitions, provide simple completions via |i_CTRL-X_CTRL-]|
     command. It is not as featureful and doesn't have semantic understanding,
     but it is fast, lightweight and useful for navigating polyglot projects.

================================================================================
LSP API                                                 *lsp-api*

The |lsp-core| API provides core functions for creating and managing clients.
The |lsp-buf| functions perform operations for LSP clients attached to the
current buffer.

                                                                  *lsp-method*
Requests and notifications defined by the LSP specification are referred to as
"LSP methods". These are handled by Lua |lsp-handler| functions.

The |vim.lsp.handlers| global table defines default handlers (only for
server-to-client requests/notifications, not client-to-server). Note: depends
on server support; they won't run if your server doesn't support them.

You can list them with: >vim

    :lua vim.print(vim.tbl_keys(vim.lsp.handlers))
<
They are also listed below.

- `'callHierarchy/incomingCalls'`
- `'callHierarchy/outgoingCalls'`
- `'client/registerCapability'`
- `'client/unregisterCapability'`
- `'signature_help'`
- `'textDocument/codeLens'`
- `'textDocument/completion'`
- `'textDocument/diagnostic'`
- `'textDocument/documentHighlight'`
- `'textDocument/documentSymbol'`
- `'textDocument/formatting'`
- `'textDocument/hover'`
- `'textDocument/inlayHint'`
- `'textDocument/publishDiagnostics'`
- `'textDocument/rangeFormatting'`
- `'textDocument/rename'`
- `'textDocument/signatureHelp'`
- `'typeHierarchy/subtypes'`
- `'typeHierarchy/supertypes'`
- `'window/logMessage'`
- `'window/showDocument'`
- `'window/showMessage'`
- `'window/showMessageRequest'`
- `'window/workDoneProgress/create'`
- `'workspace/applyEdit'`
- `'workspace/configuration'`
- `'workspace/executeCommand'`
- `'workspace/inlayHint/refresh'`

Title: LSP FAQ, Comparison with Treesitter and Ctags, and LSP API
Summary
This section provides solutions for common LSP-related questions, like forcing LSP reloads and troubleshooting completion issues, including setting `omnifunc`. It explains how to run requests synchronously and compares LSP with Treesitter and Ctags, highlighting their respective strengths. The section then transitions to the LSP API, defining LSP methods and detailing default handlers available in `vim.lsp.handlers`, including a list of supported methods.