Compare commits

...

1 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

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)