Common library code for other vc*.nvim projects.

Add command running code.

+23
+23
lua/vclib/run.lua
··· 1 + local M = {} 2 + 3 + local logging = require("vclib.logging") 4 + 5 + function M.run_with_timeout(cmd, opts, callback) 6 + logging.vclib_verbose("Running command: " .. table.concat(cmd, " ")) 7 + local merged_opts = vim.tbl_deep_extend("force", { timeout = 2000 }, opts) 8 + if callback == nil then 9 + return vim.system(cmd, merged_opts) 10 + end 11 + 12 + return vim.system(cmd, merged_opts, function(out) 13 + if out.code == 124 then 14 + logging.vclib_verbose("Command timed out: " .. table.concat(cmd, " ")) 15 + return 16 + end 17 + vim.schedule(function() 18 + callback(out) 19 + end) 20 + end) 21 + end 22 + 23 + return M