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

Code before:
        hlname = '@string.special.path',
        prefix = {
          length = #default_pre,
          hlname = prefix_hl_group,
        },
        suffix = {
          length = #info_suffix,
          hlname = 'NormalFloat',
        },
      }
    end
  end

  -- Used by open_floating_preview to allow the float to be focused
  if not opts.focus_id then
    opts.focus_id = scope
  end

  --- @diagnostic disable-next-line: param-type-mismatch
  local float_bufnr, winnr = vim.lsp.util.open_floating_preview(lines, 'plaintext', opts)
  vim.bo[float_bufnr].path = vim.bo[bufnr].path

  --- @diagnostic disable-next-line: deprecated
  local add_highlight = api.nvim_buf_add_highlight

  for i, hl in ipairs(highlights) do
    local line = lines[i]
    local prefix_len = hl.prefix and hl.prefix.length or 0
    local suffix_len = hl.suffix and hl.suffix.length or 0
    if prefix_len > 0 then
      add_highlight(float_bufnr, -1, hl.prefix.hlname, i - 1, 0, prefix_len)
    end
    add_highlight(float_bufnr, -1, hl.hlname, i - 1, prefix_len, #line - suffix_len)
    if suffix_len > 0 then
      add_highlight(float_bufnr, -1, hl.suffix.hlname, i - 1, #line - suffix_len, -1)
    end
  end

  return float_bufnr, winnr
end

--- Remove all diagnostics from the given namespace.
---
--- Unlike |vim.diagnostic.hide()|, this function removes all saved
--- diagnostics. They cannot be redisplayed using |vim.diagnostic.show()|. To
--- simply remove diagnostic decorations in a way that they can be
--- re-displayed, use |vim.diagnostic.hide()|.
---
---@param namespace integer? Diagnostic namespace. When omitted, remove
---                          diagnostics from all namespaces.
---@param bufnr integer? Remove diagnostics for the given buffer. When omitted,

Review comment (suggestion):
```suggestion
  -- TODO: Handle this generally (like vim.ui.open()), rather than overriding gf. #7282
```

Code after:
        info_suffix
      )
      highlights[#highlights + 1] = {
        hlname = '@string.special.path',
        prefix = {
          length = #default_pre,
          hlname = prefix_hl_group,
        },
        suffix = {
          length = #info_suffix,
          hlname = 'NormalFloat',
        },
      }
    end
  end

  -- Used by open_floating_preview to allow the float to be focused
  if not opts.focus_id then
    opts.focus_id = scope
  end

  --- @diagnostic disable-next-line: param-type-mismatch
  local float_bufnr, winnr = vim.lsp.util.open_floating_preview(lines, 'plaintext', opts)
  vim.bo[float_bufnr].path = vim.bo[bufnr].path

  -- TODO: Handle this generally (like vim.ui.open()), rather than overriding gf.
  vim.keymap.set('n', 'gf', function()
    local cursor_row = api.nvim_win_get_cursor(0)[1]
    local location = related_info_locations[cursor_row]
    if location then
      -- Split the window before calling `show_document` so the window doesn't disappear.
      vim.cmd.split()
      vim.lsp.util.show_document(location, 'utf-16', { focus = true })
    else
      vim.cmd.normal({ 'gf', bang = true })
    end
  end, { buffer = float_bufnr, remap = false })

  --- @diagnostic disable-next-line: deprecated
  local add_highlight = api.nvim_buf_add_highlight

  for i, hl in ipairs(highlights) do
    local line = lines[i]
    local prefix_len = hl.prefix and hl.prefix.length or 0
    local suffix_len = hl.suffix and hl.suffix.length or 0
    if prefix_len > 0 then
      add_highlight(float_bufnr, -1, hl.prefix.hlname, i - 1, 0, prefix_len)
    end
    add_highlight(float_bufnr, -1, hl.hlname, i - 1, prefix_len, #line - suffix_len)
    if suffix_len > 0 then
      add_highlight(float_bufnr, -1, hl.suffix.hlname, i - 1, #line - suffix_len, -1)