From 9def60f1dd09ac2244672b8570092229977b43b4 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Thu, 6 Oct 2022 08:55:06 +0200 Subject: feat: lock new installations to nvim 0.8+ (#3111) --- lua/lvim/lsp/utils.lua | 57 ++++++-------------------------------------------- 1 file changed, 6 insertions(+), 51 deletions(-) (limited to 'lua/lvim/lsp/utils.lua') diff --git a/lua/lvim/lsp/utils.lua b/lua/lvim/lsp/utils.lua index 53571f20..44e4f5f7 100644 --- a/lua/lvim/lsp/utils.lua +++ b/lua/lvim/lsp/utils.lua @@ -23,25 +23,14 @@ function M.get_active_clients_by_ft(filetype) end function M.get_client_capabilities(client_id) - local client - if not client_id then - local buf_clients = vim.lsp.buf_get_clients() - for _, buf_client in pairs(buf_clients) do - if buf_client.name ~= "null-ls" then - client = buf_client - break - end - end - else - client = vim.lsp.get_client_by_id(tonumber(client_id)) - end + local client = vim.lsp.get_client_by_id(tonumber(client_id)) if not client then - error "Unable to determine client_id" + Log:warn("Unable to determine client from client_id: " .. client_id) return end local enabled_caps = {} - for capability, status in pairs(client.server_capabilities or client.resolved_capabilities) do + for capability, status in pairs(client.server_capabilities) do if status == true then table.insert(enabled_caps, capability) end @@ -178,47 +167,13 @@ function M.format_filter(client) end end ----Provide vim.lsp.buf.format for nvim <0.8 ----@param opts table +---Simple wrapper for vim.lsp.buf.format() to provide defaults +---@param opts table|nil function M.format(opts) opts = opts or {} opts.filter = opts.filter or M.format_filter - if vim.lsp.buf.format then - return vim.lsp.buf.format(opts) - end - - local bufnr = opts.bufnr or vim.api.nvim_get_current_buf() - - ---@type table|nil - local clients = vim.lsp.get_active_clients { - id = opts.id, - bufnr = bufnr, - name = opts.name, - } - - if opts.filter then - clients = vim.tbl_filter(opts.filter, clients) - end - - clients = vim.tbl_filter(function(client) - return client.supports_method "textDocument/formatting" - end, clients) - - if #clients == 0 then - vim.notify_once "[LSP] Format request failed, no matching language servers." - end - - local timeout_ms = opts.timeout_ms or 1000 - for _, client in pairs(clients) do - local params = vim.lsp.util.make_formatting_params(opts.formatting_options) - local result, err = client.request_sync("textDocument/formatting", params, timeout_ms, bufnr) - if result and result.result then - vim.lsp.util.apply_text_edits(result.result, bufnr, client.offset_encoding) - elseif err then - vim.notify(string.format("[LSP][%s] %s", client.name, err), vim.log.levels.WARN) - end - end + return vim.lsp.buf.format(opts) end return M -- cgit v1.2.3