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

Code before:
--- @type table<integer,true|table<integer,true>>
local diagnostic_disabled = {}

--- @type table<integer,table<integer,table>>
local bufs_waiting_to_update = setmetatable({}, bufnr_and_namespace_cacher_mt)

--- @class vim.diagnostic.NS
--- @field name string
--- @field opts vim.diagnostic.Opts
--- @field user_data table
--- @field disabled? boolean

--- @type table<integer,vim.diagnostic.NS>
local all_namespaces = {}

---@param severity string|vim.diagnostic.SeverityEnum?
---@return vim.diagnostic.Severity?
local function to_severity(severity)
  if type(severity) == 'string' then
    severity = severity:upper()
    local ret = M.severity[severity:upper()] --[[@as vim.diagnostic.Severity?]]
    if not ret then
      error(('Invalid severity: %s'):format(severity))
    end
    return ret
  end
  return severity --[[@as vim.diagnostic.Severity?]]
end

--- @param severity vim.diagnostic.SeverityFilter
--- @return fun(d: vim.Diagnostic):boolean
local function severity_predicate(severity)
  if type(severity) ~= 'table' then
    --- @cast severity vim.diagnostic.SeverityEnum
    local severityint0 = to_severity(severity)
    ---@param d vim.Diagnostic
    return function(d)
      return d.severity == severityint0
    end
  end
  --- @diagnostic disable-next-line: undefined-field
  if severity.min or severity.max then
    --- @cast severity {min:vim.diagnostic.SeverityEnum,max:vim.diagnostic.SeverityEnum}
    local min_severity = to_severity(severity.min) or M.severity.HINT
    local max_severity = to_severity(severity.max) or M.severity.ERROR

    --- @param d vim.Diagnostic
    return function(d)
      return d.severity <= min_severity and d.severity >= max_severity
    end
  end

Review comment (suggestion):
small oversight ? `:upper()` it's being used twice here

Code after:
--- @type table<integer,table<integer,vim.diagnostic._extmark[]>>
local diagnostic_cache_extmarks = setmetatable({}, bufnr_and_namespace_cacher_mt)

--- @type table<integer,true>
local diagnostic_attached_buffers = {}

--- @type table<integer,true|table<integer,true>>
local diagnostic_disabled = {}

--- @type table<integer,table<integer,table>>
local bufs_waiting_to_update = setmetatable({}, bufnr_and_namespace_cacher_mt)

--- @class vim.diagnostic.NS
--- @field name string
--- @field opts vim.diagnostic.Opts
--- @field user_data table
--- @field disabled? boolean

--- @type table<integer,vim.diagnostic.NS>
local all_namespaces = {}

---@param severity string|vim.diagnostic.Severity?
---@return vim.diagnostic.Severity?
local function to_severity(severity)
  if type(severity) == 'string' then
    local ret = M.severity[severity:upper()] --[[@as vim.diagnostic.Severity?]]
    if not ret then
      error(('Invalid severity: %s'):format(severity))
    end
    return ret
  end
  return severity --[[@as vim.diagnostic.Severity?]]
end

--- @param severity vim.diagnostic.SeverityFilter
--- @return fun(d: vim.Diagnostic):boolean
local function severity_predicate(severity)
  if type(severity) ~= 'table' then
    local severity0 = to_severity(severity)
    ---@param d vim.Diagnostic
    return function(d)
      return d.severity == severity0
    end
  end
  --- @diagnostic disable-next-line: undefined-field
  if severity.min or severity.max then
    --- @cast severity {min:vim.diagnostic.Severity,max:vim.diagnostic.Severity}
    local min_severity = to_severity(severity.min) or M.severity.HINT
    local max_severity = to_severity(severity.max) or M.severity.ERROR

    --- @param d vim.Diagnostic