mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-25 14:01:06 +00:00
fix(lsp): use supports_method method instead of field on Neovim >= 0.11
This commit is contained in:
parent
cb223553ff
commit
6e21ac4962
3 changed files with 19 additions and 6 deletions
|
|
@ -8,7 +8,10 @@ return {
|
|||
init = function()
|
||||
vim.g.navic_silence = true
|
||||
LazyVim.lsp.on_attach(function(client, buffer)
|
||||
if client.supports_method("textDocument/documentSymbol") then
|
||||
if
|
||||
vim.fn.has("nvim-0.11") == 0 and client.supports_method("textDocument/documentSymbol")
|
||||
or client:supports_method("textDocument/documentSymbol")
|
||||
then
|
||||
require("nvim-navic").attach(client, buffer)
|
||||
end
|
||||
end)
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ function M.has(buffer, method)
|
|||
method = method:find("/") and method or "textDocument/" .. method
|
||||
local clients = LazyVim.lsp.get_clients({ bufnr = buffer })
|
||||
for _, client in ipairs(clients) do
|
||||
if client.supports_method(method) then
|
||||
if vim.fn.has("nvim-0.11") == 0 and client.supports_method(method) or client:supports_method(method) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,16 @@
|
|||
---@class lazyvim.util.lsp
|
||||
local M = {}
|
||||
|
||||
---@param client vim.lsp.Client
|
||||
---@param method string
|
||||
---@param bufnr? integer
|
||||
local function supports_method(client, method, bufnr)
|
||||
if vim.fn.has("nvim-0.11") == 0 then
|
||||
return client.supports_method and client.supports_method(method, { bufnr = bufnr })
|
||||
end
|
||||
return client:supports_method(method, bufnr) and client:supports_method(method, bufnr)
|
||||
end
|
||||
|
||||
---@alias lsp.Client.filter {id?: number, bufnr?: number, name?: string, method?: string, filter?:fun(client: lsp.Client):boolean}
|
||||
|
||||
---@param opts? lsp.Client.filter
|
||||
|
|
@ -14,7 +24,7 @@ function M.get_clients(opts)
|
|||
if opts and opts.method then
|
||||
---@param client vim.lsp.Client
|
||||
ret = vim.tbl_filter(function(client)
|
||||
return client.supports_method(opts.method, { bufnr = opts.bufnr })
|
||||
return supports_method(client, opts.method, opts.bufnr)
|
||||
end, ret)
|
||||
end
|
||||
end
|
||||
|
|
@ -75,7 +85,7 @@ function M._check_methods(client, buffer)
|
|||
for method, clients in pairs(M._supports_method) do
|
||||
clients[client] = clients[client] or {}
|
||||
if not clients[client][buffer] then
|
||||
if client.supports_method and client.supports_method(method, { bufnr = buffer }) then
|
||||
if supports_method(client, method, buffer) then
|
||||
clients[client][buffer] = true
|
||||
vim.api.nvim_exec_autocmds("User", {
|
||||
pattern = "LspSupportsMethod",
|
||||
|
|
@ -169,8 +179,8 @@ function M.formatter(opts)
|
|||
local clients = M.get_clients(LazyVim.merge({}, filter, { bufnr = buf }))
|
||||
---@param client vim.lsp.Client
|
||||
local ret = vim.tbl_filter(function(client)
|
||||
return client.supports_method("textDocument/formatting")
|
||||
or client.supports_method("textDocument/rangeFormatting")
|
||||
return supports_method(client, "textDocument/formatting")
|
||||
or supports_method(client, "textDocument/rangeFormatting")
|
||||
end, clients)
|
||||
---@param client vim.lsp.Client
|
||||
return vim.tbl_map(function(client)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue