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

Code before:
    -- If server is being restarted, make sure to re-attach to any previously attached buffers.
    -- Save which buffers before on_init in case new buffers are attached.
    local reattach_bufs = vim.deepcopy(self.attached_buffers)

    self:_run_callbacks(self._on_init_cbs, lsp.client_errors.ON_INIT_CALLBACK_ERROR, self, result)

    for buf in pairs(reattach_bufs) do
      -- The buffer may have been detached in the on_init callback.
      if self.attached_buffers[buf] then
        self:on_attach(buf)
      end
    end

    log.info(
      self._log_prefix,
      'server_capabilities',
      { server_capabilities = self.server_capabilities }
    )
  end)
end

--- @private
function Client:_process_static_registrations()
  local static_registrations = {} ---@type lsp.Registration[]

  for method, _ in pairs(lsp.protocol._method_supports_static_registration) do
    local capability = lsp.protocol._request_name_to_server_capability[method]
    if
      vim.tbl_get(self.server_capabilities, capability[1], 'id')
      and self:_supports_registration(method)
    then
      local cap = vim.tbl_get(self.server_capabilities, capability[1])
      static_registrations[#static_registrations + 1] = {
        id = cap.id,
        method = method,
        registerOptions = vim.tbl_extend('force', {}, cap),
      }
    end
  end

  if next(static_registrations) then
    self:_register_dynamic(static_registrations)
  end
end

--- @private
--- Returns the handler associated with an LSP method.
--- Returns the default handler if the user hasn't set a custom one.
---
--- @param method (vim.lsp.protocol.Method) LSP method name
--- @return lsp.Handler? handler for the given method, if defined, or the default from |vim.lsp.handlers|

Review comment (suggestion):
Nit:
```suggestion
  for method in pairs(lsp.protocol._method_supports_static_registration) do
```

Code after:
    -- Save which buffers before on_init in case new buffers are attached.
    local reattach_bufs = vim.deepcopy(self.attached_buffers)

    self:_run_callbacks(self._on_init_cbs, lsp.client_errors.ON_INIT_CALLBACK_ERROR, self, result)

    for buf in pairs(reattach_bufs) do
      -- The buffer may have been detached in the on_init callback.
      if self.attached_buffers[buf] then
        self:on_attach(buf)
      end
    end

    log.info(
      self._log_prefix,
      'server_capabilities',
      { server_capabilities = self.server_capabilities }
    )
  end)
end

--- @private
function Client:_process_static_registrations()
  local static_registrations = {} ---@type lsp.Registration[]

  for method in pairs(lsp.protocol._method_supports_static_registration) do
    local capability = lsp.protocol._request_name_to_server_capability[method]
    if
      vim.tbl_get(self.server_capabilities, capability[1], 'id')
      and self:_supports_registration(method)
    then
      local cap = vim.tbl_get(self.server_capabilities, capability[1])
      static_registrations[#static_registrations + 1] = {
        id = cap.id,
        method = method,
        registerOptions = cap or {},
      }
    end
  end

  if next(static_registrations) then
    self:_register_dynamic(static_registrations)
  end
end

--- @private
--- Returns the handler associated with an LSP method.
--- Returns the default handler if the user hasn't set a custom one.
---
--- @param method (vim.lsp.protocol.Method) LSP method name
--- @return lsp.Handler? handler for the given method, if defined, or the default from |vim.lsp.handlers|
function Client:_resolve_handler(method)