mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00

committed by
GitHub

parent
05a07ff7af
commit
50ff37308a
@@ -696,7 +696,7 @@ do
|
|||||||
|
|
||||||
local buffer_diagnostics = M.diagnostics_by_buf[bufnr]
|
local buffer_diagnostics = M.diagnostics_by_buf[bufnr]
|
||||||
if not buffer_diagnostics then return end
|
if not buffer_diagnostics then return end
|
||||||
local line_diagnostics = M.diagnostics_group_by_line(buffer_diagnostics[line])
|
local line_diagnostics = M.diagnostics_group_by_line(buffer_diagnostics)[line]
|
||||||
if not line_diagnostics then return end
|
if not line_diagnostics then return end
|
||||||
|
|
||||||
for i, diagnostic in ipairs(line_diagnostics) do
|
for i, diagnostic in ipairs(line_diagnostics) do
|
||||||
@@ -707,6 +707,7 @@ do
|
|||||||
-- TODO(ashkan) make format configurable?
|
-- TODO(ashkan) make format configurable?
|
||||||
local prefix = string.format("%d. ", i)
|
local prefix = string.format("%d. ", i)
|
||||||
local hiname = severity_highlights[diagnostic.severity]
|
local hiname = severity_highlights[diagnostic.severity]
|
||||||
|
assert(hiname, 'unknown severity: ' .. tostring(diagnostic.severity))
|
||||||
local message_lines = split_lines(diagnostic.message)
|
local message_lines = split_lines(diagnostic.message)
|
||||||
table.insert(lines, prefix..message_lines[1])
|
table.insert(lines, prefix..message_lines[1])
|
||||||
table.insert(highlights, {#prefix + 1, hiname})
|
table.insert(highlights, {#prefix + 1, hiname})
|
||||||
|
@@ -861,4 +861,29 @@ describe('LSP', function()
|
|||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
describe('lsp.util.show_line_diagnostics', function()
|
||||||
|
it('creates floating window and returns popup bufnr and winnr if current line contains diagnostics', function()
|
||||||
|
eq(3, exec_lua [[
|
||||||
|
local buffer = vim.api.nvim_create_buf(false, true)
|
||||||
|
vim.api.nvim_buf_set_lines(buffer, 0, -1, false, {
|
||||||
|
"testing";
|
||||||
|
"123";
|
||||||
|
})
|
||||||
|
local diagnostics = {
|
||||||
|
{
|
||||||
|
range = {
|
||||||
|
start = { line = 0; character = 1; };
|
||||||
|
["end"] = { line = 0; character = 3; };
|
||||||
|
};
|
||||||
|
severity = vim.lsp.protocol.DiagnosticSeverity.Error;
|
||||||
|
message = "Syntax error";
|
||||||
|
},
|
||||||
|
}
|
||||||
|
vim.api.nvim_win_set_buf(0, buffer)
|
||||||
|
vim.lsp.util.buf_diagnostics_save_positions(vim.fn.bufnr(buffer), diagnostics)
|
||||||
|
local popup_bufnr, winnr = vim.lsp.util.show_line_diagnostics()
|
||||||
|
return popup_bufnr
|
||||||
|
]])
|
||||||
|
end)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user