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.
This commit is contained in:
parent
fb2d661a0e
commit
f93360d854
@ -19,22 +19,25 @@ function build.set_dir(dirname)
|
|||||||
echo('directory does not exist: ' .. build_dir, 'Error')
|
echo('directory does not exist: ' .. build_dir, 'Error')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if vim.fn.filereadable(build_dir .. '/compile_commands.json') == 0 then
|
|
||||||
echo('compile_commands.json not found in: ' .. build_dir, 'Error')
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
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 +52,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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user