fix(lsp): deprecate vim.lsp.protocol.Methods (#35998)

This commit is contained in:
Maria Solano
2025-10-04 21:09:13 -07:00
committed by GitHub
parent 2f35221774
commit b938638d2d
23 changed files with 179 additions and 200 deletions

View File

@@ -3045,12 +3045,6 @@ make_client_capabilities()
Return: ~ Return: ~
(`lsp.ClientCapabilities`) (`lsp.ClientCapabilities`)
Methods *vim.lsp.protocol.Methods*
LSP method names.
See also: ~
• https://microsoft.github.io/language-server-protocol/specification/#metaModel
*vim.lsp.protocol.resolve_capabilities()* *vim.lsp.protocol.resolve_capabilities()*
resolve_capabilities({server_capabilities}) resolve_capabilities({server_capabilities})
Creates a normalized object describing LSP server capabilities. Creates a normalized object describing LSP server capabilities.

View File

@@ -228,7 +228,7 @@ The following new features were added.
mappings are applied. mappings are applied.
• LSP: • LSP:
• LSP method names are available in |vim.lsp.protocol.Methods|. • LSP method names are available in `vim.lsp.protocol.Methods`.
• Implemented LSP inlay hints: |lsp-inlay_hint| • Implemented LSP inlay hints: |lsp-inlay_hint|
https://microsoft.github.io/language-server-protocol/specification/#textDocument_inlayHint https://microsoft.github.io/language-server-protocol/specification/#textDocument_inlayHint
• Implemented pull diagnostic textDocument/diagnostic: |vim.lsp.diagnostic.on_diagnostic()| • Implemented pull diagnostic textDocument/diagnostic: |vim.lsp.diagnostic.on_diagnostic()|

View File

@@ -28,7 +28,6 @@ local lsp = vim._defer_require('vim.lsp', {
local log = lsp.log local log = lsp.log
local protocol = lsp.protocol local protocol = lsp.protocol
local ms = protocol.Methods
local util = lsp.util local util = lsp.util
local changetracking = lsp._changetracking local changetracking = lsp._changetracking
@@ -37,10 +36,10 @@ local changetracking = lsp._changetracking
lsp.rpc_response_error = lsp.rpc.rpc_response_error lsp.rpc_response_error = lsp.rpc.rpc_response_error
lsp._resolve_to_request = { lsp._resolve_to_request = {
[ms.codeAction_resolve] = ms.textDocument_codeAction, ['codeAction/resolve'] = 'textDocument/codeAction',
[ms.codeLens_resolve] = ms.textDocument_codeLens, ['codeLens/resolve'] = 'textDocument/codeLens',
[ms.documentLink_resolve] = ms.textDocument_documentLink, ['documentLink/resolve'] = 'textDocument/documentLink',
[ms.inlayHint_resolve] = ms.textDocument_inlayHint, ['inlayHint/resolve'] = 'textDocument/inlayHint',
} }
-- TODO improve handling of scratch buffers with LSP attached. -- TODO improve handling of scratch buffers with LSP attached.
@@ -764,17 +763,17 @@ end
---@param bufnr integer ---@param bufnr integer
function lsp._set_defaults(client, bufnr) function lsp._set_defaults(client, bufnr)
if if
client:supports_method(ms.textDocument_definition) and is_empty_or_default(bufnr, 'tagfunc') client:supports_method('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(ms.textDocument_completion) and is_empty_or_default(bufnr, 'omnifunc') client:supports_method('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(ms.textDocument_rangeFormatting) client:supports_method('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
@@ -782,7 +781,7 @@ function lsp._set_defaults(client, bufnr)
end end
vim._with({ buf = bufnr }, function() vim._with({ buf = bufnr }, function()
if if
client:supports_method(ms.textDocument_hover) client:supports_method('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
@@ -791,7 +790,7 @@ function lsp._set_defaults(client, bufnr)
end, { buffer = bufnr, desc = 'vim.lsp.buf.hover()' }) end, { buffer = bufnr, desc = 'vim.lsp.buf.hover()' })
end end
end) end)
if client:supports_method(ms.textDocument_diagnostic) then if client:supports_method('textDocument/diagnostic') then
lsp.diagnostic._enable(bufnr) lsp.diagnostic._enable(bufnr)
end end
end end
@@ -818,12 +817,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(ms.textDocument_didClose, { client:notify('textDocument/didClose', {
textDocument = { textDocument = {
uri = vim.uri_from_fname(old_name), uri = vim.uri_from_fname(old_name),
}, },
}) })
client:notify(ms.textDocument_didOpen, { client:notify('textDocument/didOpen', {
textDocument = { textDocument = {
version = 0, version = 0,
uri = uri, uri = uri,
@@ -839,7 +838,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(ms.textDocument_didSave, { client:notify('textDocument/didSave', {
textDocument = { textDocument = {
uri = uri, uri = uri,
}, },
@@ -874,12 +873,12 @@ local function buf_attach(bufnr)
}, },
reason = protocol.TextDocumentSaveReason.Manual, ---@type integer reason = protocol.TextDocumentSaveReason.Manual, ---@type integer
} }
if client:supports_method(ms.textDocument_willSave) then if client:supports_method('textDocument/willSave') then
client:notify(ms.textDocument_willSave, params) client:notify('textDocument/willSave', params)
end end
if client:supports_method(ms.textDocument_willSaveWaitUntil) then if client:supports_method('textDocument/willSaveWaitUntil') then
local result, err = local result, err =
client:request_sync(ms.textDocument_willSaveWaitUntil, params, 1000, ctx.buf) client:request_sync('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
@@ -913,8 +912,8 @@ local function buf_attach(bufnr)
local params = { textDocument = { uri = uri } } local params = { textDocument = { uri = uri } }
for _, client in ipairs(clients) do for _, client in ipairs(clients) do
changetracking.reset_buf(client, bufnr) changetracking.reset_buf(client, bufnr)
if client:supports_method(ms.textDocument_didClose) then if client:supports_method('textDocument/didClose') then
client:notify(ms.textDocument_didClose, params) client:notify('textDocument/didClose', params)
end end
end end
for _, client in ipairs(clients) do for _, client in ipairs(clients) do
@@ -1371,7 +1370,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(ms.textDocument_rangeFormatting) then if client:supports_method('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 = vim.str_utfindex(end_line, client.offset_encoding) local end_col = vim.str_utfindex(end_line, client.offset_encoding)
@@ -1387,7 +1386,7 @@ function lsp.formatexpr(opts)
}, },
} }
local response = local response =
client:request_sync(ms.textDocument_rangeFormatting, params, timeout_ms, bufnr) client:request_sync('textDocument/rangeFormatting', params, timeout_ms, bufnr)
if response and response.result then if response and response.result then
util.apply_text_edits(response.result, bufnr, client.offset_encoding) util.apply_text_edits(response.result, bufnr, client.offset_encoding)
return 0 return 0

View File

@@ -274,7 +274,7 @@ local function send_changes(bufnr, sync_kind, state, buf_state)
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 vim.lsp.buf_is_attached(bufnr, client.id) then if not client:is_stopped() and vim.lsp.buf_is_attached(bufnr, client.id) then
client:notify(protocol.Methods.textDocument_didChange, { client:notify('textDocument/didChange', {
textDocument = { textDocument = {
uri = uri, uri = uri,
version = util.buf_versions[bufnr], version = util.buf_versions[bufnr],

View File

@@ -1,6 +1,5 @@
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
---@type table<lsp.FoldingRangeKind, true> ---@type table<lsp.FoldingRangeKind, true>
@@ -37,7 +36,7 @@ local Capability = require('vim.lsp._capability')
---@field row_text table<integer, string?> ---@field row_text table<integer, string?>
local State = { local State = {
name = 'folding_range', name = 'folding_range',
method = ms.textDocument_foldingRange, method = 'textDocument/foldingRange',
active = {}, active = {},
} }
State.__index = State State.__index = State
@@ -165,19 +164,19 @@ function State:refresh(client)
local params = { textDocument = util.make_text_document_params(self.bufnr) } local params = { textDocument = util.make_text_document_params(self.bufnr) }
if client then if client then
client:request(ms.textDocument_foldingRange, params, function(...) client:request('textDocument/foldingRange', params, function(...)
self:handler(...) self:handler(...)
end, self.bufnr) end, self.bufnr)
return return
end end
if if
not next(vim.lsp.get_clients({ bufnr = self.bufnr, method = ms.textDocument_foldingRange })) not next(vim.lsp.get_clients({ bufnr = self.bufnr, method = 'textDocument/foldingRange' }))
then then
return return
end end
vim.lsp.buf_request_all(self.bufnr, ms.textDocument_foldingRange, params, function(...) vim.lsp.buf_request_all(self.bufnr, 'textDocument/foldingRange', params, function(...)
self:multi_handler(...) self:multi_handler(...)
end) end)
end end
@@ -235,10 +234,10 @@ function State:new(bufnr)
callback = function(args) callback = function(args)
local client = assert(vim.lsp.get_client_by_id(args.data.client_id)) local client = assert(vim.lsp.get_client_by_id(args.data.client_id))
if if
client:supports_method(ms.textDocument_foldingRange, bufnr) client:supports_method('textDocument/foldingRange', bufnr)
and ( and (
args.data.method == ms.textDocument_didChange args.data.method == 'textDocument/didChange'
or args.data.method == ms.textDocument_didOpen or args.data.method == 'textDocument/didOpen'
) )
then then
self:refresh(client) self:refresh(client)
@@ -311,12 +310,12 @@ function M.foldclose(kind, winid)
return return
end end
if not next(vim.lsp.get_clients({ bufnr = bufnr, method = ms.textDocument_foldingRange })) then if not next(vim.lsp.get_clients({ bufnr = bufnr, method = 'textDocument/foldingRange' })) then
return return
end end
---@type lsp.FoldingRangeParams ---@type lsp.FoldingRangeParams
local params = { textDocument = util.make_text_document_params(bufnr) } local params = { textDocument = util.make_text_document_params(bufnr) }
vim.lsp.buf_request_all(bufnr, ms.textDocument_foldingRange, params, function(...) vim.lsp.buf_request_all(bufnr, 'textDocument/foldingRange', params, function(...)
state:multi_handler(...) state:multi_handler(...)
-- Ensure this buffer stays as the current buffer after the async request -- Ensure this buffer stays as the current buffer after the async request
if api.nvim_win_get_buf(winid) == bufnr then if api.nvim_win_get_buf(winid) == bufnr then

View File

@@ -1,7 +1,6 @@
local lsp = vim.lsp local lsp = vim.lsp
local api = vim.api local api = vim.api
local util = lsp.util local util = lsp.util
local ms = lsp.protocol.Methods
---@param name string ---@param name string
---@param range lsp.Range ---@param range lsp.Range
@@ -33,13 +32,9 @@ local function query_definition(pattern)
table.insert(results, mk_tag_item(pattern, range, uri, position_encoding)) table.insert(results, mk_tag_item(pattern, range, uri, position_encoding))
end end
local request_results, _ = lsp.buf_request_sync( local request_results, _ = lsp.buf_request_sync(bufnr, 'textDocument/definition', function(client)
bufnr, return util.make_position_params(win, client.offset_encoding)
ms.textDocument_definition, end)
function(client)
return util.make_position_params(win, client.offset_encoding)
end
)
for client_id, res in pairs(request_results or {}) do for client_id, res in pairs(request_results or {}) do
local client = assert(lsp.get_client_by_id(client_id)) local client = assert(lsp.get_client_by_id(client_id))
@@ -69,7 +64,7 @@ end
---@return table[] ---@return table[]
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, ms.workspace_symbol, { query = pattern }, 1000) lsp.buf_request_sync(0, 'workspace/symbol', { query = pattern }, 1000)
if err then if err then
return {} return {}
end end

View File

@@ -2,7 +2,6 @@ local bit = require('bit')
local glob = vim.glob local glob = vim.glob
local watch = vim._watch local watch = 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 = {}
@@ -116,7 +115,7 @@ function M.register(reg, client_id)
local params = { local params = {
changes = change_queues[client_id], changes = change_queues[client_id],
} }
client:notify(ms.workspace_didChangeWatchedFiles, params) client:notify('workspace/didChangeWatchedFiles', params)
queue_timers[client_id] = nil queue_timers[client_id] = nil
change_queues[client_id] = nil change_queues[client_id] = nil
change_cache[client_id] = nil change_cache[client_id] = nil

View File

@@ -6,7 +6,6 @@ local lsp = vim.lsp
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 = {}
@@ -50,9 +49,9 @@ function M.hover(config)
validate('config', config, 'table', true) validate('config', config, 'table', true)
config = config or {} config = config or {}
config.focus_id = ms.textDocument_hover config.focus_id = 'textDocument/hover'
lsp.buf_request_all(0, ms.textDocument_hover, client_positional_params(), function(results, ctx) lsp.buf_request_all(0, 'textDocument/hover', client_positional_params(), function(results, ctx)
local bufnr = assert(ctx.bufnr) local bufnr = assert(ctx.bufnr)
if api.nvim_get_current_buf() ~= bufnr then if api.nvim_get_current_buf() ~= bufnr then
-- Ignore result since buffer changed. This happens for slow language servers. -- Ignore result since buffer changed. This happens for slow language servers.
@@ -306,21 +305,21 @@ end
--- @param opts? vim.lsp.LocationOpts --- @param opts? vim.lsp.LocationOpts
function M.declaration(opts) function M.declaration(opts)
validate('opts', opts, 'table', true) validate('opts', opts, 'table', true)
get_locations(ms.textDocument_declaration, opts) get_locations('textDocument/declaration', opts)
end end
--- Jumps to the definition of the symbol under the cursor. --- Jumps to the definition of the symbol under the cursor.
--- @param opts? vim.lsp.LocationOpts --- @param opts? vim.lsp.LocationOpts
function M.definition(opts) function M.definition(opts)
validate('opts', opts, 'table', true) validate('opts', opts, 'table', true)
get_locations(ms.textDocument_definition, opts) get_locations('textDocument/definition', opts)
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.
--- @param opts? vim.lsp.LocationOpts --- @param opts? vim.lsp.LocationOpts
function M.type_definition(opts) function M.type_definition(opts)
validate('opts', opts, 'table', true) validate('opts', opts, 'table', true)
get_locations(ms.textDocument_typeDefinition, opts) get_locations('textDocument/typeDefinition', opts)
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
@@ -328,7 +327,7 @@ end
--- @param opts? vim.lsp.LocationOpts --- @param opts? vim.lsp.LocationOpts
function M.implementation(opts) function M.implementation(opts)
validate('opts', opts, 'table', true) validate('opts', opts, 'table', true)
get_locations(ms.textDocument_implementation, opts) get_locations('textDocument/implementation', opts)
end end
--- @param results table<integer,{err: lsp.ResponseError?, result: lsp.SignatureHelp?}> --- @param results table<integer,{err: lsp.ResponseError?, result: lsp.SignatureHelp?}>
@@ -383,7 +382,7 @@ local sig_help_ns = api.nvim_create_namespace('nvim.lsp.signature_help')
function M.signature_help(config) function M.signature_help(config)
validate('config', config, 'table', true) validate('config', config, 'table', true)
local method = ms.textDocument_signatureHelp local method = 'textDocument/signatureHelp'
config = config and vim.deepcopy(config) or {} config = config and vim.deepcopy(config) or {}
config.focus_id = method config.focus_id = method
@@ -488,7 +487,7 @@ function M.completion(context)
vim.deprecate('vim.lsp.buf.completion', 'vim.lsp.completion.trigger', '0.12') vim.deprecate('vim.lsp.buf.completion', 'vim.lsp.completion.trigger', '0.12')
return lsp.buf_request( return lsp.buf_request(
0, 0,
ms.textDocument_completion, 'textDocument/completion',
client_positional_params({ client_positional_params({
context = context, context = context,
}) })
@@ -592,13 +591,13 @@ function M.format(opts)
end end
local passed_multiple_ranges = (range and #range ~= 0 and type(range[1]) == 'table') local passed_multiple_ranges = (range and #range ~= 0 and type(range[1]) == 'table')
local method ---@type vim.lsp.protocol.Method.ClientToServer local method ---@type vim.lsp.protocol.Method.ClientToServer.Request
if passed_multiple_ranges then if passed_multiple_ranges then
method = ms.textDocument_rangesFormatting method = 'textDocument/rangesFormatting'
elseif range then elseif range then
method = ms.textDocument_rangeFormatting method = 'textDocument/rangeFormatting'
else else
method = ms.textDocument_formatting method = 'textDocument/formatting'
end end
local clients = lsp.get_clients({ local clients = lsp.get_clients({
@@ -695,7 +694,7 @@ function M.rename(new_name, opts)
bufnr = bufnr, bufnr = bufnr,
name = opts.name, name = opts.name,
-- Clients must at least support rename, prepareRename is optional -- Clients must at least support rename, prepareRename is optional
method = ms.textDocument_rename, method = 'textDocument/rename',
}) })
if opts.filter then if opts.filter then
clients = vim.tbl_filter(opts.filter, clients) clients = vim.tbl_filter(opts.filter, clients)
@@ -734,17 +733,16 @@ function M.rename(new_name, opts)
local function rename(name) local function rename(name)
local params = util.make_position_params(win, client.offset_encoding) --[[@as lsp.RenameParams]] local params = util.make_position_params(win, client.offset_encoding) --[[@as lsp.RenameParams]]
params.newName = name params.newName = name
local handler = client.handlers[ms.textDocument_rename] local handler = client.handlers['textDocument/rename'] or lsp.handlers['textDocument/rename']
or 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(ms.textDocument_prepareRename) then if client:supports_method('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(ms.textDocument_prepareRename, params, function(err, result) client:request('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))
@@ -783,7 +781,7 @@ function M.rename(new_name, opts)
end, bufnr) end, bufnr)
else else
assert( assert(
client:supports_method(ms.textDocument_rename), client:supports_method('textDocument/rename'),
'Client must support textDocument/rename' 'Client must support textDocument/rename'
) )
if new_name then if new_name then
@@ -820,7 +818,7 @@ function M.references(context, opts)
local win = api.nvim_get_current_win() local win = api.nvim_get_current_win()
opts = opts or {} opts = opts or {}
lsp.buf_request_all(bufnr, ms.textDocument_references, function(client) lsp.buf_request_all(bufnr, 'textDocument/references', function(client)
local params = util.make_position_params(win, client.offset_encoding) local params = util.make_position_params(win, client.offset_encoding)
---@diagnostic disable-next-line: inject-field ---@diagnostic disable-next-line: inject-field
params.context = context or { includeDeclaration = true } params.context = context or { includeDeclaration = true }
@@ -842,7 +840,7 @@ function M.references(context, opts)
title = title, title = title,
items = all_items, items = all_items,
context = { context = {
method = ms.textDocument_references, method = 'textDocument/references',
bufnr = bufnr, bufnr = bufnr,
}, },
} }
@@ -866,7 +864,7 @@ function M.document_symbol(opts)
validate('opts', opts, 'table', true) validate('opts', opts, 'table', true)
opts = vim.tbl_deep_extend('keep', opts or {}, { loclist = true }) opts = vim.tbl_deep_extend('keep', opts or {}, { loclist = true })
local params = { textDocument = util.make_text_document_params() } local params = { textDocument = util.make_text_document_params() }
request_with_opts(ms.textDocument_documentSymbol, params, opts) request_with_opts('textDocument/documentSymbol', params, opts)
end end
--- @param client_id integer --- @param client_id integer
@@ -902,18 +900,18 @@ end
--- @type table<vim.lsp.buf.HierarchyMethod, 'type' | 'call'> --- @type table<vim.lsp.buf.HierarchyMethod, 'type' | 'call'>
local hierarchy_methods = { local hierarchy_methods = {
[ms.typeHierarchy_subtypes] = 'type', ['typeHierarchy/subtypes'] = 'type',
[ms.typeHierarchy_supertypes] = 'type', ['typeHierarchy/supertypes'] = 'type',
[ms.callHierarchy_incomingCalls] = 'call', ['callHierarchy/incomingCalls'] = 'call',
[ms.callHierarchy_outgoingCalls] = 'call', ['callHierarchy/outgoingCalls'] = 'call',
} }
--- @param method vim.lsp.buf.HierarchyMethod --- @param method vim.lsp.buf.HierarchyMethod
local function hierarchy(method) local function hierarchy(method)
local kind = hierarchy_methods[method] local kind = hierarchy_methods[method]
local prepare_method = kind == 'type' and ms.textDocument_prepareTypeHierarchy local prepare_method = kind == 'type' and 'textDocument/prepareTypeHierarchy'
or ms.textDocument_prepareCallHierarchy or 'textDocument/prepareCallHierarchy'
local bufnr = api.nvim_get_current_buf() local bufnr = api.nvim_get_current_buf()
local clients = lsp.get_clients({ bufnr = bufnr, method = prepare_method }) local clients = lsp.get_clients({ bufnr = bufnr, method = prepare_method })
@@ -965,14 +963,14 @@ end
--- |quickfix| window. If the symbol can resolve to multiple --- |quickfix| window. If the symbol can resolve to multiple
--- items, the user can pick one in the |inputlist()|. --- items, the user can pick one in the |inputlist()|.
function M.incoming_calls() function M.incoming_calls()
hierarchy(ms.callHierarchy_incomingCalls) hierarchy('callHierarchy/incomingCalls')
end end
--- Lists all the items that are called by the symbol under the --- Lists all the items that are called by the symbol under the
--- cursor in the |quickfix| window. If the symbol can resolve to --- cursor in the |quickfix| window. If the symbol can resolve to
--- multiple items, the user can pick one in the |inputlist()|. --- multiple items, the user can pick one in the |inputlist()|.
function M.outgoing_calls() function M.outgoing_calls()
hierarchy(ms.callHierarchy_outgoingCalls) hierarchy('callHierarchy/outgoingCalls')
end end
--- Lists all the subtypes or supertypes of the symbol under the --- Lists all the subtypes or supertypes of the symbol under the
@@ -984,7 +982,7 @@ function M.typehierarchy(kind)
return v == 'subtypes' or v == 'supertypes' return v == 'subtypes' or v == 'supertypes'
end) end)
local method = kind == 'subtypes' and ms.typeHierarchy_subtypes or ms.typeHierarchy_supertypes local method = kind == 'subtypes' and 'typeHierarchy/subtypes' or 'typeHierarchy/supertypes'
hierarchy(method) hierarchy(method)
end end
@@ -1059,7 +1057,7 @@ function M.workspace_symbol(query, opts)
return return
end end
local params = { query = query } local params = { query = query }
request_with_opts(ms.workspace_symbol, params, opts) request_with_opts('workspace/symbol', params, opts)
end end
--- @class vim.lsp.WorkspaceDiagnosticsOpts --- @class vim.lsp.WorkspaceDiagnosticsOpts
@@ -1093,7 +1091,7 @@ end
--- |hl-LspReferenceRead| --- |hl-LspReferenceRead|
--- |hl-LspReferenceWrite| --- |hl-LspReferenceWrite|
function M.document_highlight() function M.document_highlight()
lsp.buf_request(0, ms.textDocument_documentHighlight, client_positional_params()) lsp.buf_request(0, 'textDocument/documentHighlight', client_positional_params())
end end
--- Removes document highlights from current buffer. --- Removes document highlights from current buffer.
@@ -1239,8 +1237,8 @@ local function on_code_action_results(results, opts)
return return
end end
if not (action.edit and action.command) and client:supports_method(ms.codeAction_resolve) then if not (action.edit and action.command) and client:supports_method('codeAction/resolve') then
client:request(ms.codeAction_resolve, action, function(err, resolved_action) client:request('codeAction/resolve', action, function(err, resolved_action)
if err then if err then
-- If resolve fails, try to apply the edit/command from the original code action. -- If resolve fails, try to apply the edit/command from the original code action.
if action.edit or action.command then if action.edit or action.command then
@@ -1310,13 +1308,13 @@ function M.code_action(opts)
local mode = api.nvim_get_mode().mode local mode = api.nvim_get_mode().mode
local bufnr = api.nvim_get_current_buf() local bufnr = api.nvim_get_current_buf()
local win = api.nvim_get_current_win() local win = api.nvim_get_current_win()
local clients = lsp.get_clients({ bufnr = bufnr, method = ms.textDocument_codeAction }) local clients = lsp.get_clients({ bufnr = bufnr, method = 'textDocument/codeAction' })
if not next(clients) then if not next(clients) then
vim.notify(lsp._unsupported_method(ms.textDocument_codeAction), vim.log.levels.WARN) vim.notify(lsp._unsupported_method('textDocument/codeAction'), vim.log.levels.WARN)
return return
end end
lsp.buf_request_all(bufnr, ms.textDocument_codeAction, function(client) lsp.buf_request_all(bufnr, 'textDocument/codeAction', function(client)
---@type lsp.CodeActionParams ---@type lsp.CodeActionParams
local params local params
@@ -1371,7 +1369,7 @@ function M.execute_command(command_params)
arguments = command_params.arguments, arguments = command_params.arguments,
workDoneToken = command_params.workDoneToken, workDoneToken = command_params.workDoneToken,
} }
lsp.buf_request(0, ms.workspace_executeCommand, command_params) lsp.buf_request(0, 'workspace/executeCommand', command_params)
end end
---@type { index: integer, ranges: lsp.Range[] }? ---@type { index: integer, ranges: lsp.Range[] }?
@@ -1418,7 +1416,7 @@ function M.selection_range(direction)
return return
end end
local method = ms.textDocument_selectionRange local method = 'textDocument/selectionRange'
local client = lsp.get_clients({ method = method, bufnr = 0 })[1] local client = lsp.get_clients({ method = method, bufnr = 0 })[1]
if not client then if not client then
vim.notify(lsp._unsupported_method(method), vim.log.levels.WARN) vim.notify(lsp._unsupported_method(method), vim.log.levels.WARN)

View File

@@ -2,7 +2,6 @@ local uv = vim.uv
local api = vim.api local api = vim.api
local lsp = vim.lsp local lsp = vim.lsp
local log = lsp.log local log = lsp.log
local ms = lsp.protocol.Methods
local changetracking = lsp._changetracking local changetracking = lsp._changetracking
local validate = vim.validate local validate = vim.validate
@@ -578,7 +577,7 @@ function Client:initialize()
self.server_info = result.serverInfo self.server_info = result.serverInfo
if next(self.settings) then if next(self.settings) then
self:notify(ms.workspace_didChangeConfiguration, { settings = self.settings }) self:notify('workspace/didChangeConfiguration', { settings = self.settings })
end end
-- If server is being restarted, make sure to re-attach to any previously attached buffers. -- If server is being restarted, make sure to re-attach to any previously attached buffers.
@@ -604,21 +603,21 @@ end
-- Server capabilities for methods that support static registration. -- Server capabilities for methods that support static registration.
local static_registration_capabilities = { local static_registration_capabilities = {
[ms.textDocument_prepareCallHierarchy] = 'callHierarchyProvider', ['textDocument/prepareCallHierarchy'] = 'callHierarchyProvider',
[ms.textDocument_documentColor] = 'colorProvider', ['textDocument/documentColor'] = 'colorProvider',
[ms.textDocument_declaration] = 'declarationProvider', ['textDocument/declaration'] = 'declarationProvider',
[ms.textDocument_diagnostic] = 'diagnosticProvider', ['textDocument/diagnostic'] = 'diagnosticProvider',
[ms.textDocument_foldingRange] = 'foldingRangeProvider', ['textDocument/foldingRange'] = 'foldingRangeProvider',
[ms.textDocument_implementation] = 'implementationProvider', ['textDocument/implementation'] = 'implementationProvider',
[ms.textDocument_inlayHint] = 'inlayHintProvider', ['textDocument/inlayHint'] = 'inlayHintProvider',
[ms.textDocument_inlineCompletion] = 'inlineCompletionProvider', ['textDocument/inlineCompletion'] = 'inlineCompletionProvider',
[ms.textDocument_inlineValue] = 'inlineValueProvider', ['textDocument/inlineValue'] = 'inlineValueProvider',
[ms.textDocument_linkedEditingRange] = 'linkedEditingRangeProvider', ['textDocument/linkedEditingRange'] = 'linkedEditingRangeProvider',
[ms.textDocument_moniker] = 'monikerProvider', ['textDocument/moniker'] = 'monikerProvider',
[ms.textDocument_selectionRange] = 'selectionRangeProvider', ['textDocument/selectionRange'] = 'selectionRangeProvider',
[ms.textDocument_semanticTokens_full] = 'semanticTokensProvider', ['textDocument_semanticTokens/full'] = 'semanticTokensProvider',
[ms.textDocument_typeDefinition] = 'typeDefinitionProvider', ['textDocument/typeDefinition'] = 'typeDefinitionProvider',
[ms.textDocument_prepareTypeHierarchy] = 'typeHierarchyProvider', ['textDocument/prepareTypeHierarchy'] = 'typeHierarchyProvider',
} }
--- @private --- @private
@@ -628,6 +627,7 @@ function Client:_process_static_registrations()
for method, capability in pairs(static_registration_capabilities) do for method, capability in pairs(static_registration_capabilities) do
if if
vim.tbl_get(self.server_capabilities, capability, 'id') vim.tbl_get(self.server_capabilities, capability, 'id')
--- @cast method vim.lsp.protocol.Method
and self:_supports_registration(method) and self:_supports_registration(method)
then then
static_registrations[#static_registrations + 1] = { static_registrations[#static_registrations + 1] = {
@@ -827,7 +827,7 @@ end
--- @return boolean status indicating if the notification was successful. --- @return boolean status indicating if the notification was successful.
--- If it is false, then the client has shutdown. --- If it is false, then the client has shutdown.
function Client:notify(method, params) function Client:notify(method, params)
if method ~= ms.textDocument_didChange then if method ~= 'textDocument/didChange' then
changetracking.flush(self) changetracking.flush(self)
end end
@@ -856,7 +856,7 @@ end
--- @see |Client:notify()| --- @see |Client:notify()|
function Client:cancel_request(id) function Client:cancel_request(id)
self:_process_request(id, 'cancel') self:_process_request(id, 'cancel')
return self.rpc.notify(ms.dollar_cancelRequest, { id = id }) return self.rpc.notify('$/cancelRequest', { id = id })
end end
--- Stops a client, optionally with force. --- Stops a client, optionally with force.
@@ -882,9 +882,9 @@ function Client:stop(force)
end end
-- Sending a signal after a process has exited is acceptable. -- Sending a signal after a process has exited is acceptable.
rpc.request(ms.shutdown, nil, function(err, _) rpc.request('shutdown', nil, function(err, _)
if err == nil then if err == nil then
rpc.notify(ms.exit) rpc.notify('exit')
else else
-- If there was an error in the shutdown request, then term to be safe. -- If there was an error in the shutdown request, then term to be safe.
rpc.terminate() rpc.terminate()
@@ -923,7 +923,7 @@ function Client:_register(registrations)
for _, reg in ipairs(registrations) do for _, reg in ipairs(registrations) do
local method = reg.method local method = reg.method
if method == ms.workspace_didChangeWatchedFiles then if method == 'workspace/didChangeWatchedFiles' then
lsp._watchfiles.register(reg, self.id) lsp._watchfiles.register(reg, self.id)
elseif not self:_supports_registration(method) then elseif not self:_supports_registration(method) then
unsupported[#unsupported + 1] = method unsupported[#unsupported + 1] = method
@@ -957,7 +957,7 @@ end
function Client:_unregister(unregistrations) function Client:_unregister(unregistrations)
self:_unregister_dynamic(unregistrations) self:_unregister_dynamic(unregistrations)
for _, unreg in ipairs(unregistrations) do for _, unreg in ipairs(unregistrations) do
if unreg.method == ms.workspace_didChangeWatchedFiles then if unreg.method == 'workspace/didChangeWatchedFiles' then
lsp._watchfiles.unregister(unreg, self.id) lsp._watchfiles.unregister(unreg, self.id)
end end
end end
@@ -1045,7 +1045,7 @@ function Client:exec_cmd(command, context, handler)
command = cmdname, command = cmdname,
arguments = command.arguments, arguments = command.arguments,
} }
self:request(ms.workspace_executeCommand, params, handler, context.bufnr) self:request('workspace/executeCommand', params, handler, context.bufnr)
end end
--- Default handler for the 'textDocument/didOpen' LSP notification. --- Default handler for the 'textDocument/didOpen' LSP notification.
@@ -1053,14 +1053,14 @@ end
--- @param bufnr integer Number of the buffer, or 0 for current --- @param bufnr integer Number of the buffer, or 0 for current
function Client:_text_document_did_open_handler(bufnr) function Client:_text_document_did_open_handler(bufnr)
changetracking.init(self, bufnr) changetracking.init(self, bufnr)
if not self:supports_method(ms.textDocument_didOpen) then if not self:supports_method('textDocument/didOpen') then
return return
end end
if not api.nvim_buf_is_loaded(bufnr) then if not api.nvim_buf_is_loaded(bufnr) then
return return
end end
self:notify(ms.textDocument_didOpen, { self:notify('textDocument/didOpen', {
textDocument = { textDocument = {
version = lsp.util.buf_versions[bufnr], version = lsp.util.buf_versions[bufnr],
uri = vim.uri_from_bufnr(bufnr), uri = vim.uri_from_bufnr(bufnr),
@@ -1250,10 +1250,10 @@ function Client:_on_detach(bufnr)
changetracking.reset_buf(self, bufnr) changetracking.reset_buf(self, bufnr)
if self:supports_method(ms.textDocument_didClose) then if self:supports_method('textDocument/didClose') 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 } }
self:notify(ms.textDocument_didClose, params) self:notify('textDocument/didClose', params)
end end
self.attached_buffers[bufnr] = nil self.attached_buffers[bufnr] = nil
@@ -1340,7 +1340,7 @@ function Client:_add_workspace_folder(dir)
local wf = assert(lsp._get_workspace_folders(dir)) local wf = assert(lsp._get_workspace_folders(dir))
self:notify(ms.workspace_didChangeWorkspaceFolders, { self:notify('workspace/didChangeWorkspaceFolders', {
event = { added = wf, removed = {} }, event = { added = wf, removed = {} },
}) })
@@ -1355,7 +1355,7 @@ end
function Client:_remove_workspace_folder(dir) function Client:_remove_workspace_folder(dir)
local wf = assert(lsp._get_workspace_folders(dir)) local wf = assert(lsp._get_workspace_folders(dir))
self:notify(ms.workspace_didChangeWorkspaceFolders, { self:notify('workspace/didChangeWorkspaceFolders', {
event = { added = {}, removed = wf }, event = { added = {}, removed = wf },
}) })

View File

@@ -1,6 +1,5 @@
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 = {}
@@ -49,7 +48,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[ms.workspace_executeCommand](...) vim.lsp.handlers['workspace/executeCommand'](...)
M.refresh() M.refresh()
end) end)
end end
@@ -276,7 +275,7 @@ local function resolve_lenses(lenses, bufnr, client_id, callback)
display_line_countdown() display_line_countdown()
else else
assert(client) assert(client)
client:request(ms.codeLens_resolve, lens, function(_, result) client:request('codeLens/resolve', lens, function(_, result)
if api.nvim_buf_is_loaded(bufnr) and result and result.command then if api.nvim_buf_is_loaded(bufnr) and result and result.command then
lens.command = result.command lens.command = result.command
end end
@@ -340,7 +339,7 @@ function M.refresh(opts)
local request_ids = vim.lsp.buf_request( local request_ids = vim.lsp.buf_request(
buf, buf,
ms.textDocument_codeLens, 'textDocument/codeLens',
params, params,
M.on_codelens, M.on_codelens,
function() end function() end

View File

@@ -36,7 +36,6 @@ local M = {}
local api = vim.api local api = vim.api
local lsp = vim.lsp local lsp = vim.lsp
local protocol = lsp.protocol local protocol = lsp.protocol
local ms = protocol.Methods
local rtt_ms = 50.0 local rtt_ms = 50.0
local ns_to_ms = 0.000001 local ns_to_ms = 0.000001
@@ -448,7 +447,7 @@ local function request(clients, bufnr, win, ctx, callback)
local params = lsp.util.make_position_params(win, client.offset_encoding) local params = lsp.util.make_position_params(win, client.offset_encoding)
--- @cast params lsp.CompletionParams --- @cast params lsp.CompletionParams
params.context = ctx params.context = ctx
local ok, request_id = client:request(ms.textDocument_completion, params, function(err, result) local ok, request_id = client:request('textDocument/completion', params, function(err, result)
responses[client_id] = { err = err, result = result } responses[client_id] = { err = err, result = result }
remaining_requests = remaining_requests - 1 remaining_requests = remaining_requests - 1
if remaining_requests == 0 then if remaining_requests == 0 then
@@ -660,7 +659,7 @@ local function on_complete_done()
local changedtick = vim.b[bufnr].changedtick local changedtick = vim.b[bufnr].changedtick
--- @param result lsp.CompletionItem --- @param result lsp.CompletionItem
client:request(ms.completionItem_resolve, completion_item, function(err, result) client:request('completionItem/resolve', completion_item, function(err, result)
if changedtick ~= vim.b[bufnr].changedtick then if changedtick ~= vim.b[bufnr].changedtick then
return return
end end
@@ -870,7 +869,7 @@ function M._omnifunc(findstart, base)
lsp.log.debug('omnifunc.findstart', { findstart = findstart, base = base }) lsp.log.debug('omnifunc.findstart', { findstart = findstart, base = base })
assert(base) -- silence luals assert(base) -- silence luals
local bufnr = api.nvim_get_current_buf() local bufnr = api.nvim_get_current_buf()
local clients = lsp.get_clients({ bufnr = bufnr, method = ms.textDocument_completion }) local clients = lsp.get_clients({ bufnr = bufnr, method = '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 {}

View File

@@ -5,7 +5,6 @@
local lsp = vim.lsp local lsp = vim.lsp
local protocol = lsp.protocol local protocol = lsp.protocol
local ms = protocol.Methods
local util = lsp.util local util = lsp.util
local api = vim.api local api = vim.api
@@ -363,7 +362,7 @@ local function refresh(bufnr, client_id, only_visible)
return return
end end
local method = ms.textDocument_diagnostic local method = 'textDocument/diagnostic'
local clients = lsp.get_clients({ bufnr = bufnr, method = method, id = client_id }) local clients = lsp.get_clients({ bufnr = bufnr, method = method, id = client_id })
local bufstate = bufstates[bufnr] local bufstate = bufstates[bufnr]
@@ -403,8 +402,8 @@ function M._enable(bufnr)
buffer = bufnr, buffer = bufnr,
callback = function(opts) callback = function(opts)
if if
opts.data.method ~= ms.textDocument_didChange opts.data.method ~= 'textDocument/didChange'
and opts.data.method ~= ms.textDocument_didOpen and opts.data.method ~= 'textDocument/didOpen'
then then
return return
end end
@@ -430,7 +429,7 @@ function M._enable(bufnr)
api.nvim_create_autocmd('LspDetach', { api.nvim_create_autocmd('LspDetach', {
buffer = bufnr, buffer = bufnr,
callback = function(args) callback = function(args)
local clients = lsp.get_clients({ bufnr = bufnr, method = ms.textDocument_diagnostic }) local clients = lsp.get_clients({ bufnr = bufnr, method = 'textDocument/diagnostic' })
if if
not vim.iter(clients):any(function(c) not vim.iter(clients):any(function(c)
@@ -469,7 +468,7 @@ end
--- Request workspace-wide diagnostics. --- Request workspace-wide diagnostics.
--- @param opts vim.lsp.WorkspaceDiagnosticsOpts --- @param opts vim.lsp.WorkspaceDiagnosticsOpts
function M._workspace_diagnostics(opts) function M._workspace_diagnostics(opts)
local clients = lsp.get_clients({ method = ms.workspace_diagnostic, id = opts.client_id }) local clients = lsp.get_clients({ method = 'workspace/diagnostic', id = opts.client_id })
--- @param error lsp.ResponseError? --- @param error lsp.ResponseError?
--- @param result lsp.WorkspaceDiagnosticReport --- @param result lsp.WorkspaceDiagnosticReport
@@ -480,7 +479,7 @@ function M._workspace_diagnostics(opts)
if error ~= nil and error.code == protocol.ErrorCodes.ServerCancelled then if error ~= nil and error.code == protocol.ErrorCodes.ServerCancelled then
if error.data == nil or error.data.retriggerRequest ~= false then if error.data == nil or error.data.retriggerRequest ~= false then
local client = assert(lsp.get_client_by_id(ctx.client_id)) local client = assert(lsp.get_client_by_id(ctx.client_id))
client:request(ms.workspace_diagnostic, ctx.params, handler) client:request('workspace/diagnostic', ctx.params, handler)
end end
return return
end end
@@ -511,7 +510,7 @@ function M._workspace_diagnostics(opts)
previousResultIds = previous_result_ids(client.id), previousResultIds = previous_result_ids(client.id),
} }
client:request(ms.workspace_diagnostic, params, handler) client:request('workspace/diagnostic', params, handler)
end end
end end

View File

@@ -4,7 +4,6 @@
local api = vim.api local api = vim.api
local lsp = vim.lsp local lsp = vim.lsp
local util = lsp.util local util = lsp.util
local ms = lsp.protocol.Methods
local Range = vim.treesitter._range local Range = vim.treesitter._range
local document_color_ns = api.nvim_create_namespace('nvim.lsp.document_color') local document_color_ns = api.nvim_create_namespace('nvim.lsp.document_color')
@@ -223,7 +222,7 @@ local function buf_enable(bufnr)
local method = args.data.method --- @type string local method = args.data.method --- @type string
if if
(method == ms.textDocument_didChange or method == ms.textDocument_didOpen) (method == 'textDocument/didChange' or method == 'textDocument/didOpen')
and assert(bufstates[args.buf]).enabled and assert(bufstates[args.buf]).enabled
then then
M._buf_refresh(args.buf, args.data.client_id) M._buf_refresh(args.buf, args.data.client_id)
@@ -236,7 +235,7 @@ local function buf_enable(bufnr)
group = document_color_augroup, group = document_color_augroup,
desc = 'Disable document_color if all supporting clients detach', desc = 'Disable document_color if all supporting clients detach',
callback = function(args) callback = function(args)
local clients = lsp.get_clients({ bufnr = args.buf, method = ms.textDocument_documentColor }) local clients = lsp.get_clients({ bufnr = args.buf, method = 'textDocument/documentColor' })
if if
not vim.iter(clients):any(function(c) not vim.iter(clients):any(function(c)
@@ -259,12 +258,12 @@ function M._buf_refresh(bufnr, client_id)
ipairs(lsp.get_clients({ ipairs(lsp.get_clients({
bufnr = bufnr, bufnr = bufnr,
id = client_id, id = client_id,
method = ms.textDocument_documentColor, method = 'textDocument/documentColor',
})) }))
do do
---@type lsp.DocumentColorParams ---@type lsp.DocumentColorParams
local params = { textDocument = util.make_text_document_params(bufnr) } local params = { textDocument = util.make_text_document_params(bufnr) }
client:request(ms.textDocument_documentColor, params, on_document_color) client:request('textDocument/documentColor', params, on_document_color)
end end
end end
@@ -416,7 +415,7 @@ function M.color_presentation()
} }
--- @param result lsp.ColorPresentation[] --- @param result lsp.ColorPresentation[]
client:request(ms.textDocument_colorPresentation, params, function(err, result, ctx) client:request('textDocument/colorPresentation', params, function(err, result, ctx)
if err then if err then
lsp.log.error('color_presentation', err) lsp.log.error('color_presentation', err)
return return

View File

@@ -1,6 +1,5 @@
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
local completion = require('vim.lsp.completion') local completion = require('vim.lsp.completion')
@@ -45,7 +44,7 @@ local function show_message_notification(params, ctx)
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
RCS[ms.workspace_executeCommand] = function(_, _, _) RCS['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
@@ -53,7 +52,7 @@ end
---@param params lsp.ProgressParams ---@param params lsp.ProgressParams
---@param ctx lsp.HandlerContext ---@param ctx lsp.HandlerContext
---@diagnostic disable-next-line:no-unknown ---@diagnostic disable-next-line:no-unknown
RSC[ms.dollar_progress] = function(_, params, ctx) RSC['$/progress'] = function(_, params, 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')
@@ -89,7 +88,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 params lsp.WorkDoneProgressCreateParams ---@param params lsp.WorkDoneProgressCreateParams
---@param ctx lsp.HandlerContext ---@param ctx lsp.HandlerContext
RSC[ms.window_workDoneProgress_create] = function(_, params, ctx) RSC['window/workDoneProgress/create'] = function(_, params, 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')
@@ -101,7 +100,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 params lsp.ShowMessageRequestParams ---@param params lsp.ShowMessageRequestParams
RSC[ms.window_showMessageRequest] = function(_, params, ctx) RSC['window/showMessageRequest'] = function(_, params, ctx)
if next(params.actions or {}) then if next(params.actions or {}) then
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
@@ -143,14 +142,14 @@ 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
--- @param params lsp.RegistrationParams --- @param params lsp.RegistrationParams
RSC[ms.client_registerCapability] = function(_, params, ctx) RSC['client/registerCapability'] = function(_, params, ctx)
local client = assert(vim.lsp.get_client_by_id(ctx.client_id)) local client = assert(vim.lsp.get_client_by_id(ctx.client_id))
client:_register(params.registrations) client:_register(params.registrations)
for bufnr in pairs(client.attached_buffers) do for bufnr in pairs(client.attached_buffers) do
vim.lsp._set_defaults(client, bufnr) vim.lsp._set_defaults(client, bufnr)
end end
for _, reg in ipairs(params.registrations) do for _, reg in ipairs(params.registrations) do
if reg.method == ms.textDocument_documentColor then if reg.method == 'textDocument/documentColor' then
for bufnr in pairs(client.attached_buffers) do for bufnr in pairs(client.attached_buffers) do
if vim.lsp.document_color.is_enabled(bufnr) then if vim.lsp.document_color.is_enabled(bufnr) then
vim.lsp.document_color._buf_refresh(bufnr, client.id) vim.lsp.document_color._buf_refresh(bufnr, client.id)
@@ -163,7 +162,7 @@ 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
--- @param params lsp.UnregistrationParams --- @param params lsp.UnregistrationParams
RSC[ms.client_unregisterCapability] = function(_, params, ctx) RSC['client/unregisterCapability'] = function(_, params, ctx)
local client = assert(vim.lsp.get_client_by_id(ctx.client_id)) local client = assert(vim.lsp.get_client_by_id(ctx.client_id))
client:_unregister(params.unregisterations) client:_unregister(params.unregisterations)
return vim.NIL return vim.NIL
@@ -171,7 +170,7 @@ end
-- TODO(lewis6991): Do we need to notify other servers? -- TODO(lewis6991): Do we need to notify other servers?
--- @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
RSC[ms.workspace_applyEdit] = function(_, params, ctx) RSC['workspace/applyEdit'] = function(_, params, ctx)
assert( assert(
params, params,
'workspace/applyEdit must be called with `ApplyWorkspaceEditParams`. Server is violating the specification' 'workspace/applyEdit must be called with `ApplyWorkspaceEditParams`. Server is violating the specification'
@@ -198,7 +197,7 @@ 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
--- @param params lsp.ConfigurationParams --- @param params lsp.ConfigurationParams
RSC[ms.workspace_configuration] = function(_, params, ctx) RSC['workspace/configuration'] = function(_, params, 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( err_message(
@@ -230,7 +229,7 @@ RSC[ms.workspace_configuration] = function(_, params, 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
RSC[ms.workspace_workspaceFolders] = function(_, _, ctx) RSC['workspace/workspaceFolders'] = function(_, _, 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=', ctx.client_id, '] client has shut down after sending the message') err_message('LSP[id=', ctx.client_id, '] client has shut down after sending the message')
@@ -239,22 +238,22 @@ RSC[ms.workspace_workspaceFolders] = function(_, _, ctx)
return client.workspace_folders or vim.NIL return client.workspace_folders or vim.NIL
end end
NSC[ms.textDocument_publishDiagnostics] = function(...) NSC['textDocument/publishDiagnostics'] = function(...)
return vim.lsp.diagnostic.on_publish_diagnostics(...) return vim.lsp.diagnostic.on_publish_diagnostics(...)
end end
--- @private --- @private
RCS[ms.textDocument_diagnostic] = function(...) RCS['textDocument/diagnostic'] = function(...)
return vim.lsp.diagnostic.on_diagnostic(...) return vim.lsp.diagnostic.on_diagnostic(...)
end end
--- @private --- @private
RCS[ms.textDocument_codeLens] = function(...) RCS['textDocument/codeLens'] = function(...)
return vim.lsp.codelens.on_codelens(...) return vim.lsp.codelens.on_codelens(...)
end end
--- @private --- @private
RCS[ms.textDocument_inlayHint] = function(...) RCS['textDocument/inlayHint'] = function(...)
return vim.lsp.inlay_hint.on_inlayhint(...) return vim.lsp.inlay_hint.on_inlayhint(...)
end end
@@ -294,7 +293,7 @@ end
--- @deprecated remove in 0.13 --- @deprecated remove in 0.13
--- @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
RCS[ms.textDocument_documentSymbol] = response_to_list( RCS['textDocument/documentSymbol'] = response_to_list(
util.symbols_to_items, util.symbols_to_items,
'document symbols', 'document symbols',
function(ctx) function(ctx)
@@ -305,13 +304,13 @@ RCS[ms.textDocument_documentSymbol] = response_to_list(
--- @deprecated remove in 0.13 --- @deprecated remove in 0.13
--- @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
RCS[ms.workspace_symbol] = response_to_list(util.symbols_to_items, 'symbols', function(ctx) RCS['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)
--- @deprecated remove in 0.13 --- @deprecated remove in 0.13
--- @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
RCS[ms.textDocument_rename] = function(_, result, ctx) RCS['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
@@ -322,7 +321,7 @@ end
--- @deprecated remove in 0.13 --- @deprecated remove in 0.13
--- @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
RCS[ms.textDocument_rangeFormatting] = function(_, result, ctx) RCS['textDocument/rangeFormatting'] = function(_, result, ctx)
if not result then if not result then
return return
end end
@@ -332,7 +331,7 @@ end
--- @deprecated remove in 0.13 --- @deprecated remove in 0.13
--- @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
RCS[ms.textDocument_formatting] = function(_, result, ctx) RCS['textDocument/formatting'] = function(_, result, ctx)
if not result then if not result then
return return
end end
@@ -342,7 +341,7 @@ end
--- @deprecated remove in 0.13 --- @deprecated remove in 0.13
--- @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
RCS[ms.textDocument_completion] = function(_, result, _) RCS['textDocument/completion'] = function(_, result, _)
if vim.tbl_isempty(result or {}) then if vim.tbl_isempty(result or {}) then
return return
end end
@@ -412,7 +411,7 @@ end
--- @deprecated remove in 0.13 --- @deprecated remove in 0.13
--- @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
--- @diagnostic disable-next-line: deprecated --- @diagnostic disable-next-line: deprecated
RCS[ms.textDocument_hover] = M.hover RCS['textDocument/hover'] = M.hover
local sig_help_ns = api.nvim_create_namespace('nvim.lsp.signature_help') local sig_help_ns = api.nvim_create_namespace('nvim.lsp.signature_help')
@@ -481,11 +480,11 @@ end
--- @deprecated remove in 0.13 --- @deprecated remove in 0.13
--- @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
--- @diagnostic disable-next-line:deprecated --- @diagnostic disable-next-line:deprecated
RCS[ms.textDocument_signatureHelp] = M.signature_help RCS['textDocument/signatureHelp'] = M.signature_help
--- @deprecated remove in 0.13 --- @deprecated remove in 0.13
--- @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
RCS[ms.textDocument_documentHighlight] = function(_, result, ctx) RCS['textDocument/documentHighlight'] = function(_, result, ctx)
if not result then if not result then
return return
end end
@@ -528,11 +527,11 @@ end
--- @deprecated remove in 0.13 --- @deprecated remove in 0.13
--- @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
RCS[ms.callHierarchy_incomingCalls] = make_call_hierarchy_handler('from') RCS['callHierarchy/incomingCalls'] = make_call_hierarchy_handler('from')
--- @deprecated remove in 0.13 --- @deprecated remove in 0.13
--- @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
RCS[ms.callHierarchy_outgoingCalls] = make_call_hierarchy_handler('to') RCS['callHierarchy/outgoingCalls'] = make_call_hierarchy_handler('to')
--- Displays type hierarchy in the quickfix window. --- Displays type hierarchy in the quickfix window.
local function make_type_hierarchy_handler() local function make_type_hierarchy_handler()
@@ -569,11 +568,11 @@ end
--- @deprecated remove in 0.13 --- @deprecated remove in 0.13
--- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#typeHierarchy_incomingCalls --- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#typeHierarchy_incomingCalls
RCS[ms.typeHierarchy_subtypes] = make_type_hierarchy_handler() RCS['typeHierarchy/subtypes'] = make_type_hierarchy_handler()
--- @deprecated remove in 0.13 --- @deprecated remove in 0.13
--- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#typeHierarchy_outgoingCalls --- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#typeHierarchy_outgoingCalls
RCS[ms.typeHierarchy_supertypes] = make_type_hierarchy_handler() RCS['typeHierarchy/supertypes'] = make_type_hierarchy_handler()
--- @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
--- @param params lsp.LogMessageParams --- @param params lsp.LogMessageParams
@@ -607,7 +606,7 @@ end
--- @private --- @private
--- @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
--- @param params lsp.ShowDocumentParams --- @param params lsp.ShowDocumentParams
RSC[ms.window_showDocument] = function(_, params, ctx) RSC['window/showDocument'] = function(_, params, ctx)
local uri = params.uri local uri = params.uri
if params.external then if params.external then
@@ -649,12 +648,12 @@ RSC[ms.window_showDocument] = function(_, params, ctx)
end end
---@see https://microsoft.github.io/language-server-protocol/specification/#workspace_inlayHint_refresh ---@see https://microsoft.github.io/language-server-protocol/specification/#workspace_inlayHint_refresh
RSC[ms.workspace_inlayHint_refresh] = function(err, result, ctx) RSC['workspace_inlayHint/refresh'] = function(err, result, ctx)
return vim.lsp.inlay_hint.on_refresh(err, result, ctx) return vim.lsp.inlay_hint.on_refresh(err, result, ctx)
end end
---@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
RSC[ms.workspace_semanticTokens_refresh] = function(err, result, ctx) RSC['workspace_semanticTokens/refresh'] = function(err, result, ctx)
return vim.lsp.semantic_tokens._refresh(err, result, ctx) return vim.lsp.semantic_tokens._refresh(err, result, ctx)
end end

View File

@@ -126,7 +126,7 @@ local function check_watcher()
'dynamicRegistration' 'dynamicRegistration'
) )
local has_dynamic_capability = local has_dynamic_capability =
client.dynamic_capabilities:get(vim.lsp.protocol.Methods.workspace_didChangeWatchedFiles) client.dynamic_capabilities:get('workspace/didChangeWatchedFiles')
return has_capability == nil return has_capability == nil
or has_dynamic_capability == nil or has_dynamic_capability == nil
or client.workspace_folders == nil or client.workspace_folders == nil

View File

@@ -1,6 +1,5 @@
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 = {}
@@ -96,10 +95,10 @@ local function refresh(bufnr, client_id)
ipairs(vim.lsp.get_clients({ ipairs(vim.lsp.get_clients({
bufnr = bufnr, bufnr = bufnr,
id = client_id, id = client_id,
method = ms.textDocument_inlayHint, method = 'textDocument/inlayHint',
})) }))
do do
client:request(ms.textDocument_inlayHint, { client:request('textDocument/inlayHint', {
textDocument = util.make_text_document_params(bufnr), textDocument = util.make_text_document_params(bufnr),
range = util._make_line_range_params( range = util._make_line_range_params(
bufnr, bufnr,
@@ -190,7 +189,7 @@ function M.get(filter)
local clients = vim.lsp.get_clients({ local clients = vim.lsp.get_clients({
bufnr = bufnr, bufnr = bufnr,
method = ms.textDocument_inlayHint, method = 'textDocument/inlayHint',
}) })
if #clients == 0 then if #clients == 0 then
return {} return {}
@@ -270,8 +269,8 @@ api.nvim_create_autocmd('LspNotify', {
local bufnr = args.buf local bufnr = args.buf
if if
args.data.method ~= ms.textDocument_didChange args.data.method ~= 'textDocument/didChange'
and args.data.method ~= ms.textDocument_didOpen and args.data.method ~= 'textDocument/didOpen'
then then
return return
end end
@@ -306,7 +305,7 @@ api.nvim_create_autocmd('LspDetach', {
callback = function(args) callback = function(args)
---@type integer ---@type integer
local bufnr = args.buf local bufnr = args.buf
local clients = vim.lsp.get_clients({ bufnr = bufnr, method = ms.textDocument_inlayHint }) local clients = vim.lsp.get_clients({ bufnr = bufnr, method = 'textDocument/inlayHint' })
if not vim.iter(clients):any(function(c) if not vim.iter(clients):any(function(c)
return c.id ~= args.data.client_id return c.id ~= args.data.client_id

View File

@@ -33,7 +33,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 protocol = require('vim.lsp.protocol') local protocol = require('vim.lsp.protocol')
local ms = require('vim.lsp.protocol').Methods
local grammar = require('vim.lsp._snippet_grammar') local grammar = require('vim.lsp._snippet_grammar')
local api = vim.api local api = vim.api
@@ -61,7 +60,7 @@ local namespace = api.nvim_create_namespace('nvim.lsp.inline_completion')
---@field client_state table<integer, vim.lsp.inline_completion.ClientState> ---@field client_state table<integer, vim.lsp.inline_completion.ClientState>
local Completor = { local Completor = {
name = 'inline_completion', name = 'inline_completion',
method = ms.textDocument_inlineCompletion, method = 'textDocument/inlineCompletion',
active = {}, active = {},
} }
Completor.__index = Completor Completor.__index = Completor
@@ -283,7 +282,7 @@ function Completor:request(kind)
position = util.make_position_params(0, client.offset_encoding).position, position = util.make_position_params(0, client.offset_encoding).position,
context = context, context = context,
} }
client:request(ms.textDocument_inlineCompletion, params, function(...) client:request('textDocument/inlineCompletion', params, function(...)
self:handler(...) self:handler(...)
end) end)
end end
@@ -318,7 +317,7 @@ end
function Completor:abort() function Completor:abort()
util._cancel_requests({ util._cancel_requests({
bufnr = self.bufnr, bufnr = self.bufnr,
method = ms.textDocument_inlineCompletion, method = 'textDocument/inlineCompletion',
type = 'pending', type = 'pending',
}) })
self:reset_timer() self:reset_timer()

View File

@@ -10,7 +10,7 @@
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 lsp = vim.lsp local lsp = vim.lsp
local method = require('vim.lsp.protocol').Methods.textDocument_linkedEditingRange local method = 'textDocument/linkedEditingRange'
local Range = require('vim.treesitter._range') local Range = require('vim.treesitter._range')
local api = vim.api local api = vim.api
local M = {} local M = {}

View File

@@ -1,7 +1,7 @@
local api = vim.api local api = vim.api
local lsp = vim.lsp local lsp = vim.lsp
local util = lsp.util local util = lsp.util
local method = lsp.protocol.Methods.textDocument_onTypeFormatting local method = 'textDocument/onTypeFormatting'
local schedule = vim.schedule local schedule = vim.schedule
local current_buf = api.nvim_get_current_buf local current_buf = api.nvim_get_current_buf

View File

@@ -789,6 +789,7 @@ end
--- | vim.lsp.protocol.Method.ServerToClient --- | vim.lsp.protocol.Method.ServerToClient
-- Generated by gen_lsp.lua, keep at end of file. -- Generated by gen_lsp.lua, keep at end of file.
--- @deprecated Use `vim.lsp.protocol.Method` instead.
--- @enum vim.lsp.protocol.Methods --- @enum vim.lsp.protocol.Methods
--- @see https://microsoft.github.io/language-server-protocol/specification/#metaModel --- @see https://microsoft.github.io/language-server-protocol/specification/#metaModel
--- LSP method names. --- LSP method names.

View File

@@ -1,6 +1,5 @@
local api = vim.api local api = vim.api
local bit = require('bit') local bit = require('bit')
local ms = require('vim.lsp.protocol').Methods
local util = require('vim.lsp.util') local util = require('vim.lsp.util')
local Range = require('vim.treesitter._range') local Range = require('vim.treesitter._range')
local uv = vim.uv local uv = vim.uv
@@ -43,7 +42,7 @@ local M = {}
---@field client_state table<integer, STClientState> ---@field client_state table<integer, STClientState>
local STHighlighter = { local STHighlighter = {
name = 'semantic_tokens', name = 'semantic_tokens',
method = ms.textDocument_semanticTokens_full, method = 'textDocument/semanticTokens/full',
active = {}, active = {},
} }
STHighlighter.__index = STHighlighter STHighlighter.__index = STHighlighter
@@ -255,12 +254,13 @@ 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 = ms.textDocument_semanticTokens_full local method = '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'
params.previousResultId = current_result.result_id params.previousResultId = current_result.result_id
end end
---@cast method vim.lsp.protocol.Method.ClientToServer.Request
---@param response? lsp.SemanticTokens|lsp.SemanticTokensDelta ---@param response? lsp.SemanticTokens|lsp.SemanticTokensDelta
local success, request_id = client:request(method, params, function(err, response, ctx) local success, request_id = client:request(method, params, function(err, response, ctx)
-- look client up again using ctx.client_id instead of using a captured -- look client up again using ctx.client_id instead of using a captured

View File

@@ -179,6 +179,7 @@ local function write_to_vim_protocol(protocol)
'--- | vim.lsp.protocol.Method.ServerToClient', '--- | vim.lsp.protocol.Method.ServerToClient',
'', '',
'-- Generated by gen_lsp.lua, keep at end of file.', '-- Generated by gen_lsp.lua, keep at end of file.',
'--- @deprecated',
'--- @enum vim.lsp.protocol.Methods', '--- @enum vim.lsp.protocol.Methods',
'--- @see https://microsoft.github.io/language-server-protocol/specification/#metaModel', '--- @see https://microsoft.github.io/language-server-protocol/specification/#metaModel',
'--- LSP method names.', '--- LSP method names.',

View File

@@ -211,7 +211,7 @@ describe('vim.lsp.diagnostic', function()
diagnosticProvider = {}, diagnosticProvider = {},
}, },
handlers = { handlers = {
[vim.lsp.protocol.Methods.textDocument_diagnostic] = function(_, params) ['textDocument/diagnostic'] = function(_, params)
_G.params = params _G.params = params
_G.requests = _G.requests + 1 _G.requests = _G.requests + 1
end, end,
@@ -421,7 +421,7 @@ describe('vim.lsp.diagnostic', function()
data = {}, data = {},
message = '', message = '',
}, {}, { }, {}, {
method = vim.lsp.protocol.Methods.textDocument_diagnostic, method = 'textDocument/diagnostic',
client_id = client_id, client_id = client_id,
bufnr = diagnostic_bufnr, bufnr = diagnostic_bufnr,
}) })
@@ -438,7 +438,7 @@ describe('vim.lsp.diagnostic', function()
data = { retriggerRequest = true }, data = { retriggerRequest = true },
message = '', message = '',
}, {}, { }, {}, {
method = vim.lsp.protocol.Methods.textDocument_diagnostic, method = 'textDocument/diagnostic',
client_id = client_id, client_id = client_id,
bufnr = diagnostic_bufnr, bufnr = diagnostic_bufnr,
}) })
@@ -455,7 +455,7 @@ describe('vim.lsp.diagnostic', function()
data = { retriggerRequest = false }, data = { retriggerRequest = false },
message = '', message = '',
}, {}, { }, {}, {
method = vim.lsp.protocol.Methods.textDocument_diagnostic, method = 'textDocument/diagnostic',
client_id = client_id, client_id = client_id,
bufnr = diagnostic_bufnr, bufnr = diagnostic_bufnr,
}) })
@@ -477,7 +477,7 @@ describe('vim.lsp.diagnostic', function()
_G.make_error('Pull Diagnostic', 4, 4, 4, 4), _G.make_error('Pull Diagnostic', 4, 4, 4, 4),
}, },
}, { }, {
method = vim.lsp.protocol.Methods.textDocument_diagnostic, method = 'textDocument/diagnostic',
params = { params = {
textDocument = { uri = fake_uri }, textDocument = { uri = fake_uri },
}, },
@@ -487,7 +487,7 @@ describe('vim.lsp.diagnostic', function()
vim.api.nvim_exec_autocmds('LspNotify', { vim.api.nvim_exec_autocmds('LspNotify', {
buffer = diagnostic_bufnr, buffer = diagnostic_bufnr,
data = { data = {
method = vim.lsp.protocol.Methods.textDocument_didChange, method = 'textDocument/didChange',
client_id = client_id, client_id = client_id,
}, },
}) })
@@ -503,7 +503,7 @@ describe('vim.lsp.diagnostic', function()
kind = 'unchanged', kind = 'unchanged',
resultId = 'squidward', resultId = 'squidward',
}, { }, {
method = vim.lsp.protocol.Methods.textDocument_diagnostic, method = 'textDocument/diagnostic',
params = { params = {
textDocument = { uri = fake_uri }, textDocument = { uri = fake_uri },
}, },
@@ -513,7 +513,7 @@ describe('vim.lsp.diagnostic', function()
vim.api.nvim_exec_autocmds('LspNotify', { vim.api.nvim_exec_autocmds('LspNotify', {
buffer = diagnostic_bufnr, buffer = diagnostic_bufnr,
data = { data = {
method = vim.lsp.protocol.Methods.textDocument_didChange, method = 'textDocument/didChange',
client_id = client_id, client_id = client_id,
}, },
}) })
@@ -560,7 +560,7 @@ describe('vim.lsp.diagnostic', function()
vim.api.nvim_exec_autocmds('LspNotify', { vim.api.nvim_exec_autocmds('LspNotify', {
buffer = second_buf, buffer = second_buf,
data = { data = {
method = vim.lsp.protocol.Methods.textDocument_didChange, method = 'textDocument/didChange',
client_id = client_id, client_id = client_id,
}, },
}) })