mirror of
https://github.com/neovim/neovim.git
synced 2025-11-11 21:08:53 +00:00
refactor(lsp): use protocol.Methods instead of strings #24537
This commit is contained in:
@@ -3,6 +3,7 @@ local default_handlers = require('vim.lsp.handlers')
|
|||||||
local log = require('vim.lsp.log')
|
local log = require('vim.lsp.log')
|
||||||
local lsp_rpc = require('vim.lsp.rpc')
|
local lsp_rpc = require('vim.lsp.rpc')
|
||||||
local protocol = require('vim.lsp.protocol')
|
local protocol = require('vim.lsp.protocol')
|
||||||
|
local ms = protocol.Methods
|
||||||
local util = require('vim.lsp.util')
|
local util = require('vim.lsp.util')
|
||||||
local sync = require('vim.lsp.sync')
|
local sync = require('vim.lsp.sync')
|
||||||
local semantic_tokens = require('vim.lsp.semantic_tokens')
|
local semantic_tokens = require('vim.lsp.semantic_tokens')
|
||||||
@@ -35,34 +36,34 @@ local lsp = {
|
|||||||
|
|
||||||
-- maps request name to the required server_capability in the client.
|
-- maps request name to the required server_capability in the client.
|
||||||
lsp._request_name_to_capability = {
|
lsp._request_name_to_capability = {
|
||||||
['textDocument/hover'] = { 'hoverProvider' },
|
[ms.textDocument_hover] = { 'hoverProvider' },
|
||||||
['textDocument/signatureHelp'] = { 'signatureHelpProvider' },
|
[ms.textDocument_signatureHelp] = { 'signatureHelpProvider' },
|
||||||
['textDocument/definition'] = { 'definitionProvider' },
|
[ms.textDocument_definition] = { 'definitionProvider' },
|
||||||
['textDocument/implementation'] = { 'implementationProvider' },
|
[ms.textDocument_implementation] = { 'implementationProvider' },
|
||||||
['textDocument/declaration'] = { 'declarationProvider' },
|
[ms.textDocument_declaration] = { 'declarationProvider' },
|
||||||
['textDocument/typeDefinition'] = { 'typeDefinitionProvider' },
|
[ms.textDocument_typeDefinition] = { 'typeDefinitionProvider' },
|
||||||
['textDocument/documentSymbol'] = { 'documentSymbolProvider' },
|
[ms.textDocument_documentSymbol] = { 'documentSymbolProvider' },
|
||||||
['textDocument/prepareCallHierarchy'] = { 'callHierarchyProvider' },
|
[ms.textDocument_prepareCallHierarchy] = { 'callHierarchyProvider' },
|
||||||
['callHierarchy/incomingCalls'] = { 'callHierarchyProvider' },
|
[ms.callHierarchy_incomingCalls] = { 'callHierarchyProvider' },
|
||||||
['callHierarchy/outgoingCalls'] = { 'callHierarchyProvider' },
|
[ms.callHierarchy_outgoingCalls] = { 'callHierarchyProvider' },
|
||||||
['textDocument/rename'] = { 'renameProvider' },
|
[ms.textDocument_rename] = { 'renameProvider' },
|
||||||
['textDocument/prepareRename'] = { 'renameProvider', 'prepareProvider' },
|
[ms.textDocument_prepareRename] = { 'renameProvider', 'prepareProvider' },
|
||||||
['textDocument/codeAction'] = { 'codeActionProvider' },
|
[ms.textDocument_codeAction] = { 'codeActionProvider' },
|
||||||
['textDocument/codeLens'] = { 'codeLensProvider' },
|
[ms.textDocument_codeLens] = { 'codeLensProvider' },
|
||||||
['codeLens/resolve'] = { 'codeLensProvider', 'resolveProvider' },
|
[ms.codeLens_resolve] = { 'codeLensProvider', 'resolveProvider' },
|
||||||
['codeAction/resolve'] = { 'codeActionProvider', 'resolveProvider' },
|
[ms.codeAction_resolve] = { 'codeActionProvider', 'resolveProvider' },
|
||||||
['workspace/executeCommand'] = { 'executeCommandProvider' },
|
[ms.workspace_executeCommand] = { 'executeCommandProvider' },
|
||||||
['workspace/symbol'] = { 'workspaceSymbolProvider' },
|
[ms.workspace_symbol] = { 'workspaceSymbolProvider' },
|
||||||
['textDocument/references'] = { 'referencesProvider' },
|
[ms.textDocument_references] = { 'referencesProvider' },
|
||||||
['textDocument/rangeFormatting'] = { 'documentRangeFormattingProvider' },
|
[ms.textDocument_rangeFormatting] = { 'documentRangeFormattingProvider' },
|
||||||
['textDocument/formatting'] = { 'documentFormattingProvider' },
|
[ms.textDocument_formatting] = { 'documentFormattingProvider' },
|
||||||
['textDocument/completion'] = { 'completionProvider' },
|
[ms.textDocument_completion] = { 'completionProvider' },
|
||||||
['textDocument/documentHighlight'] = { 'documentHighlightProvider' },
|
[ms.textDocument_documentHighlight] = { 'documentHighlightProvider' },
|
||||||
['textDocument/semanticTokens/full'] = { 'semanticTokensProvider' },
|
[ms.textDocument_semanticTokens_full] = { 'semanticTokensProvider' },
|
||||||
['textDocument/semanticTokens/full/delta'] = { 'semanticTokensProvider' },
|
[ms.textDocument_semanticTokens_full_delta] = { 'semanticTokensProvider' },
|
||||||
['textDocument/inlayHint'] = { 'inlayHintProvider' },
|
[ms.textDocument_inlayHint] = { 'inlayHintProvider' },
|
||||||
['textDocument/diagnostic'] = { 'diagnosticProvider' },
|
[ms.textDocument_diagnostic] = { 'diagnosticProvider' },
|
||||||
['inlayHint/resolve'] = { 'inlayHintProvider', 'resolveProvider' },
|
[ms.inlayHint_resolve] = { 'inlayHintProvider', 'resolveProvider' },
|
||||||
}
|
}
|
||||||
|
|
||||||
-- TODO improve handling of scratch buffers with LSP attached.
|
-- TODO improve handling of scratch buffers with LSP attached.
|
||||||
@@ -583,7 +584,7 @@ do
|
|||||||
local uri = vim.uri_from_bufnr(bufnr)
|
local uri = vim.uri_from_bufnr(bufnr)
|
||||||
for _, client in pairs(state.clients) do
|
for _, client in pairs(state.clients) do
|
||||||
if not client.is_stopped() and lsp.buf_is_attached(bufnr, client.id) then
|
if not client.is_stopped() and lsp.buf_is_attached(bufnr, client.id) then
|
||||||
client.notify('textDocument/didChange', {
|
client.notify(ms.textDocument_didChange, {
|
||||||
textDocument = {
|
textDocument = {
|
||||||
uri = uri,
|
uri = uri,
|
||||||
version = util.buf_versions[bufnr],
|
version = util.buf_versions[bufnr],
|
||||||
@@ -701,7 +702,7 @@ local function text_document_did_open_handler(bufnr, client)
|
|||||||
text = buf_get_full_text(bufnr),
|
text = buf_get_full_text(bufnr),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
client.notify('textDocument/didOpen', params)
|
client.notify(ms.textDocument_didOpen, params)
|
||||||
util.buf_versions[bufnr] = params.textDocument.version
|
util.buf_versions[bufnr] = params.textDocument.version
|
||||||
|
|
||||||
-- Next chance we get, we should re-do the diagnostics
|
-- Next chance we get, we should re-do the diagnostics
|
||||||
@@ -930,17 +931,17 @@ end
|
|||||||
---@param client lsp.Client
|
---@param client lsp.Client
|
||||||
function lsp._set_defaults(client, bufnr)
|
function lsp._set_defaults(client, bufnr)
|
||||||
if
|
if
|
||||||
client.supports_method('textDocument/definition') and is_empty_or_default(bufnr, 'tagfunc')
|
client.supports_method(ms.textDocument_definition) and is_empty_or_default(bufnr, 'tagfunc')
|
||||||
then
|
then
|
||||||
vim.bo[bufnr].tagfunc = 'v:lua.vim.lsp.tagfunc'
|
vim.bo[bufnr].tagfunc = 'v:lua.vim.lsp.tagfunc'
|
||||||
end
|
end
|
||||||
if
|
if
|
||||||
client.supports_method('textDocument/completion') and is_empty_or_default(bufnr, 'omnifunc')
|
client.supports_method(ms.textDocument_completion) and is_empty_or_default(bufnr, 'omnifunc')
|
||||||
then
|
then
|
||||||
vim.bo[bufnr].omnifunc = 'v:lua.vim.lsp.omnifunc'
|
vim.bo[bufnr].omnifunc = 'v:lua.vim.lsp.omnifunc'
|
||||||
end
|
end
|
||||||
if
|
if
|
||||||
client.supports_method('textDocument/rangeFormatting')
|
client.supports_method(ms.textDocument_rangeFormatting)
|
||||||
and is_empty_or_default(bufnr, 'formatprg')
|
and is_empty_or_default(bufnr, 'formatprg')
|
||||||
and is_empty_or_default(bufnr, 'formatexpr')
|
and is_empty_or_default(bufnr, 'formatexpr')
|
||||||
then
|
then
|
||||||
@@ -948,14 +949,14 @@ function lsp._set_defaults(client, bufnr)
|
|||||||
end
|
end
|
||||||
api.nvim_buf_call(bufnr, function()
|
api.nvim_buf_call(bufnr, function()
|
||||||
if
|
if
|
||||||
client.supports_method('textDocument/hover')
|
client.supports_method(ms.textDocument_hover)
|
||||||
and is_empty_or_default(bufnr, 'keywordprg')
|
and is_empty_or_default(bufnr, 'keywordprg')
|
||||||
and vim.fn.maparg('K', 'n', false, false) == ''
|
and vim.fn.maparg('K', 'n', false, false) == ''
|
||||||
then
|
then
|
||||||
vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = bufnr })
|
vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = bufnr })
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
if client.supports_method('textDocument/diagnostic') then
|
if client.supports_method(ms.textDocument_diagnostic) then
|
||||||
lsp.diagnostic._enable(bufnr)
|
lsp.diagnostic._enable(bufnr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -1431,7 +1432,7 @@ function lsp.start_client(config)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if next(config.settings) then
|
if next(config.settings) then
|
||||||
client.notify('workspace/didChangeConfiguration', { settings = config.settings })
|
client.notify(ms.workspace_didChangeConfiguration, { settings = config.settings })
|
||||||
end
|
end
|
||||||
|
|
||||||
if config.on_init then
|
if config.on_init then
|
||||||
@@ -1573,7 +1574,7 @@ function lsp.start_client(config)
|
|||||||
---If it is false, then it will always be false
|
---If it is false, then it will always be false
|
||||||
---(the client has shutdown).
|
---(the client has shutdown).
|
||||||
function client.notify(method, params)
|
function client.notify(method, params)
|
||||||
if method ~= 'textDocument/didChange' then
|
if method ~= ms.textDocument_didChange then
|
||||||
changetracking.flush(client)
|
changetracking.flush(client)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1693,7 +1694,7 @@ function lsp.start_client(config)
|
|||||||
command = command.command,
|
command = command.command,
|
||||||
arguments = command.arguments,
|
arguments = command.arguments,
|
||||||
}
|
}
|
||||||
client.request('workspace/executeCommand', params, handler, context.bufnr)
|
client.request(ms.workspace_executeCommand, params, handler, context.bufnr)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@private
|
---@private
|
||||||
@@ -1763,12 +1764,12 @@ local function text_document_did_save_handler(bufnr)
|
|||||||
local name = api.nvim_buf_get_name(bufnr)
|
local name = api.nvim_buf_get_name(bufnr)
|
||||||
local old_name = changetracking._get_and_set_name(client, bufnr, name)
|
local old_name = changetracking._get_and_set_name(client, bufnr, name)
|
||||||
if old_name and name ~= old_name then
|
if old_name and name ~= old_name then
|
||||||
client.notify('textDocument/didClose', {
|
client.notify(ms.textDocument_didClose, {
|
||||||
textDocument = {
|
textDocument = {
|
||||||
uri = vim.uri_from_fname(old_name),
|
uri = vim.uri_from_fname(old_name),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
client.notify('textDocument/didOpen', {
|
client.notify(ms.textDocument_didOpen, {
|
||||||
textDocument = {
|
textDocument = {
|
||||||
version = 0,
|
version = 0,
|
||||||
uri = uri,
|
uri = uri,
|
||||||
@@ -1784,7 +1785,7 @@ local function text_document_did_save_handler(bufnr)
|
|||||||
if type(save_capability) == 'table' and save_capability.includeText then
|
if type(save_capability) == 'table' and save_capability.includeText then
|
||||||
included_text = text(bufnr)
|
included_text = text(bufnr)
|
||||||
end
|
end
|
||||||
client.notify('textDocument/didSave', {
|
client.notify(ms.textDocument_didSave, {
|
||||||
textDocument = {
|
textDocument = {
|
||||||
uri = uri,
|
uri = uri,
|
||||||
},
|
},
|
||||||
@@ -1835,11 +1836,11 @@ function lsp.buf_attach_client(bufnr, client_id)
|
|||||||
reason = protocol.TextDocumentSaveReason.Manual,
|
reason = protocol.TextDocumentSaveReason.Manual,
|
||||||
}
|
}
|
||||||
if vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'willSave') then
|
if vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'willSave') then
|
||||||
client.notify('textDocument/willSave', params)
|
client.notify(ms.textDocument_willSave, params)
|
||||||
end
|
end
|
||||||
if vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'willSaveWaitUntil') then
|
if vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'willSaveWaitUntil') then
|
||||||
local result, err =
|
local result, err =
|
||||||
client.request_sync('textDocument/willSaveWaitUntil', params, 1000, ctx.buf)
|
client.request_sync(ms.textDocument_willSaveWaitUntil, params, 1000, ctx.buf)
|
||||||
if result and result.result then
|
if result and result.result then
|
||||||
util.apply_text_edits(result.result, ctx.buf, client.offset_encoding)
|
util.apply_text_edits(result.result, ctx.buf, client.offset_encoding)
|
||||||
elseif err then
|
elseif err then
|
||||||
@@ -1865,7 +1866,7 @@ function lsp.buf_attach_client(bufnr, client_id)
|
|||||||
for _, client in ipairs(lsp.get_clients({ bufnr = bufnr })) do
|
for _, client in ipairs(lsp.get_clients({ bufnr = bufnr })) do
|
||||||
changetracking.reset_buf(client, bufnr)
|
changetracking.reset_buf(client, bufnr)
|
||||||
if vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'openClose') then
|
if vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'openClose') then
|
||||||
client.notify('textDocument/didClose', params)
|
client.notify(ms.textDocument_didClose, params)
|
||||||
end
|
end
|
||||||
text_document_did_open_handler(bufnr, client)
|
text_document_did_open_handler(bufnr, client)
|
||||||
end
|
end
|
||||||
@@ -1875,7 +1876,7 @@ function lsp.buf_attach_client(bufnr, client_id)
|
|||||||
for _, client in ipairs(lsp.get_clients({ bufnr = bufnr })) do
|
for _, client in ipairs(lsp.get_clients({ bufnr = bufnr })) do
|
||||||
changetracking.reset_buf(client, bufnr)
|
changetracking.reset_buf(client, bufnr)
|
||||||
if vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'openClose') then
|
if vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'openClose') then
|
||||||
client.notify('textDocument/didClose', params)
|
client.notify(ms.textDocument_didClose, params)
|
||||||
end
|
end
|
||||||
client.attached_buffers[bufnr] = nil
|
client.attached_buffers[bufnr] = nil
|
||||||
end
|
end
|
||||||
@@ -1940,7 +1941,7 @@ function lsp.buf_detach_client(bufnr, client_id)
|
|||||||
if vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'openClose') then
|
if vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'openClose') then
|
||||||
local uri = vim.uri_from_bufnr(bufnr)
|
local uri = vim.uri_from_bufnr(bufnr)
|
||||||
local params = { textDocument = { uri = uri } }
|
local params = { textDocument = { uri = uri } }
|
||||||
client.notify('textDocument/didClose', params)
|
client.notify(ms.textDocument_didClose, params)
|
||||||
end
|
end
|
||||||
|
|
||||||
client.attached_buffers[bufnr] = nil
|
client.attached_buffers[bufnr] = nil
|
||||||
@@ -2294,7 +2295,7 @@ function lsp.omnifunc(findstart, base)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local bufnr = resolve_bufnr()
|
local bufnr = resolve_bufnr()
|
||||||
local clients = lsp.get_clients({ bufnr = bufnr, method = 'textDocument/completion' })
|
local clients = lsp.get_clients({ bufnr = bufnr, method = ms.textDocument_completion })
|
||||||
local remaining = #clients
|
local remaining = #clients
|
||||||
if remaining == 0 then
|
if remaining == 0 then
|
||||||
return findstart == 1 and -1 or {}
|
return findstart == 1 and -1 or {}
|
||||||
@@ -2326,7 +2327,7 @@ function lsp.omnifunc(findstart, base)
|
|||||||
|
|
||||||
for _, client in ipairs(clients) do
|
for _, client in ipairs(clients) do
|
||||||
local params = util.make_position_params(win, client.offset_encoding)
|
local params = util.make_position_params(win, client.offset_encoding)
|
||||||
client.request('textDocument/completion', params, function(err, result)
|
client.request(ms.textDocument_completion, params, function(err, result)
|
||||||
if err then
|
if err then
|
||||||
log.warn(err.message)
|
log.warn(err.message)
|
||||||
end
|
end
|
||||||
@@ -2397,7 +2398,7 @@ function lsp.formatexpr(opts)
|
|||||||
end
|
end
|
||||||
local bufnr = api.nvim_get_current_buf()
|
local bufnr = api.nvim_get_current_buf()
|
||||||
for _, client in pairs(lsp.get_clients({ bufnr = bufnr })) do
|
for _, client in pairs(lsp.get_clients({ bufnr = bufnr })) do
|
||||||
if client.supports_method('textDocument/rangeFormatting') then
|
if client.supports_method(ms.textDocument_rangeFormatting) then
|
||||||
local params = util.make_formatting_params()
|
local params = util.make_formatting_params()
|
||||||
local end_line = vim.fn.getline(end_lnum) --[[@as string]]
|
local end_line = vim.fn.getline(end_lnum) --[[@as string]]
|
||||||
local end_col = util._str_utfindex_enc(end_line, nil, client.offset_encoding)
|
local end_col = util._str_utfindex_enc(end_line, nil, client.offset_encoding)
|
||||||
@@ -2412,7 +2413,7 @@ function lsp.formatexpr(opts)
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
local response =
|
local response =
|
||||||
client.request_sync('textDocument/rangeFormatting', params, timeout_ms, bufnr)
|
client.request_sync(ms.textDocument_rangeFormatting, params, timeout_ms, bufnr)
|
||||||
if response and response.result then
|
if response and response.result then
|
||||||
lsp.util.apply_text_edits(response.result, 0, client.offset_encoding)
|
lsp.util.apply_text_edits(response.result, 0, client.offset_encoding)
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
local bit = require('bit')
|
local bit = require('bit')
|
||||||
local watch = require('vim._watch')
|
local watch = require('vim._watch')
|
||||||
local protocol = require('vim.lsp.protocol')
|
local protocol = require('vim.lsp.protocol')
|
||||||
|
local ms = protocol.Methods
|
||||||
local lpeg = vim.lpeg
|
local lpeg = vim.lpeg
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
@@ -190,7 +191,7 @@ function M.register(reg, ctx)
|
|||||||
|
|
||||||
if not queue_timers[client_id] then
|
if not queue_timers[client_id] then
|
||||||
queue_timers[client_id] = vim.defer_fn(function()
|
queue_timers[client_id] = vim.defer_fn(function()
|
||||||
client.notify('workspace/didChangeWatchedFiles', {
|
client.notify(ms.workspace_didChangeWatchedFiles, {
|
||||||
changes = change_queues[client_id],
|
changes = change_queues[client_id],
|
||||||
})
|
})
|
||||||
queue_timers[client_id] = nil
|
queue_timers[client_id] = nil
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ local api = vim.api
|
|||||||
local validate = vim.validate
|
local validate = vim.validate
|
||||||
local util = require('vim.lsp.util')
|
local util = require('vim.lsp.util')
|
||||||
local npcall = vim.F.npcall
|
local npcall = vim.F.npcall
|
||||||
|
local ms = require('vim.lsp.protocol').Methods
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
@@ -41,7 +42,7 @@ end
|
|||||||
--- window. Calling the function twice will jump into the floating window.
|
--- window. Calling the function twice will jump into the floating window.
|
||||||
function M.hover()
|
function M.hover()
|
||||||
local params = util.make_position_params()
|
local params = util.make_position_params()
|
||||||
request('textDocument/hover', params)
|
request(ms.textDocument_hover, params)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function request_with_options(name, params, options)
|
local function request_with_options(name, params, options)
|
||||||
@@ -64,7 +65,7 @@ end
|
|||||||
--- - on_list: (function) handler for list results. See |lsp-on-list-handler|
|
--- - on_list: (function) handler for list results. See |lsp-on-list-handler|
|
||||||
function M.declaration(options)
|
function M.declaration(options)
|
||||||
local params = util.make_position_params()
|
local params = util.make_position_params()
|
||||||
request_with_options('textDocument/declaration', params, options)
|
request_with_options(ms.textDocument_declaration, params, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Jumps to the definition of the symbol under the cursor.
|
--- Jumps to the definition of the symbol under the cursor.
|
||||||
@@ -74,7 +75,7 @@ end
|
|||||||
--- - on_list: (function) handler for list results. See |lsp-on-list-handler|
|
--- - on_list: (function) handler for list results. See |lsp-on-list-handler|
|
||||||
function M.definition(options)
|
function M.definition(options)
|
||||||
local params = util.make_position_params()
|
local params = util.make_position_params()
|
||||||
request_with_options('textDocument/definition', params, options)
|
request_with_options(ms.textDocument_definition, params, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Jumps to the definition of the type of the symbol under the cursor.
|
--- Jumps to the definition of the type of the symbol under the cursor.
|
||||||
@@ -84,7 +85,7 @@ end
|
|||||||
--- - on_list: (function) handler for list results. See |lsp-on-list-handler|
|
--- - on_list: (function) handler for list results. See |lsp-on-list-handler|
|
||||||
function M.type_definition(options)
|
function M.type_definition(options)
|
||||||
local params = util.make_position_params()
|
local params = util.make_position_params()
|
||||||
request_with_options('textDocument/typeDefinition', params, options)
|
request_with_options(ms.textDocument_typeDefinition, params, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Lists all the implementations for the symbol under the cursor in the
|
--- Lists all the implementations for the symbol under the cursor in the
|
||||||
@@ -94,14 +95,14 @@ end
|
|||||||
--- - on_list: (function) handler for list results. See |lsp-on-list-handler|
|
--- - on_list: (function) handler for list results. See |lsp-on-list-handler|
|
||||||
function M.implementation(options)
|
function M.implementation(options)
|
||||||
local params = util.make_position_params()
|
local params = util.make_position_params()
|
||||||
request_with_options('textDocument/implementation', params, options)
|
request_with_options(ms.textDocument_implementation, params, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Displays signature information about the symbol under the cursor in a
|
--- Displays signature information about the symbol under the cursor in a
|
||||||
--- floating window.
|
--- floating window.
|
||||||
function M.signature_help()
|
function M.signature_help()
|
||||||
local params = util.make_position_params()
|
local params = util.make_position_params()
|
||||||
request('textDocument/signatureHelp', params)
|
request(ms.textDocument_signatureHelp, params)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Retrieves the completion items at the current cursor position. Can only be
|
--- Retrieves the completion items at the current cursor position. Can only be
|
||||||
@@ -115,7 +116,7 @@ end
|
|||||||
function M.completion(context)
|
function M.completion(context)
|
||||||
local params = util.make_position_params()
|
local params = util.make_position_params()
|
||||||
params.context = context
|
params.context = context
|
||||||
return request('textDocument/completion', params)
|
return request(ms.textDocument_completion, params)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param bufnr integer
|
---@param bufnr integer
|
||||||
@@ -199,7 +200,7 @@ function M.format(options)
|
|||||||
if not range and mode == 'v' or mode == 'V' then
|
if not range and mode == 'v' or mode == 'V' then
|
||||||
range = range_from_selection(bufnr, mode)
|
range = range_from_selection(bufnr, mode)
|
||||||
end
|
end
|
||||||
local method = range and 'textDocument/rangeFormatting' or 'textDocument/formatting'
|
local method = range and ms.textDocument_rangeFormatting or ms.textDocument_formatting
|
||||||
|
|
||||||
local clients = vim.lsp.get_clients({
|
local clients = vim.lsp.get_clients({
|
||||||
id = options.id,
|
id = options.id,
|
||||||
@@ -270,7 +271,7 @@ function M.rename(new_name, options)
|
|||||||
bufnr = bufnr,
|
bufnr = bufnr,
|
||||||
name = options.name,
|
name = options.name,
|
||||||
-- Clients must at least support rename, prepareRename is optional
|
-- Clients must at least support rename, prepareRename is optional
|
||||||
method = 'textDocument/rename',
|
method = ms.textDocument_rename,
|
||||||
})
|
})
|
||||||
if options.filter then
|
if options.filter then
|
||||||
clients = vim.tbl_filter(options.filter, clients)
|
clients = vim.tbl_filter(options.filter, clients)
|
||||||
@@ -305,17 +306,17 @@ function M.rename(new_name, options)
|
|||||||
local function rename(name)
|
local function rename(name)
|
||||||
local params = util.make_position_params(win, client.offset_encoding)
|
local params = util.make_position_params(win, client.offset_encoding)
|
||||||
params.newName = name
|
params.newName = name
|
||||||
local handler = client.handlers['textDocument/rename']
|
local handler = client.handlers[ms.textDocument_rename]
|
||||||
or vim.lsp.handlers['textDocument/rename']
|
or vim.lsp.handlers[ms.textDocument_rename]
|
||||||
client.request('textDocument/rename', params, function(...)
|
client.request(ms.textDocument_rename, params, function(...)
|
||||||
handler(...)
|
handler(...)
|
||||||
try_use_client(next(clients, idx))
|
try_use_client(next(clients, idx))
|
||||||
end, bufnr)
|
end, bufnr)
|
||||||
end
|
end
|
||||||
|
|
||||||
if client.supports_method('textDocument/prepareRename') then
|
if client.supports_method(ms.textDocument_prepareRename) then
|
||||||
local params = util.make_position_params(win, client.offset_encoding)
|
local params = util.make_position_params(win, client.offset_encoding)
|
||||||
client.request('textDocument/prepareRename', params, function(err, result)
|
client.request(ms.textDocument_prepareRename, params, function(err, result)
|
||||||
if err or result == nil then
|
if err or result == nil then
|
||||||
if next(clients, idx) then
|
if next(clients, idx) then
|
||||||
try_use_client(next(clients, idx))
|
try_use_client(next(clients, idx))
|
||||||
@@ -354,7 +355,7 @@ function M.rename(new_name, options)
|
|||||||
end, bufnr)
|
end, bufnr)
|
||||||
else
|
else
|
||||||
assert(
|
assert(
|
||||||
client.supports_method('textDocument/rename'),
|
client.supports_method(ms.textDocument_rename),
|
||||||
'Client must support textDocument/rename'
|
'Client must support textDocument/rename'
|
||||||
)
|
)
|
||||||
if new_name then
|
if new_name then
|
||||||
@@ -390,7 +391,7 @@ function M.references(context, options)
|
|||||||
params.context = context or {
|
params.context = context or {
|
||||||
includeDeclaration = true,
|
includeDeclaration = true,
|
||||||
}
|
}
|
||||||
request_with_options('textDocument/references', params, options)
|
request_with_options(ms.textDocument_references, params, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Lists all symbols in the current buffer in the quickfix window.
|
--- Lists all symbols in the current buffer in the quickfix window.
|
||||||
@@ -399,7 +400,7 @@ end
|
|||||||
--- - on_list: (function) handler for list results. See |lsp-on-list-handler|
|
--- - on_list: (function) handler for list results. See |lsp-on-list-handler|
|
||||||
function M.document_symbol(options)
|
function M.document_symbol(options)
|
||||||
local params = { textDocument = util.make_text_document_params() }
|
local params = { textDocument = util.make_text_document_params() }
|
||||||
request_with_options('textDocument/documentSymbol', params, options)
|
request_with_options(ms.textDocument_documentSymbol, params, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function pick_call_hierarchy_item(call_hierarchy_items)
|
local function pick_call_hierarchy_item(call_hierarchy_items)
|
||||||
@@ -423,7 +424,7 @@ end
|
|||||||
|
|
||||||
local function call_hierarchy(method)
|
local function call_hierarchy(method)
|
||||||
local params = util.make_position_params()
|
local params = util.make_position_params()
|
||||||
request('textDocument/prepareCallHierarchy', params, function(err, result, ctx)
|
request(ms.textDocument_prepareCallHierarchy, params, function(err, result, ctx)
|
||||||
if err then
|
if err then
|
||||||
vim.notify(err.message, vim.log.levels.WARN)
|
vim.notify(err.message, vim.log.levels.WARN)
|
||||||
return
|
return
|
||||||
@@ -496,7 +497,7 @@ function M.add_workspace_folder(workspace_folder)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not found then
|
if not found then
|
||||||
client.notify('workspace/didChangeWorkspaceFolders', params)
|
client.notify(ms.workspace_didChangeWorkspaceFolders, params)
|
||||||
if not client.workspace_folders then
|
if not client.workspace_folders then
|
||||||
client.workspace_folders = {}
|
client.workspace_folders = {}
|
||||||
end
|
end
|
||||||
@@ -524,7 +525,7 @@ function M.remove_workspace_folder(workspace_folder)
|
|||||||
for _, client in pairs(vim.lsp.get_clients({ bufnr = bufnr })) do
|
for _, client in pairs(vim.lsp.get_clients({ bufnr = bufnr })) do
|
||||||
for idx, folder in pairs(client.workspace_folders) do
|
for idx, folder in pairs(client.workspace_folders) do
|
||||||
if folder.name == workspace_folder then
|
if folder.name == workspace_folder then
|
||||||
client.notify('workspace/didChangeWorkspaceFolders', params)
|
client.notify(ms.workspace_didChangeWorkspaceFolders, params)
|
||||||
client.workspace_folders[idx] = nil
|
client.workspace_folders[idx] = nil
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -548,7 +549,7 @@ function M.workspace_symbol(query, options)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
local params = { query = query }
|
local params = { query = query }
|
||||||
request_with_options('workspace/symbol', params, options)
|
request_with_options(ms.workspace_symbol, params, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Send request to the server to resolve document highlights for the current
|
--- Send request to the server to resolve document highlights for the current
|
||||||
@@ -567,7 +568,7 @@ end
|
|||||||
--- |hl-LspReferenceWrite|
|
--- |hl-LspReferenceWrite|
|
||||||
function M.document_highlight()
|
function M.document_highlight()
|
||||||
local params = util.make_position_params()
|
local params = util.make_position_params()
|
||||||
request('textDocument/documentHighlight', params)
|
request(ms.textDocument_documentHighlight, params)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Removes document highlights from current buffer.
|
--- Removes document highlights from current buffer.
|
||||||
@@ -655,7 +656,7 @@ local function on_code_action_results(results, ctx, options)
|
|||||||
local client = vim.lsp.get_client_by_id(action_tuple[1])
|
local client = vim.lsp.get_client_by_id(action_tuple[1])
|
||||||
local action = action_tuple[2]
|
local action = action_tuple[2]
|
||||||
|
|
||||||
local reg = client.dynamic_capabilities:get('textDocument/codeAction', { bufnr = ctx.bufnr })
|
local reg = client.dynamic_capabilities:get(ms.textDocument_codeAction, { bufnr = ctx.bufnr })
|
||||||
|
|
||||||
local supports_resolve = vim.tbl_get(reg or {}, 'registerOptions', 'resolveProvider')
|
local supports_resolve = vim.tbl_get(reg or {}, 'registerOptions', 'resolveProvider')
|
||||||
or client.supports_method('codeAction/resolve')
|
or client.supports_method('codeAction/resolve')
|
||||||
@@ -694,9 +695,8 @@ end
|
|||||||
--- with all aggregated results
|
--- with all aggregated results
|
||||||
local function code_action_request(params, options)
|
local function code_action_request(params, options)
|
||||||
local bufnr = api.nvim_get_current_buf()
|
local bufnr = api.nvim_get_current_buf()
|
||||||
local method = 'textDocument/codeAction'
|
vim.lsp.buf_request_all(bufnr, ms.textDocument_codeAction, params, function(results)
|
||||||
vim.lsp.buf_request_all(bufnr, method, params, function(results)
|
local ctx = { bufnr = bufnr, method = ms.textDocument_codeAction, params = params }
|
||||||
local ctx = { bufnr = bufnr, method = method, params = params }
|
|
||||||
on_code_action_results(results, ctx, options)
|
on_code_action_results(results, ctx, options)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
@@ -776,7 +776,7 @@ function M.execute_command(command_params)
|
|||||||
arguments = command_params.arguments,
|
arguments = command_params.arguments,
|
||||||
workDoneToken = command_params.workDoneToken,
|
workDoneToken = command_params.workDoneToken,
|
||||||
}
|
}
|
||||||
request('workspace/executeCommand', command_params)
|
request(ms.workspace_executeCommand, command_params)
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
local util = require('vim.lsp.util')
|
local util = require('vim.lsp.util')
|
||||||
local log = require('vim.lsp.log')
|
local log = require('vim.lsp.log')
|
||||||
|
local ms = require('vim.lsp.protocol').Methods
|
||||||
local api = vim.api
|
local api = vim.api
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
@@ -33,7 +34,7 @@ local function execute_lens(lens, bufnr, client_id)
|
|||||||
local client = vim.lsp.get_client_by_id(client_id)
|
local client = vim.lsp.get_client_by_id(client_id)
|
||||||
assert(client, 'Client is required to execute lens, client_id=' .. client_id)
|
assert(client, 'Client is required to execute lens, client_id=' .. client_id)
|
||||||
client._exec_cmd(lens.command, { bufnr = bufnr }, function(...)
|
client._exec_cmd(lens.command, { bufnr = bufnr }, function(...)
|
||||||
vim.lsp.handlers['workspace/executeCommand'](...)
|
vim.lsp.handlers[ms.workspace_executeCommand](...)
|
||||||
M.refresh()
|
M.refresh()
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
@@ -267,7 +268,7 @@ function M.refresh()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
active_refreshes[bufnr] = true
|
active_refreshes[bufnr] = true
|
||||||
vim.lsp.buf_request(0, 'textDocument/codeLens', params, M.on_codelens)
|
vim.lsp.buf_request(0, ms.textDocument_codeLens, params, M.on_codelens)
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
local util = require('vim.lsp.util')
|
local util = require('vim.lsp.util')
|
||||||
local protocol = require('vim.lsp.protocol')
|
local protocol = require('vim.lsp.protocol')
|
||||||
|
local ms = protocol.Methods
|
||||||
|
|
||||||
local api = vim.api
|
local api = vim.api
|
||||||
|
|
||||||
@@ -422,13 +423,13 @@ function M._enable(bufnr)
|
|||||||
buffer = bufnr,
|
buffer = bufnr,
|
||||||
callback = function(opts)
|
callback = function(opts)
|
||||||
if
|
if
|
||||||
opts.data.method ~= 'textDocument/didChange'
|
opts.data.method ~= ms.textDocument_didChange
|
||||||
and opts.data.method ~= 'textDocument/didOpen'
|
and opts.data.method ~= ms.textDocument_didOpen
|
||||||
then
|
then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if bufstates[bufnr] and bufstates[bufnr].enabled then
|
if bufstates[bufnr] and bufstates[bufnr].enabled then
|
||||||
util._refresh('textDocument/diagnostic', { bufnr = bufnr, only_visible = true })
|
util._refresh(ms.textDocument_diagnostic, { bufnr = bufnr, only_visible = true })
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
group = augroup,
|
group = augroup,
|
||||||
@@ -437,7 +438,7 @@ function M._enable(bufnr)
|
|||||||
api.nvim_buf_attach(bufnr, false, {
|
api.nvim_buf_attach(bufnr, false, {
|
||||||
on_reload = function()
|
on_reload = function()
|
||||||
if bufstates[bufnr] and bufstates[bufnr].enabled then
|
if bufstates[bufnr] and bufstates[bufnr].enabled then
|
||||||
util._refresh('textDocument/diagnostic', { bufnr = bufnr })
|
util._refresh(ms.textDocument_diagnostic, { bufnr = bufnr })
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
on_detach = function()
|
on_detach = function()
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
local log = require('vim.lsp.log')
|
local log = require('vim.lsp.log')
|
||||||
local protocol = require('vim.lsp.protocol')
|
local protocol = require('vim.lsp.protocol')
|
||||||
|
local ms = protocol.Methods
|
||||||
local util = require('vim.lsp.util')
|
local util = require('vim.lsp.util')
|
||||||
local api = vim.api
|
local api = vim.api
|
||||||
|
|
||||||
@@ -15,14 +16,14 @@ local function err_message(...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_executeCommand
|
--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
|
-- Error handling is done implicitly by wrapping all handlers; see end of this file
|
||||||
end
|
end
|
||||||
|
|
||||||
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#progress
|
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#progress
|
||||||
---@param result lsp.ProgressParams
|
---@param result lsp.ProgressParams
|
||||||
---@param ctx lsp.HandlerContext
|
---@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)
|
local client = vim.lsp.get_client_by_id(ctx.client_id)
|
||||||
if not client then
|
if not client then
|
||||||
err_message('LSP[id=', tostring(ctx.client_id), '] client has shut down during progress update')
|
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
|
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_workDoneProgress_create
|
||||||
---@param result lsp.WorkDoneProgressCreateParams
|
---@param result lsp.WorkDoneProgressCreateParams
|
||||||
---@param ctx lsp.HandlerContext
|
---@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)
|
local client = vim.lsp.get_client_by_id(ctx.client_id)
|
||||||
if not client then
|
if not client then
|
||||||
err_message('LSP[id=', tostring(ctx.client_id), '] client has shut down during progress update')
|
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
|
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_showMessageRequest
|
||||||
---@param result lsp.ShowMessageRequestParams
|
---@param result lsp.ShowMessageRequestParams
|
||||||
M['window/showMessageRequest'] = function(_, result)
|
M[ms.window_showMessageRequest] = function(_, result)
|
||||||
local actions = result.actions or {}
|
local actions = result.actions or {}
|
||||||
local co, is_main = coroutine.running()
|
local co, is_main = coroutine.running()
|
||||||
if co and not is_main then
|
if co and not is_main then
|
||||||
@@ -105,7 +106,7 @@ M['window/showMessageRequest'] = function(_, result)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#client_registerCapability
|
--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
|
local client_id = ctx.client_id
|
||||||
---@type lsp.Client
|
---@type lsp.Client
|
||||||
local client = vim.lsp.get_client_by_id(client_id)
|
local client = vim.lsp.get_client_by_id(client_id)
|
||||||
@@ -118,7 +119,7 @@ M['client/registerCapability'] = function(_, result, ctx)
|
|||||||
---@type string[]
|
---@type string[]
|
||||||
local unsupported = {}
|
local unsupported = {}
|
||||||
for _, reg in ipairs(result.registrations) do
|
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)
|
require('vim.lsp._watchfiles').register(reg, ctx)
|
||||||
elseif not client.dynamic_capabilities:supports_registration(reg.method) then
|
elseif not client.dynamic_capabilities:supports_registration(reg.method) then
|
||||||
unsupported[#unsupported + 1] = reg.method
|
unsupported[#unsupported + 1] = reg.method
|
||||||
@@ -136,13 +137,13 @@ M['client/registerCapability'] = function(_, result, ctx)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#client_unregisterCapability
|
--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_id = ctx.client_id
|
||||||
local client = vim.lsp.get_client_by_id(client_id)
|
local client = vim.lsp.get_client_by_id(client_id)
|
||||||
client.dynamic_capabilities:unregister(result.unregisterations)
|
client.dynamic_capabilities:unregister(result.unregisterations)
|
||||||
|
|
||||||
for _, unreg in ipairs(result.unregisterations) do
|
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)
|
require('vim.lsp._watchfiles').unregister(unreg, ctx)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -150,7 +151,7 @@ M['client/unregisterCapability'] = function(_, result, ctx)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_applyEdit
|
--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(
|
assert(
|
||||||
workspace_edit,
|
workspace_edit,
|
||||||
'workspace/applyEdit must be called with `ApplyWorkspaceEditParams`. Server is violating the specification'
|
'workspace/applyEdit must be called with `ApplyWorkspaceEditParams`. Server is violating the specification'
|
||||||
@@ -170,7 +171,7 @@ M['workspace/applyEdit'] = function(_, workspace_edit, ctx)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_configuration
|
--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_id = ctx.client_id
|
||||||
local client = vim.lsp.get_client_by_id(client_id)
|
local client = vim.lsp.get_client_by_id(client_id)
|
||||||
if not client then
|
if not client then
|
||||||
@@ -200,7 +201,7 @@ M['workspace/configuration'] = function(_, result, ctx)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_workspaceFolders
|
--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_id = ctx.client_id
|
||||||
local client = vim.lsp.get_client_by_id(client_id)
|
local client = vim.lsp.get_client_by_id(client_id)
|
||||||
if not client then
|
if not client then
|
||||||
@@ -210,24 +211,24 @@ M['workspace/workspaceFolders'] = function(_, _, ctx)
|
|||||||
return client.workspace_folders or vim.NIL
|
return client.workspace_folders or vim.NIL
|
||||||
end
|
end
|
||||||
|
|
||||||
M['textDocument/publishDiagnostics'] = function(...)
|
M[ms.textDocument_publishDiagnostics] = function(...)
|
||||||
return require('vim.lsp.diagnostic').on_publish_diagnostics(...)
|
return require('vim.lsp.diagnostic').on_publish_diagnostics(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
M['textDocument/diagnostic'] = function(...)
|
M[ms.textDocument_diagnostic] = function(...)
|
||||||
return require('vim.lsp.diagnostic').on_diagnostic(...)
|
return require('vim.lsp.diagnostic').on_diagnostic(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
M['textDocument/codeLens'] = function(...)
|
M[ms.textDocument_codeLens] = function(...)
|
||||||
return require('vim.lsp.codelens').on_codelens(...)
|
return require('vim.lsp.codelens').on_codelens(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
M['textDocument/inlayHint'] = function(...)
|
M[ms.textDocument_inlayHint] = function(...)
|
||||||
return require('vim.lsp.inlay_hint').on_inlayhint(...)
|
return require('vim.lsp.inlay_hint').on_inlayhint(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
|
--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
|
if not result or vim.tbl_isempty(result) then
|
||||||
vim.notify('No references found')
|
vim.notify('No references found')
|
||||||
else
|
else
|
||||||
@@ -283,7 +284,7 @@ local function response_to_list(map_result, entity, title_fn)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_documentSymbol
|
--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,
|
util.symbols_to_items,
|
||||||
'document symbols',
|
'document symbols',
|
||||||
function(ctx)
|
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
|
--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)
|
return string.format("Symbols matching '%s'", ctx.params.query)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_rename
|
--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
|
if not result then
|
||||||
vim.notify("Language server couldn't provide rename result", vim.log.levels.INFO)
|
vim.notify("Language server couldn't provide rename result", vim.log.levels.INFO)
|
||||||
return
|
return
|
||||||
@@ -308,7 +309,7 @@ M['textDocument/rename'] = function(_, result, ctx, _)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_rangeFormatting
|
--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
|
if not result then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -317,7 +318,7 @@ M['textDocument/rangeFormatting'] = function(_, result, ctx, _)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_formatting
|
--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
|
if not result then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -326,7 +327,7 @@ M['textDocument/formatting'] = function(_, result, ctx, _)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion
|
--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
|
if vim.tbl_isempty(result or {}) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -380,7 +381,7 @@ function M.hover(_, result, ctx, config)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_hover
|
--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.
|
--- Jumps to a location. Used as a handler for multiple LSP methods.
|
||||||
---@param _ nil not used
|
---@param _ nil not used
|
||||||
@@ -420,13 +421,13 @@ local function location_handler(_, result, ctx, config)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_declaration
|
--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
|
--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
|
--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
|
--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".
|
--- |lsp-handler| for the method "textDocument/signatureHelp".
|
||||||
--- The active parameter is highlighted with |hl-LspSignatureActiveParameter|.
|
--- The active parameter is highlighted with |hl-LspSignatureActiveParameter|.
|
||||||
@@ -477,10 +478,10 @@ function M.signature_help(_, result, ctx, config)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_signatureHelp
|
--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
|
--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
|
if not result then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -523,13 +524,13 @@ local make_call_hierarchy_handler = function(direction)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#callHierarchy_incomingCalls
|
--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
|
--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
|
--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_type = result.type
|
||||||
local message = result.message
|
local message = result.message
|
||||||
local client_id = ctx.client_id
|
local client_id = ctx.client_id
|
||||||
@@ -551,7 +552,7 @@ M['window/logMessage'] = function(_, result, ctx, _)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_showMessage
|
--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_type = result.type
|
||||||
local message = result.message
|
local message = result.message
|
||||||
local client_id = ctx.client_id
|
local client_id = ctx.client_id
|
||||||
@@ -570,7 +571,7 @@ M['window/showMessage'] = function(_, result, ctx, _)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_showDocument
|
--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
|
local uri = result.uri
|
||||||
|
|
||||||
if result.external then
|
if result.external then
|
||||||
@@ -611,7 +612,7 @@ M['window/showDocument'] = function(_, result, ctx, _)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@see https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_inlayHint_refresh
|
---@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)
|
return require('vim.lsp.inlay_hint').on_refresh(err, result, ctx, config)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
local util = require('vim.lsp.util')
|
local util = require('vim.lsp.util')
|
||||||
local log = require('vim.lsp.log')
|
local log = require('vim.lsp.log')
|
||||||
|
local ms = require('vim.lsp.protocol').Methods
|
||||||
local api = vim.api
|
local api = vim.api
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
@@ -87,7 +88,7 @@ function M.on_refresh(err, _, ctx, _)
|
|||||||
if api.nvim_win_get_buf(winid) == bufnr then
|
if api.nvim_win_get_buf(winid) == bufnr then
|
||||||
local bufstate = bufstates[bufnr]
|
local bufstate = bufstates[bufnr]
|
||||||
if bufstate then
|
if bufstate then
|
||||||
util._refresh('textDocument/inlayHint', { bufnr = bufnr })
|
util._refresh(ms.textDocument_inlayHint, { bufnr = bufnr })
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -143,24 +144,24 @@ local function enable(bufnr)
|
|||||||
buffer = bufnr,
|
buffer = bufnr,
|
||||||
callback = function(opts)
|
callback = function(opts)
|
||||||
if
|
if
|
||||||
opts.data.method ~= 'textDocument/didChange'
|
opts.data.method ~= ms.textDocument_didChange
|
||||||
and opts.data.method ~= 'textDocument/didOpen'
|
and opts.data.method ~= ms.textDocument_didOpen
|
||||||
then
|
then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if bufstates[bufnr] and bufstates[bufnr].enabled then
|
if bufstates[bufnr] and bufstates[bufnr].enabled then
|
||||||
util._refresh('textDocument/inlayHint', { bufnr = bufnr })
|
util._refresh(ms.textDocument_inlayHint, { bufnr = bufnr })
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
group = augroup,
|
group = augroup,
|
||||||
})
|
})
|
||||||
util._refresh('textDocument/inlayHint', { bufnr = bufnr })
|
util._refresh(ms.textDocument_inlayHint, { bufnr = bufnr })
|
||||||
api.nvim_buf_attach(bufnr, false, {
|
api.nvim_buf_attach(bufnr, false, {
|
||||||
on_reload = function(_, cb_bufnr)
|
on_reload = function(_, cb_bufnr)
|
||||||
clear(cb_bufnr)
|
clear(cb_bufnr)
|
||||||
if bufstates[cb_bufnr] and bufstates[cb_bufnr].enabled then
|
if bufstates[cb_bufnr] and bufstates[cb_bufnr].enabled then
|
||||||
bufstates[cb_bufnr].applied = {}
|
bufstates[cb_bufnr].applied = {}
|
||||||
util._refresh('textDocument/inlayHint', { bufnr = cb_bufnr })
|
util._refresh(ms.textDocument_inlayHint, { bufnr = cb_bufnr })
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
on_detach = function(_, cb_bufnr)
|
on_detach = function(_, cb_bufnr)
|
||||||
@@ -176,7 +177,7 @@ local function enable(bufnr)
|
|||||||
})
|
})
|
||||||
else
|
else
|
||||||
bufstate.enabled = true
|
bufstate.enabled = true
|
||||||
util._refresh('textDocument/inlayHint', { bufnr = bufnr })
|
util._refresh(ms.textDocument_inlayHint, { bufnr = bufnr })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
local api = vim.api
|
local api = vim.api
|
||||||
local bit = require('bit')
|
local bit = require('bit')
|
||||||
local handlers = require('vim.lsp.handlers')
|
local handlers = require('vim.lsp.handlers')
|
||||||
|
local ms = require('vim.lsp.protocol').Methods
|
||||||
local util = require('vim.lsp.util')
|
local util = require('vim.lsp.util')
|
||||||
local uv = vim.uv
|
local uv = vim.uv
|
||||||
|
|
||||||
@@ -292,7 +293,7 @@ function STHighlighter:send_request()
|
|||||||
local hasEditProvider = type(spec) == 'table' and spec.delta
|
local hasEditProvider = type(spec) == 'table' and spec.delta
|
||||||
|
|
||||||
local params = { textDocument = util.make_text_document_params(self.bufnr) }
|
local params = { textDocument = util.make_text_document_params(self.bufnr) }
|
||||||
local method = 'textDocument/semanticTokens/full'
|
local method = ms.textDocument_semanticTokens_full
|
||||||
|
|
||||||
if hasEditProvider and current_result.result_id then
|
if hasEditProvider and current_result.result_id then
|
||||||
method = method .. '/delta'
|
method = method .. '/delta'
|
||||||
@@ -755,7 +756,7 @@ end
|
|||||||
--- the BufWinEnter event should take care of it next time it's displayed.
|
--- the BufWinEnter event should take care of it next time it's displayed.
|
||||||
---
|
---
|
||||||
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#semanticTokens_refreshRequest
|
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#semanticTokens_refreshRequest
|
||||||
handlers['workspace/semanticTokens/refresh'] = function(err, _, ctx)
|
handlers[ms.workspace_semanticTokens_refresh] = function(err, _, ctx)
|
||||||
if err then
|
if err then
|
||||||
return vim.NIL
|
return vim.NIL
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
local lsp = vim.lsp
|
local lsp = vim.lsp
|
||||||
local util = lsp.util
|
local util = lsp.util
|
||||||
|
local ms = lsp.protocol.Methods
|
||||||
|
|
||||||
local function mk_tag_item(name, range, uri, offset_encoding)
|
local function mk_tag_item(name, range, uri, offset_encoding)
|
||||||
local bufnr = vim.uri_to_bufnr(uri)
|
local bufnr = vim.uri_to_bufnr(uri)
|
||||||
@@ -14,7 +15,7 @@ end
|
|||||||
|
|
||||||
local function query_definition(pattern)
|
local function query_definition(pattern)
|
||||||
local params = util.make_position_params()
|
local params = util.make_position_params()
|
||||||
local results_by_client, err = lsp.buf_request_sync(0, 'textDocument/definition', params, 1000)
|
local results_by_client, err = lsp.buf_request_sync(0, ms.textDocument_definition, params, 1000)
|
||||||
if err then
|
if err then
|
||||||
return {}
|
return {}
|
||||||
end
|
end
|
||||||
@@ -42,7 +43,7 @@ end
|
|||||||
|
|
||||||
local function query_workspace_symbols(pattern)
|
local function query_workspace_symbols(pattern)
|
||||||
local results_by_client, err =
|
local results_by_client, err =
|
||||||
lsp.buf_request_sync(0, 'workspace/symbol', { query = pattern }, 1000)
|
lsp.buf_request_sync(0, ms.workspace_symbol, { query = pattern }, 1000)
|
||||||
if err then
|
if err then
|
||||||
return {}
|
return {}
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user