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,15 +26,22 @@ function build.set_dir(dirname)
build.dir = build_dir build.dir = build_dir
-- Invoke async function to avoid blocking the UI
vim.schedule(function()
echo('Processing compile_commands.json with compdb ...', 'DiagnosticInfo') echo('Processing compile_commands.json with compdb ...', 'DiagnosticInfo')
-- Post-process compile_commands.json with compdb
local compile_commands = current_dir .. '/compile_commands.json' local compile_commands = current_dir .. '/compile_commands.json'
local output = vim.fn.systemlist( -- Post-process compile_commands.json with compdb as an async job to avoid
'compdb -p ' .. build.dir .. ' list > ' .. compile_commands) -- blocking the user interface
vim.fn.jobstart(
'compdb -p ' .. build.dir .. ' list > ' .. compile_commands, {
-- Restart clangd language server
-- TODO: Configure cmake language server?
on_exit = function()
vim.cmd [[ LspRestart clangd ]]
echo('Build directory selected: ' .. dirname, 'DiagnosticInfo')
end,
-- Display any error messages to the user
on_stderr = function(_, output, _)
-- Remove any lines containing a compdb warning -- Remove any lines containing a compdb warning
local error = {} local error = {}
local warning = 'WARNING:compdb' local warning = 'WARNING:compdb'
@ -49,14 +56,11 @@ function build.set_dir(dirname)
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'")