Repository: neovim/neovim
File: runtime/lua/vim/lsp.lua (Lua)

Code before:
    then
      clients[#clients + 1] = client
    end
  end
  return clients
end

---@deprecated
function lsp.get_active_clients(filter)
  vim.deprecate('vim.lsp.get_active_clients()', 'vim.lsp.get_clients()', '0.12')
  return lsp.get_clients(filter)
end

api.nvim_create_autocmd('VimLeavePre', {
  desc = 'vim.lsp: exit handler',
  callback = function()
    local active_clients = lsp.get_clients()
    log.info('exit_handler', active_clients)

    local max_timeout = 0
    for _, client in pairs(active_clients) do
      local timeout = client.exit_timeout
      client:stop(timeout)
      if type(timeout) == 'number' then
        max_timeout = math.max(max_timeout, timeout)
      end
    end
    if max_timeout > 10 then
      api.nvim_echo({
        {
          string.format('Waiting %ss for lsp exit (Press Ctrl-C to force exit)', max_timeout / 1e3),
          'WarningMsg',
        },
      }, true, {})
    end

    vim.wait(max_timeout, function()
      return vim.iter(active_clients):all(function(client)
        return client.rpc.is_closing()
      end)
    end)
  end,
})

---@nodoc
--- Sends an async request for all active clients attached to the
--- buffer.
---
---@param bufnr (integer) Buffer handle, or 0 for current.
---@param method (vim.lsp.protocol.Method.ClientToServer.Request) LSP method name
---@param params? table|(fun(client: vim.lsp.Client, bufnr: integer): table?) Parameters to send to the server

Review comment (suggestion):
```suggestion
      max_timeout = math.max(max_timeout, tonumber(client.exit_timeout) or 0)
      client:stop(client.exit_timeout)
```

Code after:
    then
      clients[#clients + 1] = client
    end
  end
  return clients
end

---@deprecated
function lsp.get_active_clients(filter)
  vim.deprecate('vim.lsp.get_active_clients()', 'vim.lsp.get_clients()', '0.12')
  return lsp.get_clients(filter)
end

api.nvim_create_autocmd('VimLeavePre', {
  desc = 'vim.lsp: exit handler',
  callback = function()
    local active_clients = lsp.get_clients()
    log.info('exit_handler', active_clients)

    local max_timeout = 0
    for _, client in pairs(active_clients) do
      max_timeout = math.max(max_timeout, tonumber(client.exit_timeout) or 0)
      client:stop(client.exit_timeout)
    end
    if max_timeout > 10 then
      api.nvim_echo({
        {
          string.format('Waiting %ss for lsp exit (Press Ctrl-C to force exit)', max_timeout / 1e3),
          'WarningMsg',
        },
      }, true, {})
    end

    vim.wait(max_timeout, function()
      return vim.iter(active_clients):all(function(client)
        return client.rpc.is_closing()
      end)
    end)
  end,
})

---@nodoc
--- Sends an async request for all active clients attached to the
--- buffer.
---
---@param bufnr (integer) Buffer handle, or 0 for current.
---@param method (vim.lsp.protocol.Method.ClientToServer.Request) LSP method name
---@param params? table|(fun(client: vim.lsp.Client, bufnr: integer): table?) Parameters to send to the server
---@param handler? lsp.Handler See |lsp-handler|
---       If nil, follows resolution strategy defined in |lsp-handler-configuration|
---@param on_unsupported? fun()