diff --git a/lua/lazyvim/plugins/extras/editor/navic.lua b/lua/lazyvim/plugins/extras/editor/navic.lua index e25d1b51..ef1ded8d 100644 --- a/lua/lazyvim/plugins/extras/editor/navic.lua +++ b/lua/lazyvim/plugins/extras/editor/navic.lua @@ -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) diff --git a/lua/lazyvim/plugins/lsp/keymaps.lua b/lua/lazyvim/plugins/lsp/keymaps.lua index 318ec911..c472f7e5 100644 --- a/lua/lazyvim/plugins/lsp/keymaps.lua +++ b/lua/lazyvim/plugins/lsp/keymaps.lua @@ -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 diff --git a/lua/lazyvim/util/lsp.lua b/lua/lazyvim/util/lsp.lua index e868dcf0..3d8c5be1 100644 --- a/lua/lazyvim/util/lsp.lua +++ b/lua/lazyvim/util/lsp.lua @@ -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)