diff options
| author | Stephan Seitz <stephan.seitz@fau.de> | 2021-04-30 16:46:38 +0200 |
|---|---|---|
| committer | Stephan Seitz <stephan.lauf@yahoo.de> | 2021-06-01 21:38:17 +0200 |
| commit | 66f75c58d9fc984443becad301e78112323d7991 (patch) | |
| tree | c93307ad2a0a190e8a09514c8dcd06d7d500f368 /lua | |
| parent | Update lockfile.json (diff) | |
| download | nvim-treesitter-66f75c58d9fc984443becad301e78112323d7991.tar nvim-treesitter-66f75c58d9fc984443becad301e78112323d7991.tar.gz nvim-treesitter-66f75c58d9fc984443becad301e78112323d7991.tar.bz2 nvim-treesitter-66f75c58d9fc984443becad301e78112323d7991.tar.lz nvim-treesitter-66f75c58d9fc984443becad301e78112323d7991.tar.xz nvim-treesitter-66f75c58d9fc984443becad301e78112323d7991.tar.zst nvim-treesitter-66f75c58d9fc984443becad301e78112323d7991.zip | |
chore: show errors output during async installation
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-treesitter/install.lua | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index 22e34b764..6398c7c7e 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -16,6 +16,8 @@ M.compilers = { vim.fn.getenv('CC'), "cc", "gcc", "clang", "cl" } local started_commands = 0 local finished_commands = 0 local failed_commands = 0 +local complete_std_output = {} +local complete_error_output = {} local function reset_progress_counter() if started_commands ~= finished_commands then @@ -24,6 +26,8 @@ local function reset_progress_counter() started_commands = 0 finished_commands = 0 failed_commands = 0 + complete_std_output = {} + complete_error_output = {} end local function get_job_status() @@ -57,6 +61,18 @@ local function outdated_parsers() info.installed_parsers()) end +local function onread(handle, is_stderr) + return function(err, data) + if data then + if is_stderr then + complete_error_output[handle] = (complete_error_output[handle] or '')..data + else + complete_std_output[handle] = (complete_std_output[handle] or '')..data + end + end + end +end + function M.iter_cmd(cmd_list, i, lang, success_message) if i == 1 then started_commands = started_commands + 1 @@ -81,15 +97,36 @@ function M.iter_cmd(cmd_list, i, lang, success_message) end else local handle + local stdout = luv.new_pipe(false) + local stderr = luv.new_pipe(false) + attr.opts.stdio = {nil, stdout, stderr} handle = luv.spawn(attr.cmd, attr.opts, vim.schedule_wrap(function(code) + if code ~= 0 then + stdout:read_stop() + stderr:read_stop() + end + stdout:close() + stderr:close() handle:close() if code ~= 0 then failed_commands = failed_commands + 1 finished_commands = finished_commands + 1 - return api.nvim_err_writeln(attr.err or ("Failed to execute the following command:\n"..vim.inspect(attr))) + if complete_std_output[handle] and complete_std_output[handle] ~= '' then + print(complete_std_output[handle]) + end + + local err_msg = complete_error_output[handle] or '' + api.nvim_err_writeln( + 'nvim-treesitter['..lang..']: ' + ..(attr.err or ("Failed to execute the following command:\n"..vim.inspect(attr))) + ..'\n' + ..err_msg) + return end M.iter_cmd(cmd_list, i + 1, lang, success_message) end)) + luv.read_start(stdout, onread(handle, false)) + luv.read_start(stderr, onread(handle, true)) end end |
