diff --git a/plugin/build.lua b/plugin/build.lua index ce3ff19..e924a74 100644 --- a/plugin/build.lua +++ b/plugin/build.lua @@ -31,9 +31,12 @@ function build.set_dir(dirname) -- Restart clangd language server on_exit = function() - vim.cmd('LspStop') - vim.cmd('LspStart') - echo('Build directory selected: ' .. dirname, 'DiagnosticInfo') + -- This is a callback so doesn't run on the main thread which causes + -- issues for running commands, so schedule that on the main thread. + vim.schedule(function() + vim.cmd('LspRestart') + echo('Build directory selected: ' .. dirname, 'DiagnosticInfo') + end) end, -- Display any error messages to the user