refactor(diagnostic): remove get_virt_text_chunks()

This function isn't compatible with including diagnostic sources when
"source" is "if_many" since it only has access to diagnostics for a
single line. Rather than having an inconsistent or incomplete interface,
make this function private. It is still exported as part of the module
for backward compatibility with vim.lsp.diagnostics, but it can
eventually be made into a local function.
This commit is contained in:
Gregory Anders 2021-09-20 15:32:14 -06:00
parent d43151ea0b
commit bc652f148f
4 changed files with 12 additions and 30 deletions

View File

@ -75,7 +75,9 @@ For each of the functions below, use the corresponding function in
*vim.lsp.diagnostic.get_prev()* *vim.lsp.diagnostic.get_prev()*
*vim.lsp.diagnostic.get_prev_pos()* *vim.lsp.diagnostic.get_prev_pos()*
*vim.lsp.diagnostic.get_virtual_text_chunks_for_line()* *vim.lsp.diagnostic.get_virtual_text_chunks_for_line()*
Use |vim.diagnostic.get_virt_text_chunks()| instead. No replacement. Use options provided by
|vim.diagnostic.config()| to customize
virtual text.
*vim.lsp.diagnostic.goto_next()* *vim.lsp.diagnostic.goto_next()*
*vim.lsp.diagnostic.goto_prev()* *vim.lsp.diagnostic.goto_prev()*
*vim.lsp.diagnostic.redraw()* Use |vim.diagnostic.show()| instead. *vim.lsp.diagnostic.redraw()* Use |vim.diagnostic.show()| instead.

View File

@ -333,26 +333,6 @@ get_prev_pos({opts}) *vim.diagnostic.get_prev_pos()*
Return: ~ Return: ~
table Previous diagnostic position as a (row, col) tuple. table Previous diagnostic position as a (row, col) tuple.
*vim.diagnostic.get_virt_text_chunks()*
get_virt_text_chunks({line_diags}, {opts})
Get virtual text chunks to display using
|nvim_buf_set_extmark()|.
Parameters: ~
{line_diags} table The diagnostics associated with the
line.
{opts} table|nil Configuration table with the
following keys:
• prefix: (string) Prefix to display before
virtual text on line.
• spacing: (number) Number of spaces to
insert before virtual text.
Return: ~
array of ({text}, {hl_group}) tuples. This can be passed
directly to the {virt_text} option of
|nvim_buf_set_extmark()|.
goto_next({opts}) *vim.diagnostic.goto_next()* goto_next({opts}) *vim.diagnostic.goto_next()*
Move to the next diagnostic. Move to the next diagnostic.

View File

@ -851,6 +851,8 @@ end
---@param opts table|nil Configuration table with the following keys: ---@param opts table|nil Configuration table with the following keys:
--- - prefix: (string) Prefix to display before virtual text on line. --- - prefix: (string) Prefix to display before virtual text on line.
--- - spacing: (number) Number of spaces to insert before virtual text. --- - spacing: (number) Number of spaces to insert before virtual text.
--- - source: (string) Include the diagnostic source in virtual text. One of "always" or
--- "if_many".
---@private ---@private
function M._set_virtual_text(namespace, bufnr, diagnostics, opts) function M._set_virtual_text(namespace, bufnr, diagnostics, opts)
vim.validate { vim.validate {
@ -872,7 +874,7 @@ function M._set_virtual_text(namespace, bufnr, diagnostics, opts)
if opts and opts.severity then if opts and opts.severity then
line_diagnostics = filter_by_severity(opts.severity, line_diagnostics) line_diagnostics = filter_by_severity(opts.severity, line_diagnostics)
end end
local virt_texts = M.get_virt_text_chunks(line_diagnostics, opts) local virt_texts = M._get_virt_text_chunks(line_diagnostics, opts)
if virt_texts then if virt_texts then
vim.api.nvim_buf_set_extmark(bufnr, namespace, line, 0, { vim.api.nvim_buf_set_extmark(bufnr, namespace, line, 0, {
@ -885,13 +887,11 @@ end
--- Get virtual text chunks to display using |nvim_buf_set_extmark()|. --- Get virtual text chunks to display using |nvim_buf_set_extmark()|.
--- ---
---@param line_diags table The diagnostics associated with the line. --- Exported for backward compatibility with
---@param opts table|nil Configuration table with the following keys: --- vim.lsp.diagnostic.get_virtual_text_chunks_for_line(). When that function is eventually removed,
--- - prefix: (string) Prefix to display before virtual text on line. --- this can be made local.
--- - spacing: (number) Number of spaces to insert before virtual text. ---@private
---@return array of ({text}, {hl_group}) tuples. This can be passed directly to function M._get_virt_text_chunks(line_diags, opts)
--- the {virt_text} option of |nvim_buf_set_extmark()|.
function M.get_virt_text_chunks(line_diags, opts)
if #line_diags == 0 then if #line_diags == 0 then
return nil return nil
end end

View File

@ -529,7 +529,7 @@ end
---@return an array of [text, hl_group] arrays. This can be passed directly to ---@return an array of [text, hl_group] arrays. This can be passed directly to
--- the {virt_text} option of |nvim_buf_set_extmark()|. --- the {virt_text} option of |nvim_buf_set_extmark()|.
function M.get_virtual_text_chunks_for_line(bufnr, _, line_diags, opts) function M.get_virtual_text_chunks_for_line(bufnr, _, line_diags, opts)
return vim.diagnostic.get_virt_text_chunks(diagnostic_lsp_to_vim(line_diags, bufnr), opts) return vim.diagnostic._get_virt_text_chunks(diagnostic_lsp_to_vim(line_diags, bufnr), opts)
end end
--- Open a floating window with the diagnostics from {position} --- Open a floating window with the diagnostics from {position}