mirror of
https://github.com/neovim/neovim.git
synced 2024-12-23 12:45:17 -07:00
Merge 5bb11844b3
into 02bc40c194
This commit is contained in:
commit
98daec7036
@ -1824,10 +1824,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(0, 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
|
||||||
|
|
||||||
|
@ -1750,6 +1750,19 @@ describe('vim.diagnostic', function()
|
|||||||
return _G.count_extmarks(_G.diagnostic_bufnr, _G.diagnostic_ns)
|
return _G.count_extmarks(_G.diagnostic_bufnr, _G.diagnostic_ns)
|
||||||
end)
|
end)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
--`float` option defined as a function.
|
||||||
|
eq(
|
||||||
|
true,
|
||||||
|
exec_lua(function()
|
||||||
|
vim.diagnostic.config({
|
||||||
|
float = function(_, _)
|
||||||
|
return { border = 'rounded' }
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
return type(vim.diagnostic.config().float) == 'function'
|
||||||
|
end)
|
||||||
|
)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('can use functions for config values', function()
|
it('can use functions for config values', function()
|
||||||
@ -2501,6 +2514,37 @@ describe('vim.diagnostic', function()
|
|||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('', function()
|
||||||
|
eq(
|
||||||
|
{ { 'Diagnostics:', '1. syntax error' }, '╭', '┌' },
|
||||||
|
exec_lua(function()
|
||||||
|
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.diagnostic.config({
|
||||||
|
float = function(_, bufnr)
|
||||||
|
return { border = bufnr == _G.diagnostic_bufnr and 'rounded' or 'single' }
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
local float_bufnr, winnr = vim.diagnostic.open_float()
|
||||||
|
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
||||||
|
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('can show diagnostics from the whole buffer', function()
|
it('can show diagnostics from the whole buffer', function()
|
||||||
eq(
|
eq(
|
||||||
{ '1. Syntax error', '2. Some warning' },
|
{ '1. Syntax error', '2. Some warning' },
|
||||||
|
Loading…
Reference in New Issue
Block a user