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

Code before:
  local clients = vim.lsp.get_clients()
  if next(clients) then
    for _, client in pairs(clients) do
      local server_version = vim.tbl_get(client, 'server_info', 'version')
        or '? (no serverInfo.version response)'
      local cmd ---@type string
      local ccmd = client.config.cmd
      if type(ccmd) == 'table' then
        cmd = vim.inspect(ccmd)
      elseif type(ccmd) == 'function' then
        cmd = func_tostring(ccmd)
      end
      local dirs_info ---@type string
      if client.workspace_folders and #client.workspace_folders > 1 then
        local wfolders = {} --- @type string[]
        for _, dir in ipairs(client.workspace_folders) do
          wfolders[#wfolders + 1] = dir.name
        end
        dirs_info = ('- Workspace folders:\n    %s'):format(table.concat(wfolders, '\n    '))
      else
        local root_dirs = {} ---@type string[]
        if type(client.root_dir) == 'string' then
          table.insert(root_dirs, client.root_dir --[[@as string]])
        elseif type(client.root_dir) == 'function' then
          for buf, _ in pairs(client.attached_buffers) do
            client.root_dir(buf, function(dir)
              if dir then
                table.insert(root_dirs, dir)
              end
            end)
          end
        end
        if #root_dirs == 1 then
          dirs_info = string.format('- Root directory: %s', vim.fn.fnamemodify(root_dirs[1], ':~'))
        elseif #root_dirs > 1 then
          dirs_info = string.format(
            '- Root directories:\n    %s',
            table.concat(
              vim.iter(root_dirs):map(function(x)
                vim.fn.fnamemodify(x, ':~')
              end),
              '\n    '
            )
          )
        end
      end
      report_info(table.concat({
        string.format('%s (id: %d)', client.name, client.id),
        string.format('- Version: %s', server_version),
        dirs_info,
        string.format('- Command: %s', cmd),

Review comment (suggestion):
if there are many `attached_buffers` all resolving to the same root, this will show many redundant root dirs.

i will fix this in a push.

Code after:
  local clients = vim.lsp.get_clients()
  if next(clients) then
    for _, client in pairs(clients) do
      local server_version = vim.tbl_get(client, 'server_info', 'version')
        or '? (no serverInfo.version response)'
      local cmd ---@type string
      local ccmd = client.config.cmd
      if type(ccmd) == 'table' then
        cmd = vim.inspect(ccmd)
      elseif type(ccmd) == 'function' then
        cmd = func_tostring(ccmd)
      end
      local dirs_info ---@type string
      if client.workspace_folders and #client.workspace_folders > 1 then
        local wfolders = {} --- @type string[]
        for _, dir in ipairs(client.workspace_folders) do
          wfolders[#wfolders + 1] = dir.name
        end
        dirs_info = ('- Workspace folders:\n    %s'):format(table.concat(wfolders, '\n    '))
      else
        local root_dirs = {} ---@type table<string, boolean>
        local timeout = 1
        local timeoutmsg = ('root_dir() took > %ds'):format(timeout)
        for buf, _ in pairs(client.attached_buffers) do
          local dir = client._resolve_root_dir(1000, buf, client.root_dir)
          root_dirs[dir or timeoutmsg] = true
        end
        dirs_info = string.format(
          '- Root %s:\n    %s',
          vim.tbl_count(root_dirs) > 1 and 'directories' or 'directory',
          vim
            .iter(root_dirs)
            :map(function(k, _)
              return k == timeoutmsg and timeoutmsg or vim.fn.fnamemodify(k, ':~')
            end)
            :join('\n    ')
        )
      end
      report_info(table.concat({
        string.format('%s (id: %d)', client.name, client.id),
        string.format('- Version: %s', server_version),
        dirs_info,
        string.format('- Command: %s', cmd),
        string.format('- Settings: %s', vim.inspect(client.settings, { newline = '\n  ' })),
        string.format(
          '- Attached buffers: %s',
          vim.iter(pairs(client.attached_buffers)):map(tostring):join(', ')
        ),
      }, '\n'))
    end
  else