diff options
| author | kylo252 <[email protected]> | 2022-10-06 08:55:06 +0200 | 
|---|---|---|
| committer | GitHub <[email protected]> | 2022-10-06 06:55:06 +0000 | 
| commit | 9def60f1dd09ac2244672b8570092229977b43b4 (patch) | |
| tree | 44bf396deaa7ce20ebc789f95bd03494d2393488 /lua/lvim/lsp/utils.lua | |
| parent | 0d578ab152708019ad10cb7b21fc4a1cb0105a1a (diff) | |
feat: lock new installations to nvim 0.8+ (#3111)
Diffstat (limited to 'lua/lvim/lsp/utils.lua')
| -rw-r--r-- | lua/lvim/lsp/utils.lua | 57 | 
1 files changed, 6 insertions, 51 deletions
| 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 | 
