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

Code before:
      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
---
--- Buffer number, or 0 for current buffer, or nil for all.
---@field bufnr? integer
---
--- Client ID, or nil for all
---@field client_id? integer

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

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

  local var = make_enable_var(feature)
  local client_var = make_enable_var(feature, client_id)
  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.enable.Filter

Review comment (suggestion):
(Non-blocker; we can try it out and revisit later:) This could end up creating many top-level _lsp_...<client> vars. That's pretty noisy. It might be worth the trouble to define a single _lsp_enable table and manage things in there, e.g.

```
_lsp_enable = {
  client = { [42] = true, [78] = true, ... },
}
```

Code after:
          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
---
--- Buffer number, or 0 for current buffer, or nil for all.
---@field bufnr? integer
---
--- Client ID, or nil for all
---@field client_id? integer

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

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

  local var = make_enable_var(feature)
  local client_var = make_enable_var(feature, client_id)
  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])