feat(diagnostics): add diagnostics when running :make
This commit is contained in:
@@ -10,7 +10,7 @@ vim.api.nvim_create_autocmd("FileType", {
|
|||||||
desc = "Fix parsing compile errors into quickfixlist",
|
desc = "Fix parsing compile errors into quickfixlist",
|
||||||
pattern = "zig",
|
pattern = "zig",
|
||||||
callback = function()
|
callback = function()
|
||||||
vim.bo.errorformat = '%f:%l:%c: %t%.%#: %m,%-G%.%#'
|
vim.bo.errorformat = "%f:%l:%c: %t%.%#: %m,%-G%.%#"
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -19,3 +19,56 @@ vim.api.nvim_create_autocmd({ "BufReadPost" }, {
|
|||||||
pattern = "*",
|
pattern = "*",
|
||||||
command = 'silent! normal! g`"zv',
|
command = 'silent! normal! g`"zv',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
local make_group = vim.api.nvim_create_augroup("make_diagnostics", {})
|
||||||
|
local make_namespace = vim.api.nvim_create_namespace("make_diagnostics")
|
||||||
|
-- Create diagnostics after running :make
|
||||||
|
vim.api.nvim_create_autocmd("QuickFixCmdPost", {
|
||||||
|
callback = function(ctx)
|
||||||
|
if ctx.match ~= "make" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local diagnostics = vim.diagnostic.fromqflist(vim.fn.getqflist())
|
||||||
|
local buf_diag = {}
|
||||||
|
for _, d in ipairs(diagnostics) do
|
||||||
|
if not d.bufnr then
|
||||||
|
goto continue
|
||||||
|
end
|
||||||
|
|
||||||
|
if not buf_diag[d.bufnr] then
|
||||||
|
buf_diag[d.bufnr] = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
table.insert(buf_diag[d.bufnr], d)
|
||||||
|
|
||||||
|
::continue::
|
||||||
|
end
|
||||||
|
|
||||||
|
for bufnr, d in pairs(buf_diag) do
|
||||||
|
vim.diagnostic.set(make_namespace, bufnr, d)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
group = make_group,
|
||||||
|
})
|
||||||
|
-- Clear old make diagnostics before running :make
|
||||||
|
vim.api.nvim_create_autocmd("QuickFixCmdPre", {
|
||||||
|
callback = function(ctx)
|
||||||
|
if ctx.match ~= "make" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local diagnostics = vim.diagnostic.fromqflist(vim.fn.getqflist())
|
||||||
|
local bufs = {}
|
||||||
|
for _, d in ipairs(diagnostics) do
|
||||||
|
if d.bufnr then
|
||||||
|
table.insert(bufs, d.bufnr)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, bufnr in ipairs(bufs) do
|
||||||
|
vim.diagnostic.reset(make_namespace, bufnr)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
group = make_group,
|
||||||
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user