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

Code before:
  local bufstate = assert(bufstates[bufnr])

  ---@type table<integer, [integer, ">" | "<"?]?>
  local row_level = {}
  ---@type table<integer, table<lsp.FoldingRangeKind, true?>?>>
  local row_kinds = {}
  ---@type table<integer, string?>
  local row_text = {}

  for _, ranges in pairs(bufstate.client_ranges) do
    for _, range in ipairs(ranges) do
      local start_row = range.startLine
      local end_row = range.endLine
      -- Adding folds within a single line is not supported by Nvim.
      if start_row ~= end_row then
        row_text[start_row] = range.collapsedText

        local kind = range.kind
        if kind then
          -- Ignore unsupported fold kinds.
          if supported_fold_kinds[kind] then
            local kinds = row_kinds[start_row] or {}
            kinds[kind] = true
            row_kinds[start_row] = kinds
          else
            log.warn(('Received unsupported fold kind: "%s"'):format(kind))
          end
        end

        for row = start_row, end_row do
          local level = row_level[row] or { 0 }
          level[1] = level[1] + 1
          row_level[row] = level
        end
        row_level[start_row][2] = '>'
        row_level[end_row][2] = '<'
      end
    end
  end

  bufstate.row_level = row_level
  bufstate.row_kinds = row_kinds
  bufstate.row_text = row_text
end

--- Renew the cached foldinfo then force `foldexpr()` to be re-evaluated,
--- without opening folds.
---@param bufnr integer
local function foldupdate(bufnr)
  renew(bufnr)
  for _, winid in ipairs(vim.fn.win_findbuf(bufnr)) do

Review comment (suggestion):
Let's use `info` as we do with unknown diagnostic tags: https://github.com/neovim/neovim/blob/492ea28612b2e47e187d6a37f582267655ba79fe/runtime/lua/vim/lsp/diagnostic.lua#L78

Code after:
  local bufstate = assert(bufstates[bufnr])

  ---@type table<integer, [integer, ">" | "<"?]?>
  local row_level = {}
  ---@type table<integer, table<lsp.FoldingRangeKind, true?>?>>
  local row_kinds = {}
  ---@type table<integer, string?>
  local row_text = {}

  for _, ranges in pairs(bufstate.client_ranges) do
    for _, range in ipairs(ranges) do
      local start_row = range.startLine
      local end_row = range.endLine
      -- Adding folds within a single line is not supported by Nvim.
      if start_row ~= end_row then
        row_text[start_row] = range.collapsedText

        local kind = range.kind
        if kind then
          -- Ignore unsupported fold kinds.
          if supported_fold_kinds[kind] then
            local kinds = row_kinds[start_row] or {}
            kinds[kind] = true
            row_kinds[start_row] = kinds
          else
            log.info(('Received unsupported fold kind: "%s"'):format(kind))
          end
        end

        for row = start_row, end_row do
          local level = row_level[row] or { 0 }
          level[1] = level[1] + 1
          row_level[row] = level
        end
        row_level[start_row][2] = '>'
        row_level[end_row][2] = '<'
      end
    end
  end

  bufstate.row_level = row_level
  bufstate.row_kinds = row_kinds
  bufstate.row_text = row_text
end

--- Renew the cached foldinfo then force `foldexpr()` to be re-evaluated,
--- without opening folds.
---@param bufnr integer
local function foldupdate(bufnr)
  renew(bufnr)
  for _, winid in ipairs(vim.fn.win_findbuf(bufnr)) do