aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/handlers.lua
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/lua/vim/lsp/handlers.lua')
-rw-r--r--runtime/lua/vim/lsp/handlers.lua71
1 files changed, 36 insertions, 35 deletions
diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua
index d887183972..6fe4b7f939 100644
--- a/runtime/lua/vim/lsp/handlers.lua
+++ b/runtime/lua/vim/lsp/handlers.lua
@@ -1,5 +1,6 @@
local log = require('vim.lsp.log')
local protocol = require('vim.lsp.protocol')
+local ms = protocol.Methods
local util = require('vim.lsp.util')
local api = vim.api
@@ -15,14 +16,14 @@ local function err_message(...)
end
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_executeCommand
-M['workspace/executeCommand'] = function(_, _, _, _)
+M[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 result lsp.ProgressParams
---@param ctx lsp.HandlerContext
-M['$/progress'] = function(_, result, ctx)
+M[ms.dollar_progress] = function(_, result, 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')
@@ -58,7 +59,7 @@ end
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_workDoneProgress_create
---@param result lsp.WorkDoneProgressCreateParams
---@param ctx lsp.HandlerContext
-M['window/workDoneProgress/create'] = function(_, result, ctx)
+M[ms.window_workDoneProgress_create] = function(_, result, 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')
@@ -70,7 +71,7 @@ end
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_showMessageRequest
---@param result lsp.ShowMessageRequestParams
-M['window/showMessageRequest'] = function(_, result)
+M[ms.window_showMessageRequest] = function(_, result)
local actions = result.actions or {}
local co, is_main = coroutine.running()
if co and not is_main then
@@ -105,7 +106,7 @@ M['window/showMessageRequest'] = function(_, result)
end
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#client_registerCapability
-M['client/registerCapability'] = function(_, result, ctx)
+M[ms.client_registerCapability] = function(_, result, ctx)
local client_id = ctx.client_id
---@type lsp.Client
local client = vim.lsp.get_client_by_id(client_id)
@@ -118,7 +119,7 @@ M['client/registerCapability'] = function(_, result, ctx)
---@type string[]
local unsupported = {}
for _, reg in ipairs(result.registrations) do
- if reg.method == 'workspace/didChangeWatchedFiles' then
+ if reg.method == ms.workspace_didChangeWatchedFiles then
require('vim.lsp._watchfiles').register(reg, ctx)
elseif not client.dynamic_capabilities:supports_registration(reg.method) then
unsupported[#unsupported + 1] = reg.method
@@ -136,13 +137,13 @@ M['client/registerCapability'] = function(_, result, ctx)
end
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#client_unregisterCapability
-M['client/unregisterCapability'] = function(_, result, ctx)
+M[ms.client_unregisterCapability] = function(_, result, ctx)
local client_id = ctx.client_id
local client = vim.lsp.get_client_by_id(client_id)
client.dynamic_capabilities:unregister(result.unregisterations)
for _, unreg in ipairs(result.unregisterations) do
- if unreg.method == 'workspace/didChangeWatchedFiles' then
+ if unreg.method == ms.workspace_didChangeWatchedFiles then
require('vim.lsp._watchfiles').unregister(unreg, ctx)
end
end
@@ -150,7 +151,7 @@ M['client/unregisterCapability'] = function(_, result, ctx)
end
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_applyEdit
-M['workspace/applyEdit'] = function(_, workspace_edit, ctx)
+M[ms.workspace_applyEdit] = function(_, workspace_edit, ctx)
assert(
workspace_edit,
'workspace/applyEdit must be called with `ApplyWorkspaceEditParams`. Server is violating the specification'
@@ -170,7 +171,7 @@ M['workspace/applyEdit'] = function(_, workspace_edit, ctx)
end
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_configuration
-M['workspace/configuration'] = function(_, result, ctx)
+M[ms.workspace_configuration] = function(_, result, ctx)
local client_id = ctx.client_id
local client = vim.lsp.get_client_by_id(client_id)
if not client then
@@ -200,7 +201,7 @@ M['workspace/configuration'] = function(_, result, ctx)
end
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_workspaceFolders
-M['workspace/workspaceFolders'] = function(_, _, ctx)
+M[ms.workspace_workspaceFolders] = function(_, _, ctx)
local client_id = ctx.client_id
local client = vim.lsp.get_client_by_id(client_id)
if not client then
@@ -210,24 +211,24 @@ M['workspace/workspaceFolders'] = function(_, _, ctx)
return client.workspace_folders or vim.NIL
end
-M['textDocument/publishDiagnostics'] = function(...)
+M[ms.textDocument_publishDiagnostics] = function(...)
return require('vim.lsp.diagnostic').on_publish_diagnostics(...)
end
-M['textDocument/diagnostic'] = function(...)
+M[ms.textDocument_diagnostic] = function(...)
return require('vim.lsp.diagnostic').on_diagnostic(...)
end
-M['textDocument/codeLens'] = function(...)
+M[ms.textDocument_codeLens] = function(...)
return require('vim.lsp.codelens').on_codelens(...)
end
-M['textDocument/inlayHint'] = function(...)
+M[ms.textDocument_inlayHint] = function(...)
return require('vim.lsp.inlay_hint').on_inlayhint(...)
end
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
-M['textDocument/references'] = function(_, result, ctx, config)
+M[ms.textDocument_references] = function(_, result, ctx, config)
if not result or vim.tbl_isempty(result) then
vim.notify('No references found')
else
@@ -283,7 +284,7 @@ local function response_to_list(map_result, entity, title_fn)
end
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_documentSymbol
-M['textDocument/documentSymbol'] = response_to_list(
+M[ms.textDocument_documentSymbol] = response_to_list(
util.symbols_to_items,
'document symbols',
function(ctx)
@@ -293,12 +294,12 @@ M['textDocument/documentSymbol'] = response_to_list(
)
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_symbol
-M['workspace/symbol'] = response_to_list(util.symbols_to_items, 'symbols', function(ctx)
+M[ms.workspace_symbol] = response_to_list(util.symbols_to_items, 'symbols', function(ctx)
return string.format("Symbols matching '%s'", ctx.params.query)
end)
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_rename
-M['textDocument/rename'] = function(_, result, ctx, _)
+M[ms.textDocument_rename] = function(_, result, ctx, _)
if not result then
vim.notify("Language server couldn't provide rename result", vim.log.levels.INFO)
return
@@ -308,7 +309,7 @@ M['textDocument/rename'] = function(_, result, ctx, _)
end
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_rangeFormatting
-M['textDocument/rangeFormatting'] = function(_, result, ctx, _)
+M[ms.textDocument_rangeFormatting] = function(_, result, ctx, _)
if not result then
return
end
@@ -317,7 +318,7 @@ M['textDocument/rangeFormatting'] = function(_, result, ctx, _)
end
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_formatting
-M['textDocument/formatting'] = function(_, result, ctx, _)
+M[ms.textDocument_formatting] = function(_, result, ctx, _)
if not result then
return
end
@@ -326,7 +327,7 @@ M['textDocument/formatting'] = function(_, result, ctx, _)
end
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion
-M['textDocument/completion'] = function(_, result, _, _)
+M[ms.textDocument_completion] = function(_, result, _, _)
if vim.tbl_isempty(result or {}) then
return
end
@@ -380,7 +381,7 @@ function M.hover(_, result, ctx, config)
end
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_hover
-M['textDocument/hover'] = M.hover
+M[ms.textDocument_hover] = M.hover
--- Jumps to a location. Used as a handler for multiple LSP methods.
---@param _ nil not used
@@ -420,13 +421,13 @@ local function location_handler(_, result, ctx, config)
end
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_declaration
-M['textDocument/declaration'] = location_handler
+M[ms.textDocument_declaration] = location_handler
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_definition
-M['textDocument/definition'] = location_handler
+M[ms.textDocument_definition] = location_handler
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_typeDefinition
-M['textDocument/typeDefinition'] = location_handler
+M[ms.textDocument_typeDefinition] = location_handler
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_implementation
-M['textDocument/implementation'] = location_handler
+M[ms.textDocument_implementation] = location_handler
--- |lsp-handler| for the method "textDocument/signatureHelp".
--- The active parameter is highlighted with |hl-LspSignatureActiveParameter|.
@@ -477,10 +478,10 @@ function M.signature_help(_, result, ctx, config)
end
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_signatureHelp
-M['textDocument/signatureHelp'] = M.signature_help
+M[ms.textDocument_signatureHelp] = M.signature_help
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_documentHighlight
-M['textDocument/documentHighlight'] = function(_, result, ctx, _)
+M[ms.textDocument_documentHighlight] = function(_, result, ctx, _)
if not result then
return
end
@@ -523,13 +524,13 @@ local make_call_hierarchy_handler = function(direction)
end
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#callHierarchy_incomingCalls
-M['callHierarchy/incomingCalls'] = make_call_hierarchy_handler('from')
+M[ms.callHierarchy_incomingCalls] = make_call_hierarchy_handler('from')
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#callHierarchy_outgoingCalls
-M['callHierarchy/outgoingCalls'] = make_call_hierarchy_handler('to')
+M[ms.callHierarchy_outgoingCalls] = make_call_hierarchy_handler('to')
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_logMessage
-M['window/logMessage'] = function(_, result, ctx, _)
+M[ms.window_logMessage] = function(_, result, ctx, _)
local message_type = result.type
local message = result.message
local client_id = ctx.client_id
@@ -551,7 +552,7 @@ M['window/logMessage'] = function(_, result, ctx, _)
end
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_showMessage
-M['window/showMessage'] = function(_, result, ctx, _)
+M[ms.window_showMessage] = function(_, result, ctx, _)
local message_type = result.type
local message = result.message
local client_id = ctx.client_id
@@ -570,7 +571,7 @@ M['window/showMessage'] = function(_, result, ctx, _)
end
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_showDocument
-M['window/showDocument'] = function(_, result, ctx, _)
+M[ms.window_showDocument] = function(_, result, ctx, _)
local uri = result.uri
if result.external then
@@ -611,7 +612,7 @@ M['window/showDocument'] = function(_, result, ctx, _)
end
---@see https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_inlayHint_refresh
-M['workspace/inlayHint/refresh'] = function(err, result, ctx, config)
+M[ms.workspace_inlayHint_refresh] = function(err, result, ctx, config)
return require('vim.lsp.inlay_hint').on_refresh(err, result, ctx, config)
end