mirror of
https://github.com/neovim/neovim.git
synced 2025-11-06 02:34:28 +00:00
Merge pull request #16328 from gpanders/diagnostic-prefix-hi
This commit is contained in:
@@ -375,8 +375,11 @@ config({opts}, {namespace}) *vim.diagnostic.config()*
|
|||||||
|
|
||||||
• float: Options for floating windows:
|
• float: Options for floating windows:
|
||||||
• severity: See |diagnostic-severity|.
|
• severity: See |diagnostic-severity|.
|
||||||
• show_header: (boolean, default true) Show
|
• header: (string or table) String to use
|
||||||
"Diagnostics:" header
|
as the header for the floating window. If
|
||||||
|
a table, it is interpreted as a [text,
|
||||||
|
hl_group] tuple. Defaults to
|
||||||
|
"Diagnostics:".
|
||||||
• source: (string) Include the diagnostic
|
• source: (string) Include the diagnostic
|
||||||
source in the message. One of "always" or
|
source in the message. One of "always" or
|
||||||
"if_many".
|
"if_many".
|
||||||
@@ -384,17 +387,24 @@ config({opts}, {namespace}) *vim.diagnostic.config()*
|
|||||||
a diagnostic as input and returns a
|
a diagnostic as input and returns a
|
||||||
string. The return value is the text used
|
string. The return value is the text used
|
||||||
to display the diagnostic.
|
to display the diagnostic.
|
||||||
• prefix: (function or string) Prefix each
|
• prefix: (function, string, or table)
|
||||||
diagnostic in the floating window. If a
|
Prefix each diagnostic in the floating
|
||||||
function, it must have the signature
|
window. If a function, it must have the
|
||||||
(diagnostic, i, total) -> string, where
|
signature (diagnostic, i, total) ->
|
||||||
{i} is the index of the diagnostic being
|
(string, string), where {i} is the index
|
||||||
evaluated and {total} is the total number
|
of the diagnostic being evaluated and
|
||||||
of diagnostics displayed in the window.
|
{total} is the total number of
|
||||||
The returned string is prepended to each
|
diagnostics displayed in the window. The
|
||||||
diagnostic in the window. Otherwise, if
|
function should return a string which is
|
||||||
|
prepended to each diagnostic in the
|
||||||
|
window as well as an (optional) highlight
|
||||||
|
group which will be used to highlight the
|
||||||
|
prefix. If {prefix} is a table, it is
|
||||||
|
interpreted as a [text, hl_group] tuple
|
||||||
|
as in |nvim_echo()|; otherwise, if
|
||||||
{prefix} is a string, it is prepended to
|
{prefix} is a string, it is prepended to
|
||||||
each diagnostic.
|
each diagnostic in the window with no
|
||||||
|
highlight.
|
||||||
|
|
||||||
• update_in_insert: (default false) Update
|
• update_in_insert: (default false) Update
|
||||||
diagnostics in Insert mode (if false,
|
diagnostics in Insert mode (if false,
|
||||||
@@ -616,9 +626,11 @@ open_float({bufnr}, {opts}) *vim.diagnostic.open_float()*
|
|||||||
|vim.diagnostic.config()|.
|
|vim.diagnostic.config()|.
|
||||||
• severity: See |diagnostic-severity|. Overrides
|
• severity: See |diagnostic-severity|. Overrides
|
||||||
the setting from |vim.diagnostic.config()|.
|
the setting from |vim.diagnostic.config()|.
|
||||||
• show_header: (boolean, default true) Show
|
• header: (string or table) String to use as the
|
||||||
"Diagnostics:" header. Overrides the setting
|
header for the floating window. If a table, it
|
||||||
from |vim.diagnostic.config()|.
|
is interpreted as a [text, hl_group] tuple.
|
||||||
|
Overrides the setting from
|
||||||
|
|vim.diagnostic.config()|.
|
||||||
• source: (string) Include the diagnostic source
|
• source: (string) Include the diagnostic source
|
||||||
in the message. One of "always" or "if_many".
|
in the message. One of "always" or "if_many".
|
||||||
Overrides the setting from
|
Overrides the setting from
|
||||||
@@ -628,9 +640,10 @@ open_float({bufnr}, {opts}) *vim.diagnostic.open_float()*
|
|||||||
return value is the text used to display the
|
return value is the text used to display the
|
||||||
diagnostic. Overrides the setting from
|
diagnostic. Overrides the setting from
|
||||||
|vim.diagnostic.config()|.
|
|vim.diagnostic.config()|.
|
||||||
• prefix: (function or string) Prefix each
|
• prefix: (function, string, or table) Prefix
|
||||||
diagnostic in the floating window. Overrides
|
each diagnostic in the floating window.
|
||||||
the setting from |vim.diagnostic.config()|.
|
Overrides the setting from
|
||||||
|
|vim.diagnostic.config()|.
|
||||||
|
|
||||||
Return: ~
|
Return: ~
|
||||||
tuple ({float_bufnr}, {win_id})
|
tuple ({float_bufnr}, {win_id})
|
||||||
|
|||||||
@@ -539,17 +539,24 @@ end
|
|||||||
--- its severity. Otherwise, all signs use the same priority.
|
--- its severity. Otherwise, all signs use the same priority.
|
||||||
--- - float: Options for floating windows:
|
--- - float: Options for floating windows:
|
||||||
--- * severity: See |diagnostic-severity|.
|
--- * severity: See |diagnostic-severity|.
|
||||||
--- * show_header: (boolean, default true) Show "Diagnostics:" header
|
--- * header: (string or table) String to use as the header for the floating
|
||||||
|
--- window. If a table, it is interpreted as a [text, hl_group] tuple.
|
||||||
|
--- Defaults to "Diagnostics:".
|
||||||
--- * source: (string) Include the diagnostic source in
|
--- * source: (string) Include the diagnostic source in
|
||||||
--- the message. One of "always" or "if_many".
|
--- the message. One of "always" or "if_many".
|
||||||
--- * format: (function) A function that takes a diagnostic as input and returns a
|
--- * format: (function) A function that takes a diagnostic as input and returns a
|
||||||
--- string. The return value is the text used to display the diagnostic.
|
--- string. The return value is the text used to display the diagnostic.
|
||||||
--- * prefix: (function or string) Prefix each diagnostic in the floating window. If
|
--- * prefix: (function, string, or table) Prefix each diagnostic in the floating
|
||||||
--- a function, it must have the signature (diagnostic, i, total) -> string,
|
--- window. If a function, it must have the signature (diagnostic, i,
|
||||||
--- where {i} is the index of the diagnostic being evaluated and {total} is
|
--- total) -> (string, string), where {i} is the index of the diagnostic
|
||||||
--- the total number of diagnostics displayed in the window. The returned
|
--- being evaluated and {total} is the total number of diagnostics
|
||||||
--- string is prepended to each diagnostic in the window. Otherwise,
|
--- displayed in the window. The function should return a string which
|
||||||
--- if {prefix} is a string, it is prepended to each diagnostic.
|
--- is prepended to each diagnostic in the window as well as an
|
||||||
|
--- (optional) highlight group which will be used to highlight the
|
||||||
|
--- prefix. If {prefix} is a table, it is interpreted as a [text,
|
||||||
|
--- hl_group] tuple as in |nvim_echo()|; otherwise, if {prefix} is a
|
||||||
|
--- string, it is prepended to each diagnostic in the window with no
|
||||||
|
--- highlight.
|
||||||
--- - update_in_insert: (default false) Update diagnostics in Insert mode (if false,
|
--- - update_in_insert: (default false) Update diagnostics in Insert mode (if false,
|
||||||
--- diagnostics are updated on InsertLeave)
|
--- diagnostics are updated on InsertLeave)
|
||||||
--- - severity_sort: (default false) Sort diagnostics by severity. This affects the order in
|
--- - severity_sort: (default false) Sort diagnostics by severity. This affects the order in
|
||||||
@@ -1158,14 +1165,15 @@ end
|
|||||||
--- from |vim.diagnostic.config()|.
|
--- from |vim.diagnostic.config()|.
|
||||||
--- - severity: See |diagnostic-severity|. Overrides the setting from
|
--- - severity: See |diagnostic-severity|. Overrides the setting from
|
||||||
--- |vim.diagnostic.config()|.
|
--- |vim.diagnostic.config()|.
|
||||||
--- - show_header: (boolean, default true) Show "Diagnostics:" header. Overrides the
|
--- - header: (string or table) String to use as the header for the floating window. If a
|
||||||
--- setting from |vim.diagnostic.config()|.
|
--- table, it is interpreted as a [text, hl_group] tuple. Overrides the setting
|
||||||
|
--- from |vim.diagnostic.config()|.
|
||||||
--- - source: (string) Include the diagnostic source in the message. One of "always" or
|
--- - source: (string) Include the diagnostic source in the message. One of "always" or
|
||||||
--- "if_many". Overrides the setting from |vim.diagnostic.config()|.
|
--- "if_many". Overrides the setting from |vim.diagnostic.config()|.
|
||||||
--- - format: (function) A function that takes a diagnostic as input and returns a
|
--- - format: (function) A function that takes a diagnostic as input and returns a
|
||||||
--- string. The return value is the text used to display the diagnostic.
|
--- string. The return value is the text used to display the diagnostic.
|
||||||
--- Overrides the setting from |vim.diagnostic.config()|.
|
--- Overrides the setting from |vim.diagnostic.config()|.
|
||||||
--- - prefix: (function or string) Prefix each diagnostic in the floating window.
|
--- - prefix: (function, string, or table) Prefix each diagnostic in the floating window.
|
||||||
--- Overrides the setting from |vim.diagnostic.config()|.
|
--- Overrides the setting from |vim.diagnostic.config()|.
|
||||||
---@return tuple ({float_bufnr}, {win_id})
|
---@return tuple ({float_bufnr}, {win_id})
|
||||||
function M.open_float(bufnr, opts)
|
function M.open_float(bufnr, opts)
|
||||||
@@ -1237,11 +1245,22 @@ function M.open_float(bufnr, opts)
|
|||||||
|
|
||||||
local lines = {}
|
local lines = {}
|
||||||
local highlights = {}
|
local highlights = {}
|
||||||
local show_header = vim.F.if_nil(opts.show_header, true)
|
local header = if_nil(opts.header, "Diagnostics:")
|
||||||
if show_header then
|
if header then
|
||||||
table.insert(lines, "Diagnostics:")
|
vim.validate { header = { header, function(v)
|
||||||
|
return type(v) == "string" or type(v) == "table"
|
||||||
|
end, "'string' or 'table'" } }
|
||||||
|
if type(header) == "table" then
|
||||||
|
-- Don't insert any lines for an empty string
|
||||||
|
if string.len(if_nil(header[1], "")) > 0 then
|
||||||
|
table.insert(lines, header[1])
|
||||||
|
table.insert(highlights, {0, header[2] or "Bold"})
|
||||||
|
end
|
||||||
|
elseif #header > 0 then
|
||||||
|
table.insert(lines, header)
|
||||||
table.insert(highlights, {0, "Bold"})
|
table.insert(highlights, {0, "Bold"})
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if opts.format then
|
if opts.format then
|
||||||
diagnostics = reformat_diagnostics(opts.format, diagnostics)
|
diagnostics = reformat_diagnostics(opts.format, diagnostics)
|
||||||
@@ -1254,18 +1273,28 @@ function M.open_float(bufnr, opts)
|
|||||||
local prefix_opt = if_nil(opts.prefix, (scope == "cursor" and #diagnostics <= 1) and "" or function(_, i)
|
local prefix_opt = if_nil(opts.prefix, (scope == "cursor" and #diagnostics <= 1) and "" or function(_, i)
|
||||||
return string.format("%d. ", i)
|
return string.format("%d. ", i)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
local prefix, prefix_hl_group
|
||||||
if prefix_opt then
|
if prefix_opt then
|
||||||
vim.validate { prefix = { prefix_opt, function(v)
|
vim.validate { prefix = { prefix_opt, function(v)
|
||||||
return type(v) == "string" or type(v) == "function"
|
return type(v) == "string" or type(v) == "table" or type(v) == "function"
|
||||||
end, "'string' or 'function'" } }
|
end, "'string' or 'table' or 'function'" } }
|
||||||
|
if type(prefix_opt) == "string" then
|
||||||
|
prefix, prefix_hl_group = prefix_opt, "NormalFloat"
|
||||||
|
elseif type(prefix_opt) == "table" then
|
||||||
|
prefix, prefix_hl_group = prefix_opt[1] or "", prefix_opt[2] or "NormalFloat"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for i, diagnostic in ipairs(diagnostics) do
|
for i, diagnostic in ipairs(diagnostics) do
|
||||||
local prefix = type(prefix_opt) == "string" and prefix_opt or prefix_opt(diagnostic, i, #diagnostics)
|
if prefix_opt and type(prefix_opt) == "function" then
|
||||||
|
prefix, prefix_hl_group = prefix_opt(diagnostic, i, #diagnostics)
|
||||||
|
prefix, prefix_hl_group = prefix or "", prefix_hl_group or "NormalFloat"
|
||||||
|
end
|
||||||
local hiname = floating_highlight_map[diagnostic.severity]
|
local hiname = floating_highlight_map[diagnostic.severity]
|
||||||
local message_lines = vim.split(diagnostic.message, '\n')
|
local message_lines = vim.split(diagnostic.message, '\n')
|
||||||
table.insert(lines, prefix..message_lines[1])
|
table.insert(lines, prefix..message_lines[1])
|
||||||
table.insert(highlights, {#prefix, hiname})
|
table.insert(highlights, {#prefix, hiname, prefix_hl_group})
|
||||||
for j = 2, #message_lines do
|
for j = 2, #message_lines do
|
||||||
table.insert(lines, string.rep(' ', #prefix) .. message_lines[j])
|
table.insert(lines, string.rep(' ', #prefix) .. message_lines[j])
|
||||||
table.insert(highlights, {0, hiname})
|
table.insert(highlights, {0, hiname})
|
||||||
@@ -1278,8 +1307,10 @@ function M.open_float(bufnr, opts)
|
|||||||
end
|
end
|
||||||
local float_bufnr, winnr = require('vim.lsp.util').open_floating_preview(lines, 'plaintext', opts)
|
local float_bufnr, winnr = require('vim.lsp.util').open_floating_preview(lines, 'plaintext', opts)
|
||||||
for i, hi in ipairs(highlights) do
|
for i, hi in ipairs(highlights) do
|
||||||
local prefixlen, hiname = unpack(hi)
|
local prefixlen, hiname, prefix_hiname = unpack(hi)
|
||||||
-- Start highlight after the prefix
|
if prefix_hiname then
|
||||||
|
vim.api.nvim_buf_add_highlight(float_bufnr, -1, prefix_hiname, i-1, 0, prefixlen)
|
||||||
|
end
|
||||||
vim.api.nvim_buf_add_highlight(float_bufnr, -1, hiname, i-1, prefixlen, -1)
|
vim.api.nvim_buf_add_highlight(float_bufnr, -1, hiname, i-1, prefixlen, -1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1277,6 +1277,44 @@ describe('vim.diagnostic', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
describe('open_float()', function()
|
describe('open_float()', function()
|
||||||
|
it('can display a header', function()
|
||||||
|
eq({'Diagnostics:', '1. Syntax error'}, exec_lua [[
|
||||||
|
local diagnostics = {
|
||||||
|
make_error("Syntax error", 0, 1, 0, 3),
|
||||||
|
}
|
||||||
|
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
||||||
|
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
||||||
|
local float_bufnr, winnr = vim.diagnostic.open_float()
|
||||||
|
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
||||||
|
vim.api.nvim_win_close(winnr, true)
|
||||||
|
return lines
|
||||||
|
]])
|
||||||
|
|
||||||
|
eq({"We're no strangers to love...", '1. Syntax error'}, exec_lua [[
|
||||||
|
local diagnostics = {
|
||||||
|
make_error("Syntax error", 0, 1, 0, 3),
|
||||||
|
}
|
||||||
|
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
||||||
|
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
||||||
|
local float_bufnr, winnr = vim.diagnostic.open_float(0, {header = "We're no strangers to love..."})
|
||||||
|
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
||||||
|
vim.api.nvim_win_close(winnr, true)
|
||||||
|
return lines
|
||||||
|
]])
|
||||||
|
|
||||||
|
eq({'You know the rules', '1. Syntax error'}, exec_lua [[
|
||||||
|
local diagnostics = {
|
||||||
|
make_error("Syntax error", 0, 1, 0, 3),
|
||||||
|
}
|
||||||
|
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
||||||
|
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
||||||
|
local float_bufnr, winnr = vim.diagnostic.open_float(0, {header = {'You know the rules', 'Search'}})
|
||||||
|
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
||||||
|
vim.api.nvim_win_close(winnr, true)
|
||||||
|
return lines
|
||||||
|
]])
|
||||||
|
end)
|
||||||
|
|
||||||
it('can show diagnostics from the whole buffer', function()
|
it('can show diagnostics from the whole buffer', function()
|
||||||
eq({'1. Syntax error', '2. Some warning'}, exec_lua [[
|
eq({'1. Syntax error', '2. Some warning'}, exec_lua [[
|
||||||
local diagnostics = {
|
local diagnostics = {
|
||||||
@@ -1285,7 +1323,7 @@ describe('vim.diagnostic', function()
|
|||||||
}
|
}
|
||||||
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
||||||
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
||||||
local float_bufnr, winnr = vim.diagnostic.open_float(0, {show_header = false})
|
local float_bufnr, winnr = vim.diagnostic.open_float(0, {header = false})
|
||||||
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
||||||
vim.api.nvim_win_close(winnr, true)
|
vim.api.nvim_win_close(winnr, true)
|
||||||
return lines
|
return lines
|
||||||
@@ -1302,7 +1340,7 @@ describe('vim.diagnostic', function()
|
|||||||
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
||||||
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
||||||
vim.api.nvim_win_set_cursor(0, {2, 1})
|
vim.api.nvim_win_set_cursor(0, {2, 1})
|
||||||
local float_bufnr, winnr = vim.diagnostic.open_float(0, {show_header=false, scope="line"})
|
local float_bufnr, winnr = vim.diagnostic.open_float(0, {header=false, scope="line"})
|
||||||
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
||||||
vim.api.nvim_win_close(winnr, true)
|
vim.api.nvim_win_close(winnr, true)
|
||||||
return lines
|
return lines
|
||||||
@@ -1317,7 +1355,7 @@ describe('vim.diagnostic', function()
|
|||||||
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
||||||
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
||||||
vim.api.nvim_win_set_cursor(0, {1, 1})
|
vim.api.nvim_win_set_cursor(0, {1, 1})
|
||||||
local float_bufnr, winnr = vim.diagnostic.open_float(0, {show_header=false, scope="line", pos=1})
|
local float_bufnr, winnr = vim.diagnostic.open_float(0, {header=false, scope="line", pos=1})
|
||||||
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
||||||
vim.api.nvim_win_close(winnr, true)
|
vim.api.nvim_win_close(winnr, true)
|
||||||
return lines
|
return lines
|
||||||
@@ -1334,7 +1372,7 @@ describe('vim.diagnostic', function()
|
|||||||
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
||||||
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
||||||
vim.api.nvim_win_set_cursor(0, {2, 2})
|
vim.api.nvim_win_set_cursor(0, {2, 2})
|
||||||
local float_bufnr, winnr = vim.diagnostic.open_float(0, {show_header=false, scope="cursor"})
|
local float_bufnr, winnr = vim.diagnostic.open_float(0, {header=false, scope="cursor"})
|
||||||
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
||||||
vim.api.nvim_win_close(winnr, true)
|
vim.api.nvim_win_close(winnr, true)
|
||||||
return lines
|
return lines
|
||||||
@@ -1349,7 +1387,7 @@ describe('vim.diagnostic', function()
|
|||||||
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
||||||
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
||||||
vim.api.nvim_win_set_cursor(0, {1, 1})
|
vim.api.nvim_win_set_cursor(0, {1, 1})
|
||||||
local float_bufnr, winnr = vim.diagnostic.open_float(0, {show_header=false, scope="cursor", pos={1,3}})
|
local float_bufnr, winnr = vim.diagnostic.open_float(0, {header=false, scope="cursor", pos={1,3}})
|
||||||
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
||||||
vim.api.nvim_win_close(winnr, true)
|
vim.api.nvim_win_close(winnr, true)
|
||||||
return lines
|
return lines
|
||||||
@@ -1364,7 +1402,7 @@ describe('vim.diagnostic', function()
|
|||||||
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
||||||
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
||||||
vim.api.nvim_win_set_cursor(0, {1, 1})
|
vim.api.nvim_win_set_cursor(0, {1, 1})
|
||||||
local float_bufnr, winnr = vim.diagnostic.open_float(0, {show_header=false, scope="cursor", pos={0,first_line_len}})
|
local float_bufnr, winnr = vim.diagnostic.open_float(0, {header=false, scope="cursor", pos={0,first_line_len}})
|
||||||
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
||||||
vim.api.nvim_win_close(winnr, true)
|
vim.api.nvim_win_close(winnr, true)
|
||||||
return lines
|
return lines
|
||||||
@@ -1434,7 +1472,7 @@ describe('vim.diagnostic', function()
|
|||||||
}
|
}
|
||||||
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
||||||
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
||||||
local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, {show_header = false})
|
local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, {header = false})
|
||||||
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
||||||
vim.api.nvim_win_close(winnr, true)
|
vim.api.nvim_win_close(winnr, true)
|
||||||
return #lines
|
return #lines
|
||||||
@@ -1448,7 +1486,7 @@ describe('vim.diagnostic', function()
|
|||||||
}
|
}
|
||||||
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
||||||
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
||||||
local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, {show_header = false, scope = "line", pos = 5})
|
local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, {header = false, scope = "line", pos = 5})
|
||||||
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
||||||
vim.api.nvim_win_close(winnr, true)
|
vim.api.nvim_win_close(winnr, true)
|
||||||
return #lines
|
return #lines
|
||||||
@@ -1464,7 +1502,7 @@ describe('vim.diagnostic', function()
|
|||||||
}
|
}
|
||||||
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
||||||
local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, {
|
local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, {
|
||||||
show_header = false,
|
header = false,
|
||||||
source = "if_many",
|
source = "if_many",
|
||||||
})
|
})
|
||||||
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
||||||
@@ -1474,7 +1512,7 @@ describe('vim.diagnostic', function()
|
|||||||
|
|
||||||
eq({"1. source x: Syntax error"}, exec_lua [[
|
eq({"1. source x: Syntax error"}, exec_lua [[
|
||||||
local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, {
|
local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, {
|
||||||
show_header = false,
|
header = false,
|
||||||
source = "always",
|
source = "always",
|
||||||
})
|
})
|
||||||
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
||||||
@@ -1489,7 +1527,7 @@ describe('vim.diagnostic', function()
|
|||||||
}
|
}
|
||||||
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
||||||
local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, {
|
local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, {
|
||||||
show_header = false,
|
header = false,
|
||||||
source = "if_many",
|
source = "if_many",
|
||||||
})
|
})
|
||||||
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
||||||
@@ -1513,7 +1551,7 @@ describe('vim.diagnostic', function()
|
|||||||
|
|
||||||
vim.diagnostic.config({severity_sort = false})
|
vim.diagnostic.config({severity_sort = false})
|
||||||
|
|
||||||
local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, { show_header = false })
|
local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, { header = false })
|
||||||
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
||||||
vim.api.nvim_win_close(winnr, true)
|
vim.api.nvim_win_close(winnr, true)
|
||||||
return lines
|
return lines
|
||||||
@@ -1521,7 +1559,7 @@ describe('vim.diagnostic', function()
|
|||||||
|
|
||||||
eq({"1. Syntax error", "2. Error", "3. Warning", "4. Info"}, exec_lua [[
|
eq({"1. Syntax error", "2. Error", "3. Warning", "4. Info"}, exec_lua [[
|
||||||
vim.diagnostic.config({severity_sort = true})
|
vim.diagnostic.config({severity_sort = true})
|
||||||
local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, { show_header = false })
|
local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, { header = false })
|
||||||
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
||||||
vim.api.nvim_win_close(winnr, true)
|
vim.api.nvim_win_close(winnr, true)
|
||||||
return lines
|
return lines
|
||||||
@@ -1529,7 +1567,7 @@ describe('vim.diagnostic', function()
|
|||||||
|
|
||||||
eq({"1. Info", "2. Warning", "3. Error", "4. Syntax error"}, exec_lua [[
|
eq({"1. Info", "2. Warning", "3. Error", "4. Syntax error"}, exec_lua [[
|
||||||
vim.diagnostic.config({severity_sort = { reverse = true } })
|
vim.diagnostic.config({severity_sort = { reverse = true } })
|
||||||
local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, { show_header = false })
|
local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, { header = false })
|
||||||
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
||||||
vim.api.nvim_win_close(winnr, true)
|
vim.api.nvim_win_close(winnr, true)
|
||||||
return lines
|
return lines
|
||||||
@@ -1553,7 +1591,7 @@ describe('vim.diagnostic', function()
|
|||||||
make_warning('Warning', 0, 0, 0, 1),
|
make_warning('Warning', 0, 0, 0, 1),
|
||||||
})
|
})
|
||||||
|
|
||||||
local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, { show_header = false })
|
local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, { header = false })
|
||||||
if not float_bufnr then
|
if not float_bufnr then
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
@@ -1580,7 +1618,7 @@ describe('vim.diagnostic', function()
|
|||||||
}
|
}
|
||||||
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
||||||
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
||||||
local float_bufnr, winnr = vim.diagnostic.open_float(0, {show_header = false, number = "always"})
|
local float_bufnr, winnr = vim.diagnostic.open_float(0, {header = false})
|
||||||
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
||||||
vim.api.nvim_win_close(winnr, true)
|
vim.api.nvim_win_close(winnr, true)
|
||||||
return lines
|
return lines
|
||||||
@@ -1593,7 +1631,7 @@ describe('vim.diagnostic', function()
|
|||||||
}
|
}
|
||||||
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
||||||
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
||||||
local float_bufnr, winnr = vim.diagnostic.open_float(0, {show_header = false, prefix = ""})
|
local float_bufnr, winnr = vim.diagnostic.open_float(0, {header = false, prefix = ""})
|
||||||
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
|
||||||
vim.api.nvim_win_close(winnr, true)
|
vim.api.nvim_win_close(winnr, true)
|
||||||
return lines
|
return lines
|
||||||
@@ -1607,7 +1645,7 @@ describe('vim.diagnostic', function()
|
|||||||
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
||||||
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
||||||
local float_bufnr, winnr = vim.diagnostic.open_float(0, {
|
local float_bufnr, winnr = vim.diagnostic.open_float(0, {
|
||||||
show_header = false,
|
header = false,
|
||||||
prefix = function(_, i, total)
|
prefix = function(_, i, total)
|
||||||
-- Only show a number if there is more than one diagnostic
|
-- Only show a number if there is more than one diagnostic
|
||||||
if total > 1 then
|
if total > 1 then
|
||||||
@@ -1628,7 +1666,7 @@ describe('vim.diagnostic', function()
|
|||||||
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
||||||
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
|
||||||
local float_bufnr, winnr = vim.diagnostic.open_float(0, {
|
local float_bufnr, winnr = vim.diagnostic.open_float(0, {
|
||||||
show_header = false,
|
header = false,
|
||||||
prefix = function(_, i, total)
|
prefix = function(_, i, total)
|
||||||
-- Only show a number if there is more than one diagnostic
|
-- Only show a number if there is more than one diagnostic
|
||||||
if total > 1 then
|
if total > 1 then
|
||||||
@@ -1642,7 +1680,7 @@ describe('vim.diagnostic', function()
|
|||||||
return lines
|
return lines
|
||||||
]])
|
]])
|
||||||
|
|
||||||
eq("Error executing lua: .../diagnostic.lua:0: prefix: expected 'string' or 'function', got 42",
|
eq("Error executing lua: .../diagnostic.lua:0: prefix: expected 'string' or 'table' or 'function', got 42",
|
||||||
pcall_err(exec_lua, [[ vim.diagnostic.open_float(0, { prefix = 42 }) ]]))
|
pcall_err(exec_lua, [[ vim.diagnostic.open_float(0, { prefix = 42 }) ]]))
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user