From c0f255aa8f8165b0fd665ecc561223695d197072 Mon Sep 17 00:00:00 2001 From: "Philip J." Date: Tue, 29 Oct 2024 23:14:44 +0100 Subject: [PATCH] Buffer stderr and stdout before triggering callbacks Currently, whenever the compile_command outputs data on stdout or stderr the corresponding on_stdout or on_stderr is called. This results in multiple (at least 5 for even one compilation error) calls to those functions which in turn do some work parsing errors. Adding stdout_buffered and stderr_buffered to jobstart will wait until they finish writing to those descriptors, reducing the calls to on_stdout and on_stderr to at most one. --- lua/compile-mode/init.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/compile-mode/init.lua b/lua/compile-mode/init.lua index c3443f4..bbe0d0f 100644 --- a/lua/compile-mode/init.lua +++ b/lua/compile-mode/init.lua @@ -145,7 +145,9 @@ local runjob = a.wrap(function(cmd, bufnr, param, callback) log.debug("starting job...") local job_id = vim.fn.jobstart(cmd, { cwd = vim.g.compilation_directory, + stdout_buffered = true, on_stdout = on_either, + stderr_buffered = true, on_stderr = on_either, on_exit = function(id, code) callback(count, code, id)