@@ -629,93 +629,98 @@ function B.build(config, notify, opts)
629629 end
630630 end ,
631631 on_exit = function (_ , code )
632- local diagcfg = (config .diagnostics and config .diagnostics .quickfix ) or {}
633- local qf_enabled = (diagcfg .enabled ~= false )
634- local lines = {}
635- for _ , s in ipairs (all_stdout ) do table.insert (lines , s ) end
636- for _ , s in ipairs (all_stderr ) do table.insert (lines , s ) end
637- if # lines > 0 then write_build_logs (lines ) end
638- -- Compute diagnostics summary for notification
639- local items = {}
640- do
641- local parsed = { U .parse_diagnostics (lines ) }
642- items = parsed [1 ] or {}
643- end
632+ -- Ensure any unexpected error here won't block the task queue
644633 local err_cnt , warn_cnt = 0 , 0
645- for _ , it in ipairs (items ) do
646- if it .type == ' E' then err_cnt = err_cnt + 1 else warn_cnt = warn_cnt + 1 end
647- end
648- if qf_enabled and # lines > 0 then
649- local items , has_error , has_warning = U .parse_diagnostics (lines )
650- if # items > 0 then
651- vim .fn .setqflist ({}, ' ' , { title = ' Quick-c Build' , items = items })
652- local function should_open ()
653- if diagcfg .open == ' always' then return true end
654- if diagcfg .open == ' error' and has_error then return true end
655- if diagcfg .open == ' warning' and (has_error or has_warning ) then return true end
656- return false
657- end
658- local function should_jump ()
659- if diagcfg .jump == ' always' then return true end
660- if diagcfg .jump == ' error' and has_error then return true end
661- if diagcfg .jump == ' warning' and (has_error or has_warning ) then return true end
662- return false
634+ local ok = pcall (function ()
635+ local diagcfg = (config .diagnostics and config .diagnostics .quickfix ) or {}
636+ local qf_enabled = (diagcfg .enabled ~= false )
637+ local lines = {}
638+ for _ , s in ipairs (all_stdout ) do table.insert (lines , s ) end
639+ for _ , s in ipairs (all_stderr ) do table.insert (lines , s ) end
640+ if # lines > 0 then pcall (write_build_logs , lines ) end
641+ -- Compute diagnostics summary for notification (protected)
642+ local parsed_items = {}
643+ local ok_parse , pitems , has_error , has_warning = pcall (U .parse_diagnostics , lines )
644+ if ok_parse then
645+ parsed_items = pitems or {}
646+ for _ , it in ipairs (parsed_items ) do
647+ if it .type == ' E' then err_cnt = err_cnt + 1 else warn_cnt = warn_cnt + 1 end
663648 end
664- if should_open () then
665- if diagcfg .use_telescope then
666- local ok_qc , qct = pcall (require , ' quick-c.telescope' )
667- if ok_qc and qct and qct .telescope_quickfix then
668- pcall (qct .telescope_quickfix , config )
669- else
670- local ok_tb , tb = pcall (require , ' telescope.builtin' )
671- if ok_tb and tb and tb .quickfix then
672- pcall (tb .quickfix )
649+ else
650+ parsed_items = {}
651+ err_cnt , warn_cnt = 0 , 0
652+ end
653+ if qf_enabled and # lines > 0 then
654+ if ok_parse and # parsed_items > 0 then
655+ pcall (vim .fn .setqflist , {}, ' ' , { title = ' Quick-c Build' , items = parsed_items })
656+ local function should_open ()
657+ if diagcfg .open == ' always' then return true end
658+ if diagcfg .open == ' error' and has_error then return true end
659+ if diagcfg .open == ' warning' and (has_error or has_warning ) then return true end
660+ return false
661+ end
662+ local function should_jump ()
663+ if diagcfg .jump == ' always' then return true end
664+ if diagcfg .jump == ' error' and has_error then return true end
665+ if diagcfg .jump == ' warning' and (has_error or has_warning ) then return true end
666+ return false
667+ end
668+ if should_open () then
669+ if diagcfg .use_telescope then
670+ local ok_qc , qct = pcall (require , ' quick-c.telescope' )
671+ if ok_qc and qct and qct .telescope_quickfix then
672+ pcall (qct .telescope_quickfix , config )
673673 else
674- pcall (vim .cmd , ' copen' )
674+ local ok_tb , tb = pcall (require , ' telescope.builtin' )
675+ if ok_tb and tb and tb .quickfix then
676+ pcall (tb .quickfix )
677+ else
678+ pcall (vim .cmd , ' copen' )
679+ end
675680 end
681+ else
682+ pcall (vim .cmd , ' copen' )
676683 end
677- else
678- pcall (vim .cmd , ' copen' )
679- end
680- if not (pcall (require , ' telescope' )) then
681- local info = vim .fn .getqflist ({ winid = 1 }) or {}
682- local wid = info .winid or 0
683- if wid ~= 0 then
684- pcall (vim .api .nvim_win_set_option , wid , ' wrap' , true )
685- pcall (vim .api .nvim_win_set_option , wid , ' linebreak' , true )
686- pcall (vim .api .nvim_win_set_option , wid , ' breakindent' , true )
684+ if not (pcall (require , ' telescope' )) then
685+ local info = vim .fn .getqflist ({ winid = 1 }) or {}
686+ local wid = info .winid or 0
687+ if wid ~= 0 then
688+ pcall (vim .api .nvim_win_set_option , wid , ' wrap' , true )
689+ pcall (vim .api .nvim_win_set_option , wid , ' linebreak' , true )
690+ pcall (vim .api .nvim_win_set_option , wid , ' breakindent' , true )
691+ end
687692 end
688693 end
689- end
690- if should_jump () then
691- local cur = vim .api .nvim_get_current_buf ( )
692- local nameb = vim . api . nvim_buf_get_name ( cur )
693- local modified = false
694- pcall ( function () modified = vim . api . nvim_buf_get_option ( cur , ' modified ' ) end )
695- if not ( nameb == ' ' and modified ) then
696- pcall ( vim . cmd , ' silent! keepalt keepjumps cc ' )
694+ if should_jump () then
695+ local cur = vim . api . nvim_get_current_buf ()
696+ local nameb = vim .api .nvim_buf_get_name ( cur )
697+ local modified = false
698+ pcall ( function () modified = vim . api . nvim_buf_get_option ( cur , ' modified ' ) end )
699+ if not ( nameb == ' ' and modified ) then
700+ pcall ( vim . cmd , ' silent! keepalt keepjumps cc ' )
701+ end
697702 end
703+ else
704+ if code == 0 then pcall (vim .fn .setqflist , {}) end
698705 end
706+ end
707+ local dur = (((vim .loop and vim .loop .now and vim .loop .now ()) or started_at ) - started_at )
708+ local secs = (dur or 0 ) / 1000
709+ local msg = {}
710+ if code == 0 then
711+ table.insert (msg , string.format (' Build OK -> %s' , exe ))
699712 else
700- if code == 0 then vim . fn . setqflist {} end
713+ table.insert ( msg , string.format ( ' Build failed (%d) ' , code ))
701714 end
702- end
703- local dur = (((vim .loop and vim .loop .now and vim .loop .now ()) or started_at ) - started_at )
704- local secs = (dur or 0 ) / 1000
705- local msg = {}
706- if code == 0 then
707- table.insert (msg , string.format (' Build OK -> %s' , exe ))
708- else
709- table.insert (msg , string.format (' Build failed (%d)' , code ))
710- end
711- table.insert (msg , string.format (' Time: %.2fs | Errors: %d, Warnings: %d' , secs , err_cnt , warn_cnt ))
712- table.insert (msg , ' Cmd: ' .. cmdline )
713- local full = table.concat (msg , ' \n ' )
714- if code == 0 then notify .info (full ) else notify .err (full ) end
715- if code == 0 then
716- local root = vim .fn .getcwd ()
717- LAST_EXE [U .norm (root )] = exe
718- end
715+ table.insert (msg , string.format (' Time: %.2fs | Errors: %d, Warnings: %d' , secs , err_cnt , warn_cnt ))
716+ table.insert (msg , ' Cmd: ' .. cmdline )
717+ local full = table.concat (msg , ' \n ' )
718+ if code == 0 then notify .info (full ) else notify .err (full ) end
719+ if code == 0 then
720+ local root = vim .fn .getcwd ()
721+ LAST_EXE [U .norm (root )] = exe
722+ end
723+ end )
719724 if opts .on_exit then pcall (opts .on_exit , code , exe ) end
720725 done (code )
721726 end ,
0 commit comments