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

Code before:
      )
    end
    save_extmarks(underline_ns, bufnr)
  end,
  hide = function(namespace, bufnr)
    local ns = M.get_namespace(namespace)
    if ns.user_data.underline_ns then
      diagnostic_cache_extmarks[bufnr][ns.user_data.underline_ns] = {}
      if api.nvim_buf_is_valid(bufnr) then
        api.nvim_buf_clear_namespace(bufnr, ns.user_data.underline_ns, 0, -1)
      end
    end
  end,
}

--- @param namespace integer
--- @param bufnr integer
--- @param diagnostics table<integer, vim.Diagnostic[]>
--- @param opts vim.diagnostic.Opts.VirtualText
local function render_virtual_text(namespace, bufnr, diagnostics, opts)
  local lnum = api.nvim_win_get_cursor(0)[1] - 1
  api.nvim_buf_clear_namespace(bufnr, namespace, 0, -1)

  for line, line_diagnostics in pairs(diagnostics) do
    local virt_texts = M._get_virt_text_chunks(line_diagnostics, opts)
    local should_render_current_line = (opts.current_line == true and line == lnum)
      or (opts.current_line == false and line ~= lnum)

    if virt_texts and should_render_current_line then
      -- if virt_texts then
      api.nvim_buf_set_extmark(bufnr, namespace, line, 0, {
        hl_mode = opts.hl_mode or 'combine',
        virt_text = virt_texts,
        virt_text_pos = opts.virt_text_pos,
        virt_text_hide = opts.virt_text_hide,
        virt_text_win_col = opts.virt_text_win_col,
      })
    end
  end
end

M.handlers.virtual_text = {
  show = function(namespace, bufnr, diagnostics, opts)
    vim.validate('namespace', namespace, 'number')
    vim.validate('bufnr', bufnr, 'number')
    vim.validate('diagnostics', diagnostics, vim.islist, 'a list of diagnostics')
    vim.validate('opts', opts, 'table', true)

    bufnr = vim._resolve_bufnr(bufnr)
    opts = opts or {}


Review comment (suggestion):
If `opts.current_line` is `nil` this should also be true.

Code after:
        { diagnostic.end_lnum, diagnostic.end_col },
        { priority = get_priority(diagnostic.severity) }
      )
    end
    save_extmarks(underline_ns, bufnr)
  end,
  hide = function(namespace, bufnr)
    local ns = M.get_namespace(namespace)
    if ns.user_data.underline_ns then
      diagnostic_cache_extmarks[bufnr][ns.user_data.underline_ns] = {}
      if api.nvim_buf_is_valid(bufnr) then
        api.nvim_buf_clear_namespace(bufnr, ns.user_data.underline_ns, 0, -1)
      end
    end
  end,
}

--- @param namespace integer
--- @param bufnr integer
--- @param diagnostics table<integer, vim.Diagnostic[]>
--- @param opts vim.diagnostic.Opts.VirtualText
local function render_virtual_text(namespace, bufnr, diagnostics, opts)
  local lnum = api.nvim_win_get_cursor(0)[1] - 1
  api.nvim_buf_clear_namespace(bufnr, namespace, 0, -1)

  for line, line_diagnostics in pairs(diagnostics) do
    local virt_texts = M._get_virt_text_chunks(line_diagnostics, opts)
    local skip = (opts.current_line == true and line ~= lnum)
      or (opts.current_line == false and line == lnum)

    if virt_texts and not skip then
      api.nvim_buf_set_extmark(bufnr, namespace, line, 0, {
        hl_mode = opts.hl_mode or 'combine',
        virt_text = virt_texts,
        virt_text_pos = opts.virt_text_pos,
        virt_text_hide = opts.virt_text_hide,
        virt_text_win_col = opts.virt_text_win_col,
      })
    end
  end
end

M.handlers.virtual_text = {
  show = function(namespace, bufnr, diagnostics, opts)
    vim.validate('namespace', namespace, 'number')
    vim.validate('bufnr', bufnr, 'number')
    vim.validate('diagnostics', diagnostics, vim.islist, 'a list of diagnostics')
    vim.validate('opts', opts, 'table', true)

    bufnr = vim._resolve_bufnr(bufnr)
    opts = opts or {}