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

Code before:
      health.ok(
        string.format('Parser: %-25s ABI: %d, path: %s', parser.name, lang.abi_version, parser.path)
      )
    end
  end

  health.start('Treesitter queries')
  local query_files = vim.api.nvim_get_runtime_file('queries/**/*.scm', true)
  ---@class QueryEntry
  ---@field lang string
  ---@field type string
  ---@field path string
  ---@field index integer
  local queries_by_lang = {} ---@type table<string, QueryEntry[]>
  for i, query_file in ipairs(query_files) do
    local lang, query_type = query_file:match('queries/([^/]+)/([^/]+)%.scm$')
    if lang and query_type then
      if not queries_by_lang[lang] then
        queries_by_lang[lang] = {}
      end
      table.insert(queries_by_lang[lang], {
        lang = lang,
        type = query_type,
        path = query_file,
        index = i,
      })
    end
  end
  if vim.tbl_isempty(queries_by_lang) then
    health.warn('No query files found')
  else
    for lang, queries in vim.spairs(queries_by_lang) do
      table.sort(queries, function(a, b)
        if a.type == b.type then
          return a.index < b.index
        else
          return a.type < b.type
        end
      end)

      for i, query in ipairs(queries) do
        local is_duplicate = i > 1 and queries[i - 1].type == query.type
        if is_duplicate then
          health.ok(
            string.format('Language: %-15s %s (not loaded): %s', lang, query.type, query.path)
          )
        else
          health.ok(string.format('Language: %-15s %s: %s', lang, query.type, query.path))
        end
      end
    end

Review comment (suggestion):
This list is going to be very unwieldy; I would recommend stripping the filename  (since it's redundant with the leading `type:`). You can use `vim.fn.fnamemodify` for that.

Code after:
      health.ok(
        string.format('Parser: %-25s ABI: %d, path: %s', parser.name, lang.abi_version, parser.path)
      )
    end
  end

  health.start('Treesitter queries')
  local query_files = vim.api.nvim_get_runtime_file('queries/**/*.scm', true)

  ---@class QueryEntry
  ---@field lang string
  ---@field type string
  ---@field path string
  ---@field index integer
  local queries_by_lang = {} ---@type table<string, QueryEntry[]>

  for i, query_file in ipairs(query_files) do
    local lang, query_type = query_file:match('queries/([^/]+)/([^/]+)%.scm$')
    if lang and query_type then
      if not queries_by_lang[lang] then
        queries_by_lang[lang] = {}
      end
      table.insert(queries_by_lang[lang], {
        lang = lang,
        type = query_type,
        path = query_file,
        index = i,
      })
    end
  end

  if not vim.tbl_isempty(queries_by_lang) then
    for lang, queries in vim.spairs(queries_by_lang) do
      table.sort(queries, function(a, b)
        if a.type == b.type then
          return a.index < b.index
        else
          return a.type < b.type
        end
      end)

      for _, query in ipairs(queries) do
        local dir = vim.fn.fnamemodify(query.path, ':h')
        health.ok(string.format('%-15s %-15s %s', lang, query.type, dir))
      end
    end
  end
end

return M