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

Code before:
          type = 'pending',
        })
        for _, client in ipairs(clients) do
          client:request(method, {
            textDocument = textDocument,
            range = make_line_range_params(bufnr, first - 1, last - 1, client.offset_encoding),
          }, opts.handler, bufnr)
        end
      end
    end
  else
    for _, client in ipairs(clients) do
      client:request(method, {
        textDocument = textDocument,
        range = make_line_range_params(
          bufnr,
          0,
          api.nvim_buf_line_count(bufnr) - 1,
          client.offset_encoding
        ),
      }, opts.handler, bufnr)
    end
  end
end

---@class (private) vim.lsp.util.enable.Filter
---@field bufnr? integer
---@field client_id? integer

---@param feature string
---@param filter? vim.lsp.util.enable.Filter
function M._is_enabled(feature, filter)
  vim.validate('filter', filter, 'table', true)

  filter = filter or {}
  local bufnr = filter.bufnr
  local client_id = filter.client_id

  local var = ('__lsp_%s_enabled'):format(feature)
  local client_var = ('__lsp_%s_client_%d_enabled'):format(feature, client_id or 0)
  return vim.F.if_nil(client_id and vim.g[client_var], vim.g[var])
    and vim.F.if_nil(bufnr and vim.b[bufnr][var], vim.g[var])
end

---@param feature string
---@param enable? boolean
---@param filter? vim.lsp.util.enable.Filter
function M._enable(feature, enable, filter)
  vim.validate('enable', enable, 'boolean', true)
  vim.validate('filter', filter, 'table', true)


Review comment (suggestion):
I would consider renaming this to `vim.lsp.enable.Filter` and then removing `vim.lsp.semantic_tokens.enable.Filter` to use this type instead.

Code after:
  local clients = vim.lsp.get_clients({ bufnr = bufnr, method = method, id = opts.client_id })

  if #clients == 0 then
    return
  end

  local textDocument = M.make_text_document_params(bufnr)

  if opts.only_visible then
    for _, window in ipairs(api.nvim_list_wins()) do
      if api.nvim_win_get_buf(window) == bufnr then
        local first = vim.fn.line('w0', window)
        local last = vim.fn.line('w$', window)
        M._cancel_requests({
          bufnr = bufnr,
          clients = clients,
          method = method,
          type = 'pending',
        })
        for _, client in ipairs(clients) do
          client:request(method, {
            textDocument = textDocument,
            range = make_line_range_params(bufnr, first - 1, last - 1, client.offset_encoding),
          }, opts.handler, bufnr)
        end
      end
    end
  else
    for _, client in ipairs(clients) do
      client:request(method, {
        textDocument = textDocument,
        range = make_line_range_params(
          bufnr,
          0,
          api.nvim_buf_line_count(bufnr) - 1,
          client.offset_encoding
        ),
      }, opts.handler, bufnr)
    end
  end
end

---@param feature string
---@param client_id? integer
local function make_enable_var(feature, client_id)
  return ('_lsp_enabled_%s%s'):format(feature, client_id and ('_client_%d'):format(client_id) or '')
end

---@class vim.lsp.enable.Filter
---@inlinedoc
---