1
0

Added building via shell in neovim

Display diagnostics inline to buffer
List compile errors/warnings in quickfix list
Added 'push' command to install script
Make sure install script executes from the correct directory
This commit is contained in:
2025-09-24 23:03:16 +01:00
parent d0ba7f74b1
commit ce611a0e14
2 changed files with 109 additions and 6 deletions

View File

@@ -59,6 +59,90 @@ vim.opt.listchars:append({ lead = "." })
-- Functions
--------------------------------------------------------------------------------
-- Building & Errors
-- Diagnostics configuration
vim.diagnostic.config({
signs = {
text = {
[vim.diagnostic.severity.ERROR] = "",
[vim.diagnostic.severity.WARN] = ""
},
linehl = {
[vim.diagnostic.severity.ERROR] = "DiagnosticLineError",
[vim.diagnostic.severity.WARN] = "DiagnosticLineWarn"
},
},
virtual_text = {
virt_text_pos = "eol_right_align",
prefix =
function(d, i, total)
return d.severity == vim.diagnostic.severity.ERROR and "!" or "#"
end
},
underline = false,
severity_sort = true
})
local _last_build = ""
local _quickfix = {}
local _namespace = vim.api.nvim_create_namespace("__qf.buffer.errors")
local function LoadDiagnostics(args)
local bufnr = args.buf
if _quickfix[bufnr] then
vim.diagnostic.set(_namespace, bufnr, _quickfix[bufnr])
end
end
local function ExecuteBuild()
vim.cmd("silent make")
-- Reset currently displayed diagnostics
_quickfix = {}
vim.diagnostic.reset()
local entries = vim.fn.getqflist()
if #entries ~= 0 then
-- Group diagnostics by buffer number
local diagnostics = vim.diagnostic.fromqflist(entries)
for _, d in ipairs(diagnostics) do
if not _quickfix[d.bufnr] then
_quickfix[d.bufnr] = {}
end
table.insert(_quickfix[d.bufnr], d)
end
-- Display the new diagnostics
for it, v in pairs(_quickfix) do
vim.diagnostic.set(_namespace, it, v)
end
end
end
local function PromptBuild()
vim.ui.input(
{
prompt = "Compile: ",
completion = "shellcmdline",
default = _last_build
},
function(input)
if input ~= nil then
local makeprg = vim.o.makeprg
vim.o.makeprg = input
ExecuteBuild()
_last_build = input
vim.o.makeprg = makeprg
end
end
)
end
-- Buffers
local function BufferComplete()
@@ -185,6 +269,7 @@ MAP("i", "<S-Tab>", "<C-o><<")
MAP("i", "<Tab>", BufferComplete, { expr = true })
MAP("n", "<Leader>s", ManageSplit)
MAP("n", "<Leader>f", ProjectSearch)
MAP("n", "<Leader>m", PromptBuild)
--------------------------------------------------------------------------------
-- Autocommands
@@ -193,8 +278,9 @@ MAP("n", "<Leader>f", ProjectSearch)
AUTOCMD('BufEnter', { command = "let b:man_default_sects=\"2,3\"", pattern = "*.c" })
AUTOCMD('BufReadPost', { command = "setlocal nornu", pattern = "quickfix" })
AUTOCMD('BufWritePre', { callback = TrimBuffer, pattern = "*" })
AUTOCMD('VimEnter', { callback = MakeScratch, pattern = "*" })
AUTOCMD('BufWinEnter', { callback = LayoutHelp, pattern = "*" })
AUTOCMD('WinEnter', { callback = ExpandHelp, pattern = "*" })
AUTOCMD('WinLeave', { callback = ExpandHelp, pattern = "*" })
AUTOCMD('BufWritePre', { callback = TrimBuffer, pattern = "*" })
AUTOCMD('VimEnter', { callback = MakeScratch, pattern = "*" })
AUTOCMD('BufWinEnter', { callback = LayoutHelp, pattern = "*" })
AUTOCMD('WinEnter', { callback = ExpandHelp, pattern = "*" })
AUTOCMD('WinLeave', { callback = ExpandHelp, pattern = "*" })
AUTOCMD('BufRead', { callback = LoadDiagnostics, pattern = "*" })