mirror of
https://github.com/neovim/neovim.git
synced 2025-10-08 02:46:31 +00:00
fix(lsp): deprecate vim.lsp.protocol.Methods
(#35998)
This commit is contained in:
@@ -28,7 +28,6 @@ local lsp = vim._defer_require('vim.lsp', {
|
||||
|
||||
local log = lsp.log
|
||||
local protocol = lsp.protocol
|
||||
local ms = protocol.Methods
|
||||
local util = lsp.util
|
||||
local changetracking = lsp._changetracking
|
||||
|
||||
@@ -37,10 +36,10 @@ local changetracking = lsp._changetracking
|
||||
lsp.rpc_response_error = lsp.rpc.rpc_response_error
|
||||
|
||||
lsp._resolve_to_request = {
|
||||
[ms.codeAction_resolve] = ms.textDocument_codeAction,
|
||||
[ms.codeLens_resolve] = ms.textDocument_codeLens,
|
||||
[ms.documentLink_resolve] = ms.textDocument_documentLink,
|
||||
[ms.inlayHint_resolve] = ms.textDocument_inlayHint,
|
||||
['codeAction/resolve'] = 'textDocument/codeAction',
|
||||
['codeLens/resolve'] = 'textDocument/codeLens',
|
||||
['documentLink/resolve'] = 'textDocument/documentLink',
|
||||
['inlayHint/resolve'] = 'textDocument/inlayHint',
|
||||
}
|
||||
|
||||
-- TODO improve handling of scratch buffers with LSP attached.
|
||||
@@ -764,17 +763,17 @@ end
|
||||
---@param bufnr integer
|
||||
function lsp._set_defaults(client, bufnr)
|
||||
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
|
||||
vim.bo[bufnr].tagfunc = 'v:lua.vim.lsp.tagfunc'
|
||||
end
|
||||
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
|
||||
vim.bo[bufnr].omnifunc = 'v:lua.vim.lsp.omnifunc'
|
||||
end
|
||||
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, 'formatexpr')
|
||||
then
|
||||
@@ -782,7 +781,7 @@ function lsp._set_defaults(client, bufnr)
|
||||
end
|
||||
vim._with({ buf = bufnr }, function()
|
||||
if
|
||||
client:supports_method(ms.textDocument_hover)
|
||||
client:supports_method('textDocument/hover')
|
||||
and is_empty_or_default(bufnr, 'keywordprg')
|
||||
and vim.fn.maparg('K', 'n', false, false) == ''
|
||||
then
|
||||
@@ -791,7 +790,7 @@ function lsp._set_defaults(client, bufnr)
|
||||
end, { buffer = bufnr, desc = 'vim.lsp.buf.hover()' })
|
||||
end
|
||||
end)
|
||||
if client:supports_method(ms.textDocument_diagnostic) then
|
||||
if client:supports_method('textDocument/diagnostic') then
|
||||
lsp.diagnostic._enable(bufnr)
|
||||
end
|
||||
end
|
||||
@@ -818,12 +817,12 @@ local function text_document_did_save_handler(bufnr)
|
||||
local name = api.nvim_buf_get_name(bufnr)
|
||||
local old_name = changetracking._get_and_set_name(client, bufnr, name)
|
||||
if old_name and name ~= old_name then
|
||||
client:notify(ms.textDocument_didClose, {
|
||||
client:notify('textDocument/didClose', {
|
||||
textDocument = {
|
||||
uri = vim.uri_from_fname(old_name),
|
||||
},
|
||||
})
|
||||
client:notify(ms.textDocument_didOpen, {
|
||||
client:notify('textDocument/didOpen', {
|
||||
textDocument = {
|
||||
version = 0,
|
||||
uri = uri,
|
||||
@@ -839,7 +838,7 @@ local function text_document_did_save_handler(bufnr)
|
||||
if type(save_capability) == 'table' and save_capability.includeText then
|
||||
included_text = text(bufnr)
|
||||
end
|
||||
client:notify(ms.textDocument_didSave, {
|
||||
client:notify('textDocument/didSave', {
|
||||
textDocument = {
|
||||
uri = uri,
|
||||
},
|
||||
@@ -874,12 +873,12 @@ local function buf_attach(bufnr)
|
||||
},
|
||||
reason = protocol.TextDocumentSaveReason.Manual, ---@type integer
|
||||
}
|
||||
if client:supports_method(ms.textDocument_willSave) then
|
||||
client:notify(ms.textDocument_willSave, params)
|
||||
if client:supports_method('textDocument/willSave') then
|
||||
client:notify('textDocument/willSave', params)
|
||||
end
|
||||
if client:supports_method(ms.textDocument_willSaveWaitUntil) then
|
||||
if client:supports_method('textDocument/willSaveWaitUntil') then
|
||||
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
|
||||
util.apply_text_edits(result.result, ctx.buf, client.offset_encoding)
|
||||
elseif err then
|
||||
@@ -913,8 +912,8 @@ local function buf_attach(bufnr)
|
||||
local params = { textDocument = { uri = uri } }
|
||||
for _, client in ipairs(clients) do
|
||||
changetracking.reset_buf(client, bufnr)
|
||||
if client:supports_method(ms.textDocument_didClose) then
|
||||
client:notify(ms.textDocument_didClose, params)
|
||||
if client:supports_method('textDocument/didClose') then
|
||||
client:notify('textDocument/didClose', params)
|
||||
end
|
||||
end
|
||||
for _, client in ipairs(clients) do
|
||||
@@ -1371,7 +1370,7 @@ function lsp.formatexpr(opts)
|
||||
end
|
||||
local bufnr = api.nvim_get_current_buf()
|
||||
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 end_line = vim.fn.getline(end_lnum) --[[@as string]]
|
||||
local end_col = vim.str_utfindex(end_line, client.offset_encoding)
|
||||
@@ -1387,7 +1386,7 @@ function lsp.formatexpr(opts)
|
||||
},
|
||||
}
|
||||
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
|
||||
util.apply_text_edits(response.result, bufnr, client.offset_encoding)
|
||||
return 0
|
||||
|
Reference in New Issue
Block a user