mirror of
https://github.com/neovim/neovim.git
synced 2026-08-28 01:51:52 +00:00
fix(diagnostic): open_float() handles config.float function #31577
Problem: The `float` field of vim.diagnostic.config can be a function, but diagnostic.open_float() does not handle it correctly. Solution: Add handling for it in open_float().
This commit is contained in:
@@ -545,7 +545,7 @@ Lua module: vim.diagnostic *diagnostic-api*
|
|||||||
Use virtual lines for diagnostics.
|
Use virtual lines for diagnostics.
|
||||||
• {signs}? (`boolean|vim.diagnostic.Opts.Signs|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.Signs`, default: `true`)
|
• {signs}? (`boolean|vim.diagnostic.Opts.Signs|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.Signs`, default: `true`)
|
||||||
Use signs for diagnostics |diagnostic-signs|.
|
Use signs for diagnostics |diagnostic-signs|.
|
||||||
• {float}? (`boolean|vim.diagnostic.Opts.Float|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.Float`)
|
• {float}? (`boolean|vim.diagnostic.Opts.Float|fun(namespace?: integer|integer[], bufnr:integer): vim.diagnostic.Opts.Float`)
|
||||||
Options for floating windows. See
|
Options for floating windows. See
|
||||||
|vim.diagnostic.Opts.Float|.
|
|vim.diagnostic.Opts.Float|.
|
||||||
• {status}? (`vim.diagnostic.Opts.Status`) Options for the
|
• {status}? (`vim.diagnostic.Opts.Status`) Options for the
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ end
|
|||||||
--- @field signs? boolean|vim.diagnostic.Opts.Signs|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.Signs
|
--- @field signs? boolean|vim.diagnostic.Opts.Signs|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.Signs
|
||||||
---
|
---
|
||||||
--- Options for floating windows. See |vim.diagnostic.Opts.Float|.
|
--- Options for floating windows. See |vim.diagnostic.Opts.Float|.
|
||||||
--- @field float? boolean|vim.diagnostic.Opts.Float|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.Float
|
--- @field float? boolean|vim.diagnostic.Opts.Float|fun(namespace?: integer|integer[], bufnr:integer): vim.diagnostic.Opts.Float
|
||||||
---
|
---
|
||||||
--- Options for the statusline component.
|
--- Options for the statusline component.
|
||||||
--- @field status? vim.diagnostic.Opts.Status
|
--- @field status? vim.diagnostic.Opts.Status
|
||||||
@@ -2439,10 +2439,13 @@ function M.open_float(opts, ...)
|
|||||||
-- Resolve options with user settings from vim.diagnostic.config
|
-- Resolve options with user settings from vim.diagnostic.config
|
||||||
-- Unlike the other decoration functions (e.g. set_virtual_text, set_signs, etc.) `open_float`
|
-- Unlike the other decoration functions (e.g. set_virtual_text, set_signs, etc.) `open_float`
|
||||||
-- does not have a dedicated table for configuration options; instead, the options are mixed in
|
-- does not have a dedicated table for configuration options; instead, the options are mixed in
|
||||||
-- with its `opts` table which also includes "keyword" parameters. So we create a dedicated
|
-- with its `opts` table. We create a dedicated options table (`float_opts`) that inherits
|
||||||
-- options table that inherits missing keys from the global configuration before resolving.
|
-- missing keys from the global configuration (`global_diagnostic_options.float`), which can
|
||||||
local t = global_diagnostic_options.float
|
-- be a table or a function.
|
||||||
local float_opts = vim.tbl_extend('keep', opts, type(t) == 'table' and t or {})
|
local o = global_diagnostic_options
|
||||||
|
local t = type(o.float) == 'table' and o.float
|
||||||
|
or (type(o.float) == 'function' and o.float(opts.namespace, bufnr) or {})
|
||||||
|
local float_opts = vim.tbl_extend('keep', opts, t)
|
||||||
opts = get_resolved_options({ float = float_opts }, nil, bufnr).float
|
opts = get_resolved_options({ float = float_opts }, nil, bufnr).float
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -3215,28 +3215,40 @@ describe('vim.diagnostic', function()
|
|||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it(
|
it('creates floating window without header and supports function-based float config', function()
|
||||||
'creates floating window and returns float bufnr and winnr without header, if requested',
|
-- One line (since no header):
|
||||||
function()
|
-- 1. <msg>
|
||||||
-- One line (since no header):
|
eq(
|
||||||
-- 1. <msg>
|
{ 1, '╭', '┌' },
|
||||||
eq(
|
exec_lua(function()
|
||||||
1,
|
local diagnostics = {
|
||||||
exec_lua(function()
|
_G.make_error('Syntax error', 0, 1, 0, 3),
|
||||||
local diagnostics = {
|
}
|
||||||
_G.make_error('Syntax error', 0, 1, 0, 3),
|
vim.api.nvim_win_set_buf(0, _G.diagnostic_bufnr)
|
||||||
}
|
vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, diagnostics)
|
||||||
vim.api.nvim_win_set_buf(0, _G.diagnostic_bufnr)
|
local float_bufnr, winnr =
|
||||||
vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, diagnostics)
|
vim.diagnostic.open_float(_G.diagnostic_bufnr, { header = false })
|
||||||
local float_bufnr, winnr =
|
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
||||||
vim.diagnostic.open_float(_G.diagnostic_bufnr, { header = false })
|
vim.api.nvim_win_close(winnr, true)
|
||||||
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
vim.diagnostic.config({
|
||||||
vim.api.nvim_win_close(winnr, true)
|
float = function(_, bufnr)
|
||||||
return #lines
|
return { border = bufnr == _G.diagnostic_bufnr and 'rounded' or 'single' }
|
||||||
end)
|
end,
|
||||||
)
|
})
|
||||||
end
|
_, winnr = vim.diagnostic.open_float()
|
||||||
)
|
local border1 = vim.api.nvim_win_get_config(winnr).border
|
||||||
|
vim.api.nvim_win_close(winnr, true)
|
||||||
|
|
||||||
|
local other_bufnr = vim.api.nvim_create_buf(true, true)
|
||||||
|
vim.api.nvim_win_set_buf(0, other_bufnr)
|
||||||
|
vim.diagnostic.set(_G.diagnostic_ns, other_bufnr, diagnostics)
|
||||||
|
local _, winnr1 = vim.diagnostic.open_float()
|
||||||
|
local border2 = vim.api.nvim_win_get_config(winnr1).border
|
||||||
|
vim.api.nvim_win_close(winnr1, true)
|
||||||
|
return { #lines, border1[1], border2[1] }
|
||||||
|
end)
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
|
||||||
it('clamps diagnostic line numbers within the valid range', function()
|
it('clamps diagnostic line numbers within the valid range', function()
|
||||||
eq(
|
eq(
|
||||||
|
|||||||
Reference in New Issue
Block a user