aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2024-10-29 09:36:02 +0000
committerLewis Russell <me@lewisr.dev>2024-11-01 09:17:39 +0000
commit9b357e30fdd0a575480182872331fdb87e9cc331 (patch)
tree02e7a8ce3fcd70946acca8e27d2769dfcf75b6e3 /runtime
parentf54266dbed6f1a4cb4fad3486a722a25070d7feb (diff)
downloadrneovim-9b357e30fdd0a575480182872331fdb87e9cc331.tar.gz
rneovim-9b357e30fdd0a575480182872331fdb87e9cc331.tar.bz2
rneovim-9b357e30fdd0a575480182872331fdb87e9cc331.zip
feat(lsp)!: remove client-server handlers from vim.lsp.handlers
- Partition the handlers in vim.lsp.handlers as: - client to server response handlers (RCS) - server to client request handlers (RSC) - server to client notification handlers (NSC) Note use string indexes instead of protocol.methods for improved typing in LuaLS (tip: use hover on RCS, RSC or NSC).
Diffstat (limited to 'runtime')
-rw-r--r--runtime/doc/deprecated.txt6
-rw-r--r--runtime/doc/lsp.txt277
-rw-r--r--runtime/doc/news-0.10.txt2
-rw-r--r--runtime/doc/news.txt8
-rw-r--r--runtime/lua/vim/lsp.lua1
-rw-r--r--runtime/lua/vim/lsp/_meta.lua4
-rw-r--r--runtime/lua/vim/lsp/buf.lua66
-rw-r--r--runtime/lua/vim/lsp/codelens.lua2
-rw-r--r--runtime/lua/vim/lsp/diagnostic.lua83
-rw-r--r--runtime/lua/vim/lsp/handlers.lua173
-rw-r--r--runtime/lua/vim/lsp/inlay_hint.lua4
-rw-r--r--runtime/lua/vim/lsp/protocol.lua104
12 files changed, 374 insertions, 356 deletions
diff --git a/runtime/doc/deprecated.txt b/runtime/doc/deprecated.txt
index 9c973b20bd..5e809ad26c 100644
--- a/runtime/doc/deprecated.txt
+++ b/runtime/doc/deprecated.txt
@@ -50,6 +50,12 @@ LSP
• *vim.lsp.buf.completion* Use |vim.lsp.completion.trigger()| instead.
• vim.lsp.buf_request_all The `error` key has been renamed to `err` inside
the result parameter of the handler.
+• *vim.lsp.with()* Pass configuration to equivalent
+ functions in `vim.lsp.buf.*'.
+• |vim.lsp.handlers|
+ No longer support client to server response handlers. Only server to
+ client requests/notification handlers are supported.
+• *vim.lsp.handlers.signature_help()* Use |vim.lsp.buf.signature_help()| instead.
------------------------------------------------------------------------------
DEPRECATED IN 0.10 *deprecated-0.10*
diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt
index 804eb171f7..6e5c85c019 100644
--- a/runtime/doc/lsp.txt
+++ b/runtime/doc/lsp.txt
@@ -195,41 +195,41 @@ Requests and notifications defined by the LSP specification are referred to as
They are also listed below. Note that handlers depend on server support: they
won't run if your server doesn't support them.
-- callHierarchy/incomingCalls
-- callHierarchy/outgoingCalls
-- textDocument/codeAction
-- textDocument/completion
-- textDocument/declaration*
-- textDocument/definition
-- textDocument/diagnostic
-- textDocument/documentHighlight
-- textDocument/documentSymbol
-- textDocument/formatting
-- textDocument/hover
-- textDocument/implementation*
-- textDocument/inlayHint
-- textDocument/prepareTypeHierarchy
-- textDocument/publishDiagnostics
-- textDocument/rangeFormatting
-- textDocument/rangesFormatting
-- textDocument/references
-- textDocument/rename
-- textDocument/semanticTokens/full
-- textDocument/semanticTokens/full/delta
-- textDocument/signatureHelp
-- textDocument/typeDefinition*
-- typeHierarchy/subtypes
-- typeHierarchy/supertypes
-- window/logMessage
-- window/showMessage
-- window/showDocument
-- window/showMessageRequest
-- workspace/applyEdit
-- workspace/configuration
-- workspace/executeCommand
-- workspace/inlayHint/refresh
-- workspace/symbol
-- workspace/workspaceFolders
+- `'callHierarchy/incomingCalls'`
+- `'callHierarchy/outgoingCalls'`
+- `'textDocument/codeAction'`
+- `'textDocument/completion'`
+- `'textDocument/declaration'`
+- `'textDocument/definition'`
+- `'textDocument/diagnostic'`
+- `'textDocument/documentHighlight'`
+- `'textDocument/documentSymbol'`
+- `'textDocument/formatting'`
+- `'textDocument/hover'`
+- `'textDocument/implementation'`
+- `'textDocument/inlayHint'`
+- `'textDocument/prepareTypeHierarchy'`
+- `'textDocument/publishDiagnostics'`
+- `'textDocument/rangeFormatting'`
+- `'textDocument/rangesFormatting'`
+- `'textDocument/references'`
+- `'textDocument/rename'`
+- `'textDocument/semanticTokens/full'`
+- `'textDocument/semanticTokens/full/delta'`
+- `'textDocument/signatureHelp'`
+- `'textDocument/typeDefinition*'`
+- `'typeHierarchy/subtypes'`
+- `'typeHierarchy/supertypes'`
+- `'window/logMessage'`
+- `'window/showMessage'`
+- `'window/showDocument'`
+- `'window/showMessageRequest'`
+- `'workspace/applyEdit'`
+- `'workspace/configuration'`
+- `'workspace/executeCommand'`
+- `'workspace/inlayHint/refresh'`
+- `'workspace/symbol'`
+- `'workspace/workspaceFolders'`
*lsp-handler*
LSP handlers are functions that handle |lsp-response|s to requests made by Nvim
@@ -238,7 +238,7 @@ there is no response, so they can't be handled. |lsp-notification|)
Each response handler has this signature: >
- function(err, result, ctx, config)
+ function(err, result, ctx)
<
Parameters: ~
• {err} (`table|nil`) Error info dict, or `nil` if the request
@@ -255,121 +255,53 @@ Each response handler has this signature: >
request. Handlers can compare this to the
current document version to check if the
response is "stale". See also |b:changedtick|.
- • {config} (`table`) Handler-defined configuration table, which allows
- users to customize handler behavior.
- For an example, see:
- |vim.lsp.diagnostic.on_publish_diagnostics()|
- To configure a particular |lsp-handler|, see:
- |lsp-handler-configuration|
Returns: ~
Two values `result, err` where `err` is shaped like an RPC error: >
{ code, message, data? }
< You can use |vim.lsp.rpc.rpc_response_error()| to create this object.
- *lsp-handler-configuration*
-
-To configure the behavior of a builtin |lsp-handler|, the convenient method
-|vim.lsp.with()| is provided for users.
-
- To configure the behavior of |vim.lsp.diagnostic.on_publish_diagnostics()|,
- consider the following example, where a new |lsp-handler| is created using
- |vim.lsp.with()| that no longer generates signs for the diagnostics: >lua
-
- vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
- vim.lsp.diagnostic.on_publish_diagnostics, {
- -- Disable signs
- signs = false,
- }
- )
-<
- To enable signs, use |vim.lsp.with()| again to create and assign a new
- |lsp-handler| to |vim.lsp.handlers| for the associated method: >lua
-
- vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
- vim.lsp.diagnostic.on_publish_diagnostics, {
- -- Enable signs
- signs = true,
- }
- )
-<
- To configure a handler on a per-server basis, you can use the {handlers} key
- for |vim.lsp.start_client()| >lua
-
- vim.lsp.start_client {
- ..., -- Other configuration omitted.
- handlers = {
- ["textDocument/publishDiagnostics"] = vim.lsp.with(
- vim.lsp.diagnostic.on_publish_diagnostics, {
- -- Disable virtual_text
- virtual_text = false,
- }
- ),
- },
- }
-<
- or if using "nvim-lspconfig", you can use the {handlers} key of `setup()`:
- >lua
-
- require('lspconfig').rust_analyzer.setup {
- handlers = {
- ["textDocument/publishDiagnostics"] = vim.lsp.with(
- vim.lsp.diagnostic.on_publish_diagnostics, {
- -- Disable virtual_text
- virtual_text = false
- }
- ),
- }
- }
-<
- Some handlers do not have an explicitly named handler function (such as
- |vim.lsp.diagnostic.on_publish_diagnostics()|). To override these, first
- create a reference to the existing handler: >lua
-
- local on_references = vim.lsp.handlers["textDocument/references"]
- vim.lsp.handlers["textDocument/references"] = vim.lsp.with(
- on_references, {
- -- Use location list instead of quickfix list
- loclist = true,
- }
- )
-<
*lsp-handler-resolution*
-Handlers can be set by:
+Handlers can be set by (in increasing priority):
- Setting a field in vim.lsp.handlers. *vim.lsp.handlers*
- vim.lsp.handlers is a global table that contains the default mapping of
- |lsp-method| names to |lsp-handlers|. To override the handler for the
- `"textDocument/definition"` method: >lua
+ `vim.lsp.handlers` is a global table that contains the default mapping of
+ |lsp-method| names to lsp-handlers.
+
+ Example: >lua
- vim.lsp.handlers["textDocument/definition"] = my_custom_default_definition
+ vim.lsp.handlers['textDocument/publishDiagnostics'] = my_custom_diagnostics_handler
<
+ Note: this only applies for requests/notifications made by the
+ server to the client.
+
- The {handlers} parameter of |vim.lsp.start()|. This sets the default
- |lsp-handler| for the server being started. Example: >lua
+ |lsp-handler| for a specific server.
+
+ Example: >lua
vim.lsp.start {
..., -- Other configuration omitted.
handlers = {
- ["textDocument/definition"] = my_custom_server_definition
+ ['textDocument/publishDiagnostics'] = my_custom_server_definition
},
}
+<
+ Note: this only applies for requests/notifications made by the
+ server to the client.
- The {handler} parameter of |vim.lsp.buf_request_all()|. This sets
- the |lsp-handler| ONLY for the given request(s). Example: >lua
+ the |lsp-handler| ONLY for the given request(s).
+
+ Example: >lua
vim.lsp.buf_request_all(
0,
- "textDocument/definition",
+ 'textDocument/publishDiagnostics',
my_request_params,
my_handler
)
<
-In summary, the |lsp-handler| will be chosen based on the current |lsp-method|
-in the following order:
-
-1. Handler passed to |vim.lsp.buf_request_all()|, if any.
-2. Handler defined in |vim.lsp.start()|, if any.
-3. Handler defined in |vim.lsp.handlers|, if any.
*vim.lsp.log_levels*
Log levels are defined in |vim.log.levels|
@@ -955,14 +887,6 @@ tagfunc({pattern}, {flags}) *vim.lsp.tagfunc()*
Return: ~
(`table[]`) tags A list of matching tags
-with({handler}, {override_config}) *vim.lsp.with()*
- Function to manage overriding defaults for LSP handlers.
-
- Parameters: ~
- • {handler} (`lsp.Handler`) See |lsp-handler|
- • {override_config} (`table`) Table containing the keys to override
- behavior of the {handler}
-
==============================================================================
Lua module: vim.lsp.client *lsp-client*
@@ -1279,6 +1203,13 @@ Lua module: vim.lsp.buf *lsp-buf*
Fields: ~
• {silent}? (`boolean`)
+*vim.lsp.buf.signature_help.Opts*
+ Extends: |vim.lsp.util.open_floating_preview.Opts|
+
+
+ Fields: ~
+ • {silent}? (`boolean`)
+
*vim.lsp.buf.add_workspace_folder()*
add_workspace_folder({workspace_folder})
@@ -1461,10 +1392,14 @@ rename({new_name}, {opts}) *vim.lsp.buf.rename()*
ones where client.name matches this field.
• {bufnr}? (`integer`) (default: current buffer)
-signature_help() *vim.lsp.buf.signature_help()*
+signature_help({config}) *vim.lsp.buf.signature_help()*
Displays signature information about the symbol under the cursor in a
floating window.
+ Parameters: ~
+ • {config} (`vim.lsp.buf.signature_help.Opts?`) See
+ |vim.lsp.buf.signature_help.Opts|.
+
type_definition({opts}) *vim.lsp.buf.type_definition()*
Jumps to the definition of the type of the symbol under the cursor.
@@ -1514,66 +1449,24 @@ get_namespace({client_id}, {is_pull})
client. Defaults to push
*vim.lsp.diagnostic.on_diagnostic()*
-on_diagnostic({_}, {result}, {ctx}, {config})
+on_diagnostic({_}, {result}, {ctx})
|lsp-handler| for the method "textDocument/diagnostic"
- See |vim.diagnostic.config()| for configuration options. Handler-specific
- configuration can be set using |vim.lsp.with()|: >lua
- vim.lsp.handlers["textDocument/diagnostic"] = vim.lsp.with(
- vim.lsp.diagnostic.on_diagnostic, {
- -- Enable underline, use default values
- underline = true,
- -- Enable virtual text, override spacing to 4
- virtual_text = {
- spacing = 4,
- },
- -- Use a function to dynamically turn signs off
- -- and on, using buffer local variables
- signs = function(namespace, bufnr)
- return vim.b[bufnr].show_signs == true
- end,
- -- Disable a feature
- update_in_insert = false,
- }
- )
-<
+ See |vim.diagnostic.config()| for configuration options.
Parameters: ~
• {result} (`lsp.DocumentDiagnosticReport`)
• {ctx} (`lsp.HandlerContext`)
- • {config} (`vim.diagnostic.Opts`) Configuration table (see
- |vim.diagnostic.config()|).
*vim.lsp.diagnostic.on_publish_diagnostics()*
-on_publish_diagnostics({_}, {result}, {ctx}, {config})
+on_publish_diagnostics({_}, {result}, {ctx})
|lsp-handler| for the method "textDocument/publishDiagnostics"
- See |vim.diagnostic.config()| for configuration options. Handler-specific
- configuration can be set using |vim.lsp.with()|: >lua
- vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
- vim.lsp.diagnostic.on_publish_diagnostics, {
- -- Enable underline, use default values
- underline = true,
- -- Enable virtual text, override spacing to 4
- virtual_text = {
- spacing = 4,
- },
- -- Use a function to dynamically turn signs off
- -- and on, using buffer local variables
- signs = function(namespace, bufnr)
- return vim.b[bufnr].show_signs == true
- end,
- -- Disable a feature
- update_in_insert = false,
- }
- )
-<
+ See |vim.diagnostic.config()| for configuration options.
Parameters: ~
• {result} (`lsp.PublishDiagnosticsParams`)
• {ctx} (`lsp.HandlerContext`)
- • {config} (`vim.diagnostic.Opts?`) Configuration table (see
- |vim.diagnostic.config()|).
==============================================================================
@@ -1824,32 +1717,6 @@ stop({bufnr}, {client_id}) *vim.lsp.semantic_tokens.stop()*
==============================================================================
-Lua module: vim.lsp.handlers *lsp-handlers*
-
- *vim.lsp.handlers.signature_help()*
-signature_help({_}, {result}, {ctx}, {config})
- |lsp-handler| for the method "textDocument/signatureHelp".
-
- The active parameter is highlighted with |hl-LspSignatureActiveParameter|. >lua
- vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(
- vim.lsp.handlers.signature_help, {
- -- Use a sharp border with `FloatBorder` highlights
- border = "single"
- }
- )
-<
-
- Parameters: ~
- • {result} (`lsp.SignatureHelp?`) Response from the language server
- • {ctx} (`lsp.HandlerContext`) Client context
- • {config} (`table`) Configuration table.
- • border: (default=nil)
- • Add borders to the floating window
- • See |vim.lsp.util.open_floating_preview()| for more
- options
-
-
-==============================================================================
Lua module: vim.lsp.util *lsp-util*
*vim.lsp.util.open_floating_preview.Opts*
diff --git a/runtime/doc/news-0.10.txt b/runtime/doc/news-0.10.txt
index a5ded1ca22..35af570ec3 100644
--- a/runtime/doc/news-0.10.txt
+++ b/runtime/doc/news-0.10.txt
@@ -246,7 +246,7 @@ The following new features were added.
indicator to see if a server supports a feature. Instead use
`client.supports_method(<method>)`. It considers both the dynamic
capabilities and static `server_capabilities`.
- • `anchor_bias` option to |lsp-handlers| aids in positioning of floating
+ • `anchor_bias` option to lsp-handlers aids in positioning of floating
windows.
• |vim.lsp.util.locations_to_items()| sets the `user_data` of each item to
the original LSP `Location` or `LocationLink`.
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
index c01bb46de7..f82cf4453e 100644
--- a/runtime/doc/news.txt
+++ b/runtime/doc/news.txt
@@ -87,7 +87,13 @@ LSP
but no longer trigger the global handlers from `vim.lsp.handlers`
• |vim.lsp.buf.typehierarchy()| now passes the correct params for each
client request.
-
+• |vim.lsp.handlers.signature_help()| is no longer used.
+• |vim.lsp.diagnostic.on_publish_diagnostics()| and
+ |vim.lsp.diagnostic.on_diagnostic()| no longer accept a config parameter and
+ can no longer be configured with |vim.lsp.with()|.
+ Instead use: >lua
+ vim.diagnostic.config(config, vim.lsp.diagnostic.get_namespace(client_id))
+<
LUA
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua
index a8ae283f64..42a0ccc3d4 100644
--- a/runtime/lua/vim/lsp.lua
+++ b/runtime/lua/vim/lsp.lua
@@ -1165,6 +1165,7 @@ function lsp.for_each_buffer_client(bufnr, fn)
end
end
+--- @deprecated
--- Function to manage overriding defaults for LSP handlers.
---@param handler (lsp.Handler) See |lsp-handler|
---@param override_config (table) Table containing the keys to override behavior of the {handler}
diff --git a/runtime/lua/vim/lsp/_meta.lua b/runtime/lua/vim/lsp/_meta.lua
index 589a49c003..bf693ccc57 100644
--- a/runtime/lua/vim/lsp/_meta.lua
+++ b/runtime/lua/vim/lsp/_meta.lua
@@ -1,8 +1,8 @@
---@meta
error('Cannot require a meta file')
----@alias lsp.Handler fun(err: lsp.ResponseError?, result: any, context: lsp.HandlerContext, config?: table): ...any
----@alias lsp.MultiHandler fun(results: table<integer,{err: lsp.ResponseError?, result: any}>, context: lsp.HandlerContext, config?: table): ...any
+---@alias lsp.Handler fun(err: lsp.ResponseError?, result: any, context: lsp.HandlerContext): ...any
+---@alias lsp.MultiHandler fun(results: table<integer,{err: lsp.ResponseError?, result: any}>, context: lsp.HandlerContext): ...any
---@class lsp.HandlerContext
---@field method string
diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua
index 4818359fb3..152226a757 100644
--- a/runtime/lua/vim/lsp/buf.lua
+++ b/runtime/lua/vim/lsp/buf.lua
@@ -258,10 +258,72 @@ function M.implementation(opts)
get_locations(ms.textDocument_implementation, opts)
end
+local sig_help_ns = api.nvim_create_namespace('vim_lsp_signature_help')
+
+--- @class vim.lsp.buf.signature_help.Opts : vim.lsp.util.open_floating_preview.Opts
+--- @field silent? boolean
+
+-- TODO(lewis6991): support multiple clients
--- Displays signature information about the symbol under the cursor in a
--- floating window.
-function M.signature_help()
- lsp.buf_request(0, ms.textDocument_signatureHelp, client_positional_params())
+--- @param config? vim.lsp.buf.signature_help.Opts
+function M.signature_help(config)
+ local method = ms.textDocument_signatureHelp
+
+ config = config or {}
+ config.focus_id = method
+
+ lsp.buf_request(0, method, client_positional_params(), function(err, result, ctx)
+ local client = assert(vim.lsp.get_client_by_id(ctx.client_id))
+
+ if err then
+ vim.notify(
+ client.name .. ': ' .. tostring(err.code) .. ': ' .. err.message,
+ vim.log.levels.ERROR
+ )
+ api.nvim_command('redraw')
+ return
+ end
+
+ if api.nvim_get_current_buf() ~= ctx.bufnr then
+ -- Ignore result since buffer changed. This happens for slow language servers.
+ return
+ end
+
+ -- When use `autocmd CompleteDone <silent><buffer> lua vim.lsp.buf.signature_help()` to call signatureHelp handler
+ -- If the completion item doesn't have signatures It will make noise. Change to use `print` that can use `<silent>` to ignore
+ if not result or not result.signatures or not result.signatures[1] then
+ if config.silent ~= true then
+ print('No signature help available')
+ end
+ return
+ end
+
+ local triggers =
+ vim.tbl_get(client.server_capabilities, 'signatureHelpProvider', 'triggerCharacters')
+
+ local ft = vim.bo[ctx.bufnr].filetype
+ local lines, hl = util.convert_signature_help_to_markdown_lines(result, ft, triggers)
+ if not lines or vim.tbl_isempty(lines) then
+ if config.silent ~= true then
+ print('No signature help available')
+ end
+ return
+ end
+
+ local fbuf = util.open_floating_preview(lines, 'markdown', config)
+
+ -- Highlight the active parameter.
+ if hl then
+ vim.hl.range(
+ fbuf,
+ sig_help_ns,
+ 'LspSignatureActiveParameter',
+ { hl[1], hl[2] },
+ { hl[3], hl[4] }
+ )
+ end
+ end)
end
--- @deprecated
diff --git a/runtime/lua/vim/lsp/codelens.lua b/runtime/lua/vim/lsp/codelens.lua
index d8c6c27a98..fdbdda695a 100644
--- a/runtime/lua/vim/lsp/codelens.lua
+++ b/runtime/lua/vim/lsp/codelens.lua
@@ -261,7 +261,7 @@ end
---@param err lsp.ResponseError?
---@param result lsp.CodeLens[]
---@param ctx lsp.HandlerContext
-function M.on_codelens(err, result, ctx, _)
+function M.on_codelens(err, result, ctx)
if err then
active_refreshes[assert(ctx.bufnr)] = nil
log.error('codelens', err)
diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua
index c59e2db901..8fd30c7668 100644
--- a/runtime/lua/vim/lsp/diagnostic.lua
+++ b/runtime/lua/vim/lsp/diagnostic.lua
@@ -9,14 +9,6 @@ local augroup = api.nvim_create_augroup('vim_lsp_diagnostic', {})
local DEFAULT_CLIENT_ID = -1
-local function get_client_id(client_id)
- if client_id == nil then
- client_id = DEFAULT_CLIENT_ID
- end
-
- return client_id
-end
-
---@param severity lsp.DiagnosticSeverity
local function severity_lsp_to_vim(severity)
if type(severity) == 'string' then
@@ -218,8 +210,7 @@ end
--- @param client_id? integer
--- @param diagnostics vim.Diagnostic[]
--- @param is_pull boolean
---- @param config? vim.diagnostic.Opts
-local function handle_diagnostics(uri, client_id, diagnostics, is_pull, config)
+local function handle_diagnostics(uri, client_id, diagnostics, is_pull)
local fname = vim.uri_to_fname(uri)
if #diagnostics == 0 and vim.fn.bufexists(fname) == 0 then
@@ -231,91 +222,39 @@ local function handle_diagnostics(uri, client_id, diagnostics, is_pull, config)
return
end
- client_id = get_client_id(client_id)
- local namespace = M.get_namespace(client_id, is_pull)
-
- if config then
- --- @cast config table<string, table>
- for _, opt in pairs(config) do
- convert_severity(opt)
- end
- -- Persist configuration to ensure buffer reloads use the same
- -- configuration. To make lsp.with configuration work (See :help
- -- lsp-handler-configuration)
- vim.diagnostic.config(config, namespace)
+ if client_id == nil then
+ client_id = DEFAULT_CLIENT_ID
end
+ local namespace = M.get_namespace(client_id, is_pull)
+
vim.diagnostic.set(namespace, bufnr, diagnostic_lsp_to_vim(diagnostics, bufnr, client_id))
end
--- |lsp-handler| for the method "textDocument/publishDiagnostics"
---
---- See |vim.diagnostic.config()| for configuration options. Handler-specific
---- configuration can be set using |vim.lsp.with()|:
----
---- ```lua
---- vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
---- vim.lsp.diagnostic.on_publish_diagnostics, {
---- -- Enable underline, use default values
---- underline = true,
---- -- Enable virtual text, override spacing to 4
---- virtual_text = {
---- spacing = 4,
---- },
---- -- Use a function to dynamically turn signs off
---- -- and on, using buffer local variables
---- signs = function(namespace, bufnr)
---- return vim.b[bufnr].show_signs == true
---- end,
---- -- Disable a feature
---- update_in_insert = false,
---- }
---- )
---- ```
+--- See |vim.diagnostic.config()| for configuration options.
---
---@param _ lsp.ResponseError?
---@param result lsp.PublishDiagnosticsParams
---@param ctx lsp.HandlerContext
----@param config? vim.diagnostic.Opts Configuration table (see |vim.diagnostic.config()|).
-function M.on_publish_diagnostics(_, result, ctx, config)
- handle_diagnostics(result.uri, ctx.client_id, result.diagnostics, false, config)
+function M.on_publish_diagnostics(_, result, ctx)
+ handle_diagnostics(result.uri, ctx.client_id, result.diagnostics, false)
end
--- |lsp-handler| for the method "textDocument/diagnostic"
---
---- See |vim.diagnostic.config()| for configuration options. Handler-specific
---- configuration can be set using |vim.lsp.with()|:
----
---- ```lua
---- vim.lsp.handlers["textDocument/diagnostic"] = vim.lsp.with(
---- vim.lsp.diagnostic.on_diagnostic, {
---- -- Enable underline, use default values
---- underline = true,
---- -- Enable virtual text, override spacing to 4
---- virtual_text = {
---- spacing = 4,
---- },
---- -- Use a function to dynamically turn signs off
---- -- and on, using buffer local variables
---- signs = function(namespace, bufnr)
---- return vim.b[bufnr].show_signs == true
---- end,
---- -- Disable a feature
---- update_in_insert = false,
---- }
---- )
---- ```
+--- See |vim.diagnostic.config()| for configuration options.
---
---@param _ lsp.ResponseError?
---@param result lsp.DocumentDiagnosticReport
---@param ctx lsp.HandlerContext
----@param config vim.diagnostic.Opts Configuration table (see |vim.diagnostic.config()|).
-function M.on_diagnostic(_, result, ctx, config)
+function M.on_diagnostic(_, result, ctx)
if result == nil or result.kind == 'unchanged' then
return
end
- handle_diagnostics(ctx.params.textDocument.uri, ctx.client_id, result.items, true, config)
+ handle_diagnostics(ctx.params.textDocument.uri, ctx.client_id, result.items, true)
end
--- Clear push diagnostics and diagnostic cache.
diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua
index ad827cfd34..2b7aefe0e1 100644
--- a/runtime/lua/vim/lsp/handlers.lua
+++ b/runtime/lua/vim/lsp/handlers.lua
@@ -5,10 +5,21 @@ local util = require('vim.lsp.util')
local api = vim.api
local completion = require('vim.lsp.completion')
---- @type table<string,lsp.Handler>
+--- @type table<string, lsp.Handler>
local M = {}
--- FIXME: DOC: Expose in vimdocs
+--- @deprecated
+--- Client to server response handlers.
+--- @type table<vim.lsp.protocol.Method.ClientToServer, lsp.Handler>
+local RCS = {}
+
+--- Server to client request handlers.
+--- @type table<vim.lsp.protocol.Method.ServerToClient, lsp.Handler>
+local RSC = {}
+
+--- Server to client notification handlers.
+--- @type table<vim.lsp.protocol.Method.ServerToClient, lsp.Handler>
+local NSC = {}
--- Writes to error buffer.
---@param ... string Will be concatenated before being written
@@ -18,14 +29,15 @@ local function err_message(...)
end
--- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_executeCommand
-M[ms.workspace_executeCommand] = function(_, _, _, _)
+RCS[ms.workspace_executeCommand] = function(_, _, _)
-- Error handling is done implicitly by wrapping all handlers; see end of this file
end
--- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#progress
---@param params lsp.ProgressParams
---@param ctx lsp.HandlerContext
-M[ms.dollar_progress] = function(_, params, ctx)
+---@diagnostic disable-next-line:no-unknown
+RSC[ms.dollar_progress] = function(_, params, ctx)
local client = vim.lsp.get_client_by_id(ctx.client_id)
if not client then
err_message('LSP[id=', tostring(ctx.client_id), '] client has shut down during progress update')
@@ -59,26 +71,26 @@ M[ms.dollar_progress] = function(_, params, ctx)
end
--- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_workDoneProgress_create
----@param result lsp.WorkDoneProgressCreateParams
+---@param params lsp.WorkDoneProgressCreateParams
---@param ctx lsp.HandlerContext
-M[ms.window_workDoneProgress_create] = function(_, result, ctx)
+RSC[ms.window_workDoneProgress_create] = function(_, params, ctx)
local client = vim.lsp.get_client_by_id(ctx.client_id)
if not client then
err_message('LSP[id=', tostring(ctx.client_id), '] client has shut down during progress update')
return vim.NIL
end
- client.progress:push(result)
+ client.progress:push(params)
return vim.NIL
end
--- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_showMessageRequest
----@param result lsp.ShowMessageRequestParams
-M[ms.window_showMessageRequest] = function(_, result)
- local actions = result.actions or {}
+---@param params lsp.ShowMessageRequestParams
+RSC[ms.window_showMessageRequest] = function(_, params)
+ local actions = params.actions or {}
local co, is_main = coroutine.running()
if co and not is_main then
local opts = {
- prompt = result.message .. ': ',
+ prompt = params.message .. ': ',
format_item = function(action)
return (action.title:gsub('\r\n', '\\r\\n')):gsub('\n', '\\n')
end,
@@ -92,7 +104,7 @@ M[ms.window_showMessageRequest] = function(_, result)
end)
return coroutine.yield()
else
- local option_strings = { result.message, '\nRequest Actions:' }
+ local option_strings = { params.message, '\nRequest Actions:' }
for i, action in ipairs(actions) do
local title = action.title:gsub('\r\n', '\\r\\n')
title = title:gsub('\n', '\\n')
@@ -108,19 +120,19 @@ M[ms.window_showMessageRequest] = function(_, result)
end
--- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#client_registerCapability
---- @param result lsp.RegistrationParams
-M[ms.client_registerCapability] = function(_, result, ctx)
+--- @param params lsp.RegistrationParams
+RSC[ms.client_registerCapability] = function(_, params, ctx)
local client_id = ctx.client_id
local client = assert(vim.lsp.get_client_by_id(client_id))
- client.dynamic_capabilities:register(result.registrations)
+ client.dynamic_capabilities:register(params.registrations)
for bufnr, _ in pairs(client.attached_buffers) do
vim.lsp._set_defaults(client, bufnr)
end
---@type string[]
local unsupported = {}
- for _, reg in ipairs(result.registrations) do
+ for _, reg in ipairs(params.registrations) do
if reg.method == ms.workspace_didChangeWatchedFiles then
vim.lsp._watchfiles.register(reg, ctx)
elseif not client.dynamic_capabilities:supports_registration(reg.method) then
@@ -139,13 +151,13 @@ M[ms.client_registerCapability] = function(_, result, ctx)
end
--- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#client_unregisterCapability
---- @param result lsp.UnregistrationParams
-M[ms.client_unregisterCapability] = function(_, result, ctx)
+--- @param params lsp.UnregistrationParams
+RSC[ms.client_unregisterCapability] = function(_, params, ctx)
local client_id = ctx.client_id
local client = assert(vim.lsp.get_client_by_id(client_id))
- client.dynamic_capabilities:unregister(result.unregisterations)
+ client.dynamic_capabilities:unregister(params.unregisterations)
- for _, unreg in ipairs(result.unregisterations) do
+ for _, unreg in ipairs(params.unregisterations) do
if unreg.method == ms.workspace_didChangeWatchedFiles then
vim.lsp._watchfiles.unregister(unreg, ctx)
end
@@ -153,20 +165,20 @@ M[ms.client_unregisterCapability] = function(_, result, ctx)
return vim.NIL
end
+-- TODO(lewis6991): Do we need to notify other servers?
--- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_applyEdit
-M[ms.workspace_applyEdit] = function(_, workspace_edit, ctx)
+RSC[ms.workspace_applyEdit] = function(_, params, ctx)
assert(
- workspace_edit,
+ params,
'workspace/applyEdit must be called with `ApplyWorkspaceEditParams`. Server is violating the specification'
)
-- TODO(ashkan) Do something more with label?
local client_id = ctx.client_id
local client = assert(vim.lsp.get_client_by_id(client_id))
- if workspace_edit.label then
- print('Workspace edit', workspace_edit.label)
+ if params.label then
+ print('Workspace edit', params.label)
end
- local status, result =
- pcall(util.apply_workspace_edit, workspace_edit.edit, client.offset_encoding)
+ local status, result = pcall(util.apply_workspace_edit, params.edit, client.offset_encoding)
return {
applied = status,
failureReason = result,
@@ -182,8 +194,8 @@ local function lookup_section(table, section)
end