mirror of
https://github.com/neovim/neovim.git
synced 2025-10-26 12:27:24 +00:00
refactor(diagnostic)!: replace 'show_*' functions with 'open_float' (#16057)
'show_line_diagnostics()' and 'show_position_diagnostics()' are almost identical; they differ only in the fact that the latter also accepts a column to form a full position, rather than just a line. This is not enough to justify two separate interfaces for this common functionality. Renaming this to simply 'show_diagnostics()' is one step forward, but that is also not a good name as the '_diagnostics()' suffix is redundant. However, we cannot name it simply 'show()' since that function already exists with entirely different semantics. Instead, combine these two into a single 'open_float()' function that handles all of the cases of showing diagnostics in a floating window. Also add a "float" key to 'vim.diagnostic.config()' to provide global values of configuration options that can be overridden ephemerally. This makes the float API consistent with the rest of the diagnostic API. BREAKING CHANGE
This commit is contained in:
@@ -551,14 +551,15 @@ end
|
||||
---@param position table|nil The (0,0)-indexed position
|
||||
---@return table {popup_bufnr, win_id}
|
||||
function M.show_position_diagnostics(opts, buf_nr, position)
|
||||
if opts then
|
||||
if opts.severity then
|
||||
opts.severity = severity_lsp_to_vim(opts.severity)
|
||||
elseif opts.severity_limit then
|
||||
opts.severity = {min=severity_lsp_to_vim(opts.severity_limit)}
|
||||
end
|
||||
opts = opts or {}
|
||||
opts.where = "cursor"
|
||||
opts.pos = position
|
||||
if opts.severity then
|
||||
opts.severity = severity_lsp_to_vim(opts.severity)
|
||||
elseif opts.severity_limit then
|
||||
opts.severity = {min=severity_lsp_to_vim(opts.severity_limit)}
|
||||
end
|
||||
return vim.diagnostic.show_position_diagnostics(opts, buf_nr, position)
|
||||
return vim.diagnostic.open_float(buf_nr, opts)
|
||||
end
|
||||
|
||||
--- Open a floating window with the diagnostics from {line_nr}
|
||||
@@ -573,11 +574,13 @@ end
|
||||
---@param client_id number|nil the client id
|
||||
---@return table {popup_bufnr, win_id}
|
||||
function M.show_line_diagnostics(opts, buf_nr, line_nr, client_id)
|
||||
opts = opts or {}
|
||||
opts.where = "line"
|
||||
opts.pos = line_nr
|
||||
if client_id then
|
||||
opts = opts or {}
|
||||
opts.namespace = M.get_namespace(client_id)
|
||||
end
|
||||
return vim.diagnostic.show_line_diagnostics(opts, buf_nr, line_nr)
|
||||
return vim.diagnostic.open_float(buf_nr, opts)
|
||||
end
|
||||
|
||||
--- Redraw diagnostics for the given buffer and client
|
||||
|
||||
Reference in New Issue
Block a user