---@class lib.lsp
local M = {}

---Boilerplate to create an autocommand to do something on LspAttach.
---@param callback fun(client:vim.lsp.Client, buffer:number)
---@param name? string
function M.on_attach(callback, name)
  return vim.api.nvim_create_autocmd('LspAttach', {
    callback = function(args)
      local buffer = args.buf ---@type number
      local client = vim.lsp.get_client_by_id(args.data.client_id)

      if client and (not name or client.name == name) then
        return callback(client, buffer)
      end
    end,
  })
end

return M