mirror of
https://github.com/neovim/neovim.git
synced 2025-11-03 17:24:29 +00:00
docs: lsp, vim_diff
- quickstart - mark lsp.txt as `new_layout` - remove lsp-handler documentation for notifications: they don't have handlers because they don't have server responses.
This commit is contained in:
@@ -24,26 +24,23 @@ QUICKSTART *lsp-quickstart*
|
|||||||
Nvim provides an LSP client, but the servers are provided by third parties.
|
Nvim provides an LSP client, but the servers are provided by third parties.
|
||||||
Follow these steps to get LSP features:
|
Follow these steps to get LSP features:
|
||||||
|
|
||||||
1. Install language servers using your package manager or by
|
1. Install language servers using your package manager or by following the
|
||||||
following the upstream installation instruction.
|
upstream installation instruction. You can find language servers here:
|
||||||
|
https://microsoft.github.io/language-server-protocol/implementors/servers/
|
||||||
|
|
||||||
A list of language servers is available at:
|
2. Configure the LSP client per language server. See |vim.lsp.start()| or use
|
||||||
|
this minimal example as a guide: >lua
|
||||||
|
|
||||||
https://microsoft.github.io/language-server-protocol/implementors/servers/
|
|
||||||
|
|
||||||
2. Configure the LSP client per language server.
|
|
||||||
A minimal example:
|
|
||||||
>lua
|
|
||||||
vim.lsp.start({
|
vim.lsp.start({
|
||||||
name = 'my-server-name',
|
name = 'my-server-name',
|
||||||
cmd = {'name-of-language-server-executable'},
|
cmd = {'name-of-language-server-executable'},
|
||||||
root_dir = vim.fs.dirname(vim.fs.find({'setup.py', 'pyproject.toml'}, { upward = true })[1]),
|
root_dir = vim.fs.dirname(vim.fs.find({'setup.py', 'pyproject.toml'}, { upward = true })[1]),
|
||||||
})
|
})
|
||||||
<
|
<
|
||||||
See |vim.lsp.start()| for details.
|
3. Check that the server attached to the buffer: >
|
||||||
|
:lua =vim.lsp.get_active_clients()
|
||||||
|
|
||||||
3. Configure keymaps and autocmds to utilize LSP features.
|
4. Configure keymaps and autocmds to use LSP features. See |lsp-config|.
|
||||||
See |lsp-config|.
|
|
||||||
|
|
||||||
*lsp-config*
|
*lsp-config*
|
||||||
*lsp-defaults*
|
*lsp-defaults*
|
||||||
@@ -103,11 +100,9 @@ calls behind capability checks:
|
|||||||
<
|
<
|
||||||
|
|
||||||
To learn what capabilities are available you can run the following command in
|
To learn what capabilities are available you can run the following command in
|
||||||
a buffer with a started LSP client:
|
a buffer with a started LSP client: >vim
|
||||||
|
|
||||||
>vim
|
|
||||||
:lua =vim.lsp.get_active_clients()[1].server_capabilities
|
:lua =vim.lsp.get_active_clients()[1].server_capabilities
|
||||||
<
|
|
||||||
|
|
||||||
Full list of features provided by default can be found in |lsp-buf|.
|
Full list of features provided by default can be found in |lsp-buf|.
|
||||||
|
|
||||||
@@ -115,26 +110,20 @@ Full list of features provided by default can be found in |lsp-buf|.
|
|||||||
FAQ *lsp-faq*
|
FAQ *lsp-faq*
|
||||||
|
|
||||||
- Q: How to force-reload LSP?
|
- Q: How to force-reload LSP?
|
||||||
A: Stop all clients, then reload the buffer. >vim
|
- A: Stop all clients, then reload the buffer. >vim
|
||||||
|
|
||||||
:lua vim.lsp.stop_client(vim.lsp.get_active_clients())
|
:lua vim.lsp.stop_client(vim.lsp.get_active_clients())
|
||||||
:edit
|
:edit
|
||||||
|
|
||||||
- Q: Why isn't completion working?
|
- Q: Why isn't completion working?
|
||||||
A: In the buffer where you want to use LSP, check that 'omnifunc' is set to
|
- A: In the buffer where you want to use LSP, check that 'omnifunc' is set to
|
||||||
"v:lua.vim.lsp.omnifunc": >vim
|
"v:lua.vim.lsp.omnifunc": `:verbose set omnifunc?`
|
||||||
|
- Some other plugin may be overriding the option. To avoid that you could
|
||||||
:verbose set omnifunc?
|
set the option in an |after-directory| ftplugin, e.g.
|
||||||
|
"after/ftplugin/python.vim".
|
||||||
< 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)?
|
- 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
|
- A: Check if the function has an `async` parameter and set the value to
|
||||||
false.
|
false. E.g. code formatting: >vim
|
||||||
|
|
||||||
E.g. code formatting: >vim
|
|
||||||
|
|
||||||
" Auto-format *.rs (rust) files prior to saving them
|
" Auto-format *.rs (rust) files prior to saving them
|
||||||
" (async = false is the default for format)
|
" (async = false is the default for format)
|
||||||
@@ -142,7 +131,7 @@ FAQ *lsp-faq*
|
|||||||
<
|
<
|
||||||
*lsp-vs-treesitter*
|
*lsp-vs-treesitter*
|
||||||
- Q: How do LSP and Treesitter compare?
|
- Q: How do LSP and Treesitter compare?
|
||||||
A: LSP requires a client and language server. The language server uses
|
- A: LSP requires a client and language server. The language server uses
|
||||||
semantic analysis to understand code at a project level. This provides
|
semantic analysis to understand code at a project level. This provides
|
||||||
language servers with the ability to rename across files, find
|
language servers with the ability to rename across files, find
|
||||||
definitions in external libraries and more.
|
definitions in external libraries and more.
|
||||||
@@ -173,129 +162,72 @@ when creating a new client. Keys are LSP method names: >vim
|
|||||||
*lsp-method*
|
*lsp-method*
|
||||||
|
|
||||||
Methods are the names of requests and notifications as defined by the LSP
|
Methods are the names of requests and notifications as defined by the LSP
|
||||||
specification. These LSP requests/notifications are defined by default:
|
specification. These LSP requests/notifications are defined by default in the
|
||||||
|
Nvim LSP client (but depends on server support):
|
||||||
|
|
||||||
callHierarchy/incomingCalls
|
- callHierarchy/incomingCalls
|
||||||
callHierarchy/outgoingCalls
|
- callHierarchy/outgoingCalls
|
||||||
textDocument/codeAction
|
- textDocument/codeAction
|
||||||
textDocument/completion
|
- textDocument/completion
|
||||||
textDocument/declaration*
|
- textDocument/declaration*
|
||||||
textDocument/definition
|
- textDocument/definition
|
||||||
textDocument/documentHighlight
|
- textDocument/documentHighlight
|
||||||
textDocument/documentSymbol
|
- textDocument/documentSymbol
|
||||||
textDocument/formatting
|
- textDocument/formatting
|
||||||
textDocument/hover
|
- textDocument/hover
|
||||||
textDocument/implementation*
|
- textDocument/implementation*
|
||||||
textDocument/inlayHint
|
- textDocument/inlayHint
|
||||||
textDocument/publishDiagnostics
|
- textDocument/publishDiagnostics
|
||||||
textDocument/rangeFormatting
|
- textDocument/rangeFormatting
|
||||||
textDocument/references
|
- textDocument/references
|
||||||
textDocument/rename
|
- textDocument/rename
|
||||||
textDocument/semanticTokens/full
|
- textDocument/semanticTokens/full
|
||||||
textDocument/semanticTokens/full/delta
|
- textDocument/semanticTokens/full/delta
|
||||||
textDocument/signatureHelp
|
- textDocument/signatureHelp
|
||||||
textDocument/typeDefinition*
|
- textDocument/typeDefinition*
|
||||||
window/logMessage
|
- window/logMessage
|
||||||
window/showMessage
|
- window/showMessage
|
||||||
window/showDocument
|
- window/showDocument
|
||||||
window/showMessageRequest
|
- window/showMessageRequest
|
||||||
workspace/applyEdit
|
- workspace/applyEdit
|
||||||
workspace/inlayHint/refresh
|
- workspace/inlayHint/refresh
|
||||||
workspace/symbol
|
- workspace/symbol
|
||||||
|
|
||||||
* NOTE: These are sometimes not implemented by servers.
|
|
||||||
|
|
||||||
*lsp-handler*
|
*lsp-handler*
|
||||||
|
LSP handlers are functions that handle |lsp-response|s to requests made by Nvim
|
||||||
|
to the server. (Notifications, as opposed to requests, are fire-and-forget:
|
||||||
|
there is no response, so they can't be handled. |lsp-notification|)
|
||||||
|
|
||||||
LSP handlers are functions with signatures designed to handle LSP responses
|
Each response handler has this signature: >
|
||||||
and notifications.
|
|
||||||
|
|
||||||
For |lsp-response|, each |lsp-handler| has this signature: >
|
function(err, result, ctx, config)
|
||||||
|
|
||||||
function(err, result, ctx, config)
|
|
||||||
<
|
<
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
{err} (table|nil)
|
- {err} (table|nil) Error info dict, or `nil` if the request
|
||||||
When the language server is unable to complete a
|
completed.
|
||||||
request, a table with information about the error is
|
- {result} (Result | Params | nil) `result` key of the |lsp-response| or
|
||||||
sent. Otherwise, it is `nil`. See |lsp-response|.
|
`nil` if the request failed.
|
||||||
{result} (Result | Params | nil)
|
- {ctx} (table) Table of calling state associated with the
|
||||||
When the language server is able to successfully
|
handler, with these keys:
|
||||||
complete a request, this contains the `result` key of
|
- {method} (string) |lsp-method| name.
|
||||||
the response. See |lsp-response|.
|
- {client_id} (number) |vim.lsp.client| identifier.
|
||||||
{ctx} (table)
|
- {bufnr} (Buffer) Buffer handle.
|
||||||
Context describes additional calling state associated
|
- {params} (table|nil) Request parameters table.
|
||||||
with the handler. It consists of the following key,
|
- {version} (number) Document version at time of
|
||||||
value pairs:
|
request. Handlers can compare this to the
|
||||||
|
current document version to check if the
|
||||||
{method} (string)
|
response is "stale". See also |b:changedtick|.
|
||||||
The |lsp-method| name.
|
- {config} (table) Handler-defined configuration table, which allows
|
||||||
{client_id} (number)
|
users to customize handler behavior.
|
||||||
The ID of the |vim.lsp.client|.
|
For an example, see:
|
||||||
{bufnr} (Buffer)
|
|vim.lsp.diagnostic.on_publish_diagnostics()|
|
||||||
Buffer handle, or 0 for current.
|
To configure a particular |lsp-handler|, see:
|
||||||
{params} (table|nil)
|
|lsp-handler-configuration|
|
||||||
The parameters used in the original
|
|
||||||
request which resulted in this handler
|
|
||||||
call.
|
|
||||||
{version} (number) Document version at time of
|
|
||||||
request. Handlers can compare this to the
|
|
||||||
current document version to check if the
|
|
||||||
response is "stale".
|
|
||||||
See also |b:changedtick|.
|
|
||||||
{config} (table)
|
|
||||||
Configuration for the handler.
|
|
||||||
|
|
||||||
Each handler can define its own configuration table
|
|
||||||
that allows users to customize the behavior of a
|
|
||||||
particular handler.
|
|
||||||
|
|
||||||
To configure a particular |lsp-handler|, see:
|
|
||||||
|lsp-handler-configuration|
|
|
||||||
|
|
||||||
|
|
||||||
Returns: ~
|
Returns: ~
|
||||||
The |lsp-handler| can respond by returning two values: `result, err`
|
Two values `result, err` where `err` is shaped like an RPC error: >
|
||||||
Where `err` must be shaped like an RPC error:
|
{ code, message, data? }
|
||||||
`{ code, message, data? }`
|
< You can use |vim.lsp.rpc.rpc_response_error()| to create this object.
|
||||||
|
|
||||||
You can use |vim.lsp.rpc.rpc_response_error()| to create this object.
|
|
||||||
|
|
||||||
For |lsp-notification|, each |lsp-handler| has this signature: >
|
|
||||||
|
|
||||||
function(err, result, ctx, config)
|
|
||||||
<
|
|
||||||
Parameters: ~
|
|
||||||
{err} (nil)
|
|
||||||
This is always `nil`.
|
|
||||||
See |lsp-notification|
|
|
||||||
{result} (Result)
|
|
||||||
This contains the `params` key of the notification.
|
|
||||||
See |lsp-notification|
|
|
||||||
{ctx} (table)
|
|
||||||
Context describes additional calling state associated
|
|
||||||
with the handler. It consists of the following key,
|
|
||||||
value pairs:
|
|
||||||
|
|
||||||
{method} (string)
|
|
||||||
The |lsp-method| name.
|
|
||||||
{client_id} (number)
|
|
||||||
The ID of the |vim.lsp.client|.
|
|
||||||
{config} (table)
|
|
||||||
Configuration for the handler.
|
|
||||||
|
|
||||||
Each handler can define its own configuration table
|
|
||||||
that allows users to customize the behavior of a
|
|
||||||
particular handler.
|
|
||||||
|
|
||||||
For an example, see:
|
|
||||||
|vim.lsp.diagnostic.on_publish_diagnostics()|
|
|
||||||
|
|
||||||
To configure a particular |lsp-handler|, see:
|
|
||||||
|lsp-handler-configuration|
|
|
||||||
|
|
||||||
Returns: ~
|
|
||||||
The |lsp-handler|'s return value will be ignored.
|
|
||||||
|
|
||||||
*lsp-handler-configuration*
|
*lsp-handler-configuration*
|
||||||
|
|
||||||
@@ -419,12 +351,12 @@ name: >lua
|
|||||||
<
|
<
|
||||||
|
|
||||||
*lsp-response*
|
*lsp-response*
|
||||||
For the format of the response message, see:
|
LSP response shape:
|
||||||
https://microsoft.github.io/language-server-protocol/specifications/specification-current/#responseMessage
|
https://microsoft.github.io/language-server-protocol/specifications/specification-current/#responseMessage
|
||||||
|
|
||||||
*lsp-notification*
|
*lsp-notification*
|
||||||
For the format of the notification message, see:
|
LSP notification shape:
|
||||||
https://microsoft.github.io/language-server-protocol/specifications/specification-current/#notificationMessage
|
https://microsoft.github.io/language-server-protocol/specifications/specification-current/#notificationMessage
|
||||||
|
|
||||||
*lsp-on-list-handler*
|
*lsp-on-list-handler*
|
||||||
|
|
||||||
|
|||||||
@@ -564,7 +564,8 @@ Aliases:
|
|||||||
Commands:
|
Commands:
|
||||||
:behave
|
:behave
|
||||||
:fixdel
|
:fixdel
|
||||||
:hardcopy
|
*hardcopy* `:hardcopy` was removed. Instead, use `:TOhtml` and print the
|
||||||
|
resulting HTML using a web browser or other HTML viewer.
|
||||||
:helpfind
|
:helpfind
|
||||||
:mode (no longer accepts an argument)
|
:mode (no longer accepts an argument)
|
||||||
:open
|
:open
|
||||||
@@ -586,6 +587,11 @@ Compile-time features:
|
|||||||
Emacs tags support
|
Emacs tags support
|
||||||
X11 integration (see |x11-selection|)
|
X11 integration (see |x11-selection|)
|
||||||
|
|
||||||
|
Cscope:
|
||||||
|
*cscope*
|
||||||
|
Cscope support was removed in favour of plugin-based solutions such as:
|
||||||
|
https://github.com/dhananjaylatkar/cscope_maps.nvim
|
||||||
|
|
||||||
Eval:
|
Eval:
|
||||||
Vim9script
|
Vim9script
|
||||||
*cscope_connection()*
|
*cscope_connection()*
|
||||||
@@ -715,6 +721,7 @@ Plugins:
|
|||||||
|
|
||||||
- logiPat
|
- logiPat
|
||||||
- rrhelper
|
- rrhelper
|
||||||
|
- *vimball*
|
||||||
|
|
||||||
Providers:
|
Providers:
|
||||||
|
|
||||||
@@ -771,18 +778,5 @@ TUI:
|
|||||||
at how the terminal is sending CSI. Nvim does not issue such a sequence and
|
at how the terminal is sending CSI. Nvim does not issue such a sequence and
|
||||||
always uses 7-bit control sequences.
|
always uses 7-bit control sequences.
|
||||||
|
|
||||||
Cscope:
|
|
||||||
*cscope*
|
|
||||||
Cscope support was removed in favour of plugin-based solutions such as:
|
|
||||||
https://github.com/dhananjaylatkar/cscope_maps.nvim
|
|
||||||
|
|
||||||
Hardcopy:
|
|
||||||
*hardcopy*
|
|
||||||
`:hardcopy` was removed. Instead, use `:TOhtml` and print the resulting HTML
|
|
||||||
using a web browser or some other HTML viewer.
|
|
||||||
|
|
||||||
Bundled plugins:
|
|
||||||
vimball *vimball*
|
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
vim:tw=78:ts=8:sw=2:et:ft=help:norl:
|
vim:tw=78:ts=8:sw=2:et:ft=help:norl:
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ local M = {}
|
|||||||
-- All other files are "legacy" files which require fixed-width layout.
|
-- All other files are "legacy" files which require fixed-width layout.
|
||||||
local new_layout = {
|
local new_layout = {
|
||||||
['api.txt'] = true,
|
['api.txt'] = true,
|
||||||
|
['lsp.txt'] = true,
|
||||||
['channel.txt'] = true,
|
['channel.txt'] = true,
|
||||||
['deprecated.txt'] = true,
|
['deprecated.txt'] = true,
|
||||||
['develop.txt'] = true,
|
['develop.txt'] = true,
|
||||||
|
|||||||
Reference in New Issue
Block a user