Compare commits

...

2 Commits

Author SHA1 Message Date
15d3879525 Actually run compdb asynchronously
Turns out vim.schedule() only defers calling the function until main
event loop has some free cycles but can still block the UI, just a bit
later. This patch replaces the external command invoked in the callback
passed into vim.schedule() with vim.fn.jobstart() and moves the other
code into job callbacks.
2024-03-14 21:13:28 +00:00
fb2d661a0e Remove J/K mappings to move block up/down a line 2024-03-14 20:41:58 +00:00
2 changed files with 31 additions and 31 deletions

View File

@ -26,37 +26,41 @@ function build.set_dir(dirname)
build.dir = build_dir build.dir = build_dir
-- Invoke async function to avoid blocking the UI echo('Processing compile_commands.json with compdb ...', 'DiagnosticInfo')
vim.schedule(function() local compile_commands = current_dir .. '/compile_commands.json'
echo('Processing compile_commands.json with compdb ...', 'DiagnosticInfo') -- Post-process compile_commands.json with compdb as an async job to avoid
-- blocking the user interface
vim.fn.jobstart(
'compdb -p ' .. build.dir .. ' list > ' .. compile_commands, {
-- Post-process compile_commands.json with compdb -- Restart clangd language server
local compile_commands = current_dir .. '/compile_commands.json' -- TODO: Configure cmake language server?
local output = vim.fn.systemlist( on_exit = function()
'compdb -p ' .. build.dir .. ' list > ' .. compile_commands) vim.cmd [[ LspRestart clangd ]]
echo('Build directory selected: ' .. dirname, 'DiagnosticInfo')
end,
-- Remove any lines containing a compdb warning -- Display any error messages to the user
local error = {} on_stderr = function(_, output, _)
local warning = 'WARNING:compdb' -- Remove any lines containing a compdb warning
for _, line in ipairs(output) do local error = {}
if string.sub(line, 1, #warning) ~= warning then local warning = 'WARNING:compdb'
table.insert(error, line) for _, line in ipairs(output) do
end if string.sub(line, 1, #warning) ~= warning then
end table.insert(error, line)
end
end
-- Display the error message if there was one -- Display the error message if there was one
if table.maxn(error) > 0 then if table.maxn(error) > 0 then
echo(vim.fn.join(error, '\n'), 'Error') echo(vim.fn.join(error, '\n'), 'Error')
return return
end end
end,
-- TODO: Configure cmake language server? stderr_buffered = true,
}
-- Restart clangd language server )
vim.cmd [[ LspRestart clangd ]]
echo('Build directory selected: ' .. dirname, 'DiagnosticInfo')
end)
end end
function build.select_dir(callback) function build.select_dir(callback)

View File

@ -43,7 +43,3 @@ vim.keymap.set('n', 'Q', '<nop>', {noremap = true})
-- Undo neovim's default mapping of Y to y$ -- Undo neovim's default mapping of Y to y$
vim.cmd('unmap Y') vim.cmd('unmap Y')
-- Move visually selected blocks around
vim.keymap.set('v', 'J', ":move '>+1<CR>gv=gv'")
vim.keymap.set('v', 'K', ":move '<-2<CR>gv=gv'")