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, capability in pairs(vim.lsp.protocol._request_name_to_server_capability) do
    if
      vim.tbl_get(self.server_capabilities, unpack(capability), 'id')
      --- @cast method vim.lsp.protocol.Method
      and self:_supports_registration(method)
    then
      local cap = vim.tbl_get(self.server_capabilities, unpack(capability))
      static_registrations[#static_registrations + 1] = {
        id = cap.id,
        method = method,
        registerOptions = {
          documentSelector = cap.documentSelector, ---@type lsp.DocumentSelector|lsp.null
        },
      }
    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.
---

Review comment (suggestion):
```suggestion
  for method, capability in pairs(lsp.protocol._request_name_to_server_capability) do
```
Since the import is aliased above.

Code after:
    -- 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, capability in pairs(lsp.protocol._request_name_to_server_capability) do
    if
      vim.tbl_get(self.server_capabilities, unpack(capability), 'id')
      --- @cast method vim.lsp.protocol.Method
      and self:_supports_registration(method)
    then
      local cap = vim.tbl_get(self.server_capabilities, unpack(capability))
      static_registrations[#static_registrations + 1] = {
        id = cap.id,
        method = method,
        registerOptions = {
          documentSelector = cap.documentSelector, ---@type lsp.DocumentSelector|lsp.null
        },
      }
    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.
---