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

Code before:
--- function.
---
--- Copy this sample code into `lua/foo/health.lua`, replacing "foo" in the path
--- with your plugin name: >lua
---
---         local M = {}
---
---         M.check = function()
---           vim.health.start("foo report")
---           -- make sure setup function parameters are ok
---           if check_setup() then
---             vim.health.ok("Setup is correct")
---           else
---             vim.health.error("Setup is incorrect")
---           end
---           -- do some more checking
---           -- ...
---         end
---
---         return M
---</pre>

local M = {}

local s_output = {} ---@type string[]
local report_output = {} ---@type { ['ok']: number, ['warn']: number, ['error']: number }

-- From a path return a list [{name}, {func}, {type}] representing a healthcheck
local function filepath_to_healthcheck(path)
  path = vim.fs.abspath(vim.fs.normalize(path))
  local name --- @type string
  local func --- @type string
  local filetype --- @type string
  if path:find('vim$') then
    name = vim.fs.basename(path):gsub('%.vim$', '')
    func = 'health#' .. name .. '#check'
    filetype = 'v'
  else
    local rtp_lua = vim
      .iter(vim.api.nvim_get_runtime_file('lua/', true))
      :map(function(rtp_lua)
        return vim.fs.abspath(vim.fs.normalize(rtp_lua))
      end)
      :find(function(rtp_lua)
        return vim.fs.relpath(rtp_lua, path)
      end)
    -- "/path/to/rtp/lua/foo/bar/health.lua" => "foo/bar/health.lua"
    -- "/another/rtp/lua/baz/health/init.lua" => "baz/health/init.lua"
    local subpath = path:gsub('^' .. vim.pesc(rtp_lua), ''):gsub('^/+', '')
    if vim.fs.basename(subpath) == 'health.lua' then
      -- */health.lua

Review comment (suggestion):
Not sure of the best name for this, but `report_output` seems strange.
```suggestion
local results = {} ---@type { ['ok']: number, ['warn']: number, ['error']: number }
```

Code after:
--- function.
---
--- Copy this sample code into `lua/foo/health.lua`, replacing "foo" in the path
--- with your plugin name: >lua
---
---         local M = {}
---
---         M.check = function()
---           vim.health.start("foo report")
---           -- make sure setup function parameters are ok
---           if check_setup() then
---             vim.health.ok("Setup is correct")
---           else
---             vim.health.error("Setup is incorrect")
---           end
---           -- do some more checking
---           -- ...
---         end
---
---         return M
---</pre>

local M = {}

local s_output = {} ---@type string[]
local check_summary = { warn = 0, error = 0 }

-- From a path return a list [{name}, {func}, {type}] representing a healthcheck
local function filepath_to_healthcheck(path)
  path = vim.fs.abspath(vim.fs.normalize(path))
  local name --- @type string
  local func --- @type string
  local filetype --- @type string
  if path:find('vim$') then
    name = vim.fs.basename(path):gsub('%.vim$', '')
    func = 'health#' .. name .. '#check'
    filetype = 'v'
  else
    local rtp_lua = vim
      .iter(vim.api.nvim_get_runtime_file('lua/', true))
      :map(function(rtp_lua)
        return vim.fs.abspath(vim.fs.normalize(rtp_lua))
      end)
      :find(function(rtp_lua)
        return vim.fs.relpath(rtp_lua, path)
      end)
    -- "/path/to/rtp/lua/foo/bar/health.lua" => "foo/bar/health.lua"
    -- "/another/rtp/lua/baz/health/init.lua" => "baz/health/init.lua"
    local subpath = path:gsub('^' .. vim.pesc(rtp_lua), ''):gsub('^/+', '')
    if vim.fs.basename(subpath) == 'health.lua' then
      -- */health.lua