mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-22 04:21:08 +00:00
fix(lsp): fixed deprecated warnings
This commit is contained in:
parent
10e5bf5c5b
commit
bed725a054
2 changed files with 39 additions and 4 deletions
|
|
@ -54,7 +54,7 @@ function M.has(buffer, method)
|
||||||
method = method:find("/") and method or "textDocument/" .. method
|
method = method:find("/") and method or "textDocument/" .. method
|
||||||
local clients = LazyVim.lsp.get_clients({ bufnr = buffer })
|
local clients = LazyVim.lsp.get_clients({ bufnr = buffer })
|
||||||
for _, client in ipairs(clients) do
|
for _, client in ipairs(clients) do
|
||||||
if client.supports_method(method) then
|
if client:supports_method(method) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,51 @@
|
||||||
---@class lazyvim.util.lsp
|
---@class lazyvim.util.lsp
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
---@alias lsp.Client.filter {id?: number, bufnr?: number, name?: string, method?: string, filter?:fun(client: lsp.Client):boolean}
|
---@alias lsp.Client.filter {id?: number, bufnr?: number, name?: string, method?: string, filter?:fun(client: vim.lsp.Client):boolean}
|
||||||
|
|
||||||
|
--- Neovim 0.11 uses a lua class for clients, while older versions use a table.
|
||||||
|
--- Wraps older style clients to be compatible with the new style.
|
||||||
|
---@param client vim.lsp.Client
|
||||||
|
---@return vim.lsp.Client
|
||||||
|
local function wrap(client)
|
||||||
|
local meta = getmetatable(client)
|
||||||
|
if meta and meta.request then
|
||||||
|
return client
|
||||||
|
end
|
||||||
|
---@diagnostic disable-next-line: undefined-field
|
||||||
|
if client.wrapped then
|
||||||
|
return client
|
||||||
|
end
|
||||||
|
local methods = { "request", "supports_method", "cancel_request", "notify" }
|
||||||
|
-- old style
|
||||||
|
return setmetatable({ wrapped = true }, {
|
||||||
|
__index = function(_, k)
|
||||||
|
if k == "supports_method" then
|
||||||
|
-- supports_method doesn't support the bufnr argument
|
||||||
|
return function(_, method)
|
||||||
|
return client[k](method)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if vim.tbl_contains(methods, k) then
|
||||||
|
return function(_, ...)
|
||||||
|
return client[k](...)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return client[k]
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
---@param opts? lsp.Client.filter
|
---@param opts? lsp.Client.filter
|
||||||
function M.get_clients(opts)
|
function M.get_clients(opts)
|
||||||
local ret = {} ---@type vim.lsp.Client[]
|
local ret = {} ---@type vim.lsp.Client[]
|
||||||
if vim.lsp.get_clients then
|
if vim.lsp.get_clients then
|
||||||
ret = vim.lsp.get_clients(opts)
|
ret = vim.lsp.get_clients(opts)
|
||||||
|
ret = vim.tbl_map(wrap, ret)
|
||||||
else
|
else
|
||||||
---@diagnostic disable-next-line: deprecated
|
---@diagnostic disable-next-line: deprecated
|
||||||
ret = vim.lsp.get_active_clients(opts)
|
ret = vim.lsp.get_active_clients(opts)
|
||||||
|
ret = vim.tbl_map(wrap, ret)
|
||||||
if opts and opts.method then
|
if opts and opts.method then
|
||||||
---@param client vim.lsp.Client
|
---@param client vim.lsp.Client
|
||||||
ret = vim.tbl_filter(function(client)
|
ret = vim.tbl_filter(function(client)
|
||||||
|
|
@ -29,7 +64,7 @@ function M.on_attach(on_attach, name)
|
||||||
local buffer = args.buf ---@type number
|
local buffer = args.buf ---@type number
|
||||||
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
||||||
if client and (not name or client.name == name) then
|
if client and (not name or client.name == name) then
|
||||||
return on_attach(client, buffer)
|
return on_attach(wrap(client), buffer)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
@ -75,7 +110,7 @@ function M._check_methods(client, buffer)
|
||||||
for method, clients in pairs(M._supports_method) do
|
for method, clients in pairs(M._supports_method) do
|
||||||
clients[client] = clients[client] or {}
|
clients[client] = clients[client] or {}
|
||||||
if not clients[client][buffer] then
|
if not clients[client][buffer] then
|
||||||
if client.supports_method and client.supports_method(method, { bufnr = buffer }) then
|
if client.supports_method and client:supports_method(method, { bufnr = buffer }) then
|
||||||
clients[client][buffer] = true
|
clients[client][buffer] = true
|
||||||
vim.api.nvim_exec_autocmds("User", {
|
vim.api.nvim_exec_autocmds("User", {
|
||||||
pattern = "LspSupportsMethod",
|
pattern = "LspSupportsMethod",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue