Skip to content

Commit 1974ce9

Browse files
authored
Merge pull request #239 from kaihowl/use-qf-id
fix: use qf id to prevent interleaving output
2 parents 6942fc4 + e43b787 commit 1974ce9

File tree

3 files changed

+52
-8
lines changed

3 files changed

+52
-8
lines changed

README-cn.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@
240240
- g:asyncrun_timer - 每 100ms 处理多少条消息,默认为 25。
241241
- g:asyncrun_wrapper - 命令前缀,默认为空,比如可以设置成 `nice`
242242
- g:asyncrun_stdin - 设置成非零的话,允许 stdin,比如 cmake 在 windows 下要求 stdin 为打开状态。
243+
- g:asyncrun_qfid - 使用 quickfix id 来防止附加到 quickfix 列表的并发插件的交错输出。
243244

244245
更多配置内容,见 **[这里](https://github.com/skywind3000/asyncrun.vim/wiki/Options)**.
245246

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ parameters:
247247
- g:asyncrun_timer - how many messages should be inserted into quickfix every 100ms interval.
248248
- g:asyncrun_wrapper - enable to setup a command prefix.
249249
- g:asyncrun_stdin - non-zero to enable stdin (useful for cmake on windows).
250+
- g:asyncrun_qfid - use quickfix id to prevent interleaving output of concurrent plugins appending to the quickfix list.
250251

251252
For more information of above options, please visit **[option details](https://github.com/skywind3000/asyncrun.vim/wiki/Options)**.
252253

plugin/asyncrun.vim

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ let g:asyncrun_stop = get(g:, 'asyncrun_stop', '')
130130
" specify how to run your command
131131
let g:asyncrun_mode = get(g:, 'asyncrun_mode', 0)
132132

133+
" Use quickfix-ID to allow concurrent use of quickfix list and not
134+
" interleave streamed output of a running command with output from
135+
" other plugins
136+
if !exists('g:asyncrun_qf_id')
137+
let g:asyncrun_qf_id = has('patch-8.0.1023') || has('nvim-0.6.1')
138+
endif
139+
133140
" command hook
134141
let g:asyncrun_hook = get(g:, 'asyncrun_hook', '')
135142

@@ -431,16 +438,33 @@ function! s:AsyncRun_Job_Update(count, ...)
431438
if once == 0
432439
if l:text != ''
433440
if l:raw == 0
434-
if and(g:asyncrun_skip, 1) == 0
435-
caddexpr l:text
441+
if exists('s:qf_id')
442+
let qflist = {'id': s:qf_id, 'lines': split(l:text, "\n")}
443+
if and(g:asyncrun_skip, 1) == 0
444+
call setqflist([], 'a', qflist)
445+
else
446+
noautocmd call setqflist([], 'a', qflist)
447+
endif
436448
else
437-
noautocmd caddexpr l:text
449+
if and(g:asyncrun_skip, 1) == 0
450+
caddexpr l:text
451+
else
452+
noautocmd caddexpr l:text
453+
endif
438454
endif
439455
else
440-
call setqflist([{'text':l:text}], 'a')
456+
if exists('s:qf_id')
457+
call setqflist([], 'a', {'id': s:qf_id, 'items': [{'text':l:text}]})
458+
else
459+
call setqflist([{'text':l:text}], 'a')
460+
endif
441461
endif
442462
elseif g:asyncrun_trim == 0
443-
call setqflist(l:empty, 'a')
463+
if exists('s:qf_id')
464+
call setqflist([], 'a', {'id': s:qf_id, 'items': l:empty})
465+
else
466+
call setqflist(l:empty, 'a')
467+
endif
444468
endif
445469
else
446470
if l:text != ''
@@ -568,20 +592,31 @@ function! s:AsyncRun_Job_OnFinish()
568592
call timer_stop(s:async_timer)
569593
unlet s:async_timer
570594
endif
595+
if exists('s:qf_id')
596+
unlet s:qf_id
597+
endif
571598
call s:AsyncRun_Job_Update(-1, s:async_info.once)
572599
let l:current = localtime()
573600
let l:last = l:current - s:async_start
574601
let l:check = s:AsyncRun_Job_CheckScroll()
575602
if s:async_code == 0
576603
let l:text = "[Finished in ".l:last." seconds]"
577604
if !s:async_info.strip
578-
call setqflist([{'text':l:text}], 'a')
605+
if exists('s:qf_id')
606+
call setqflist([], 'a', {'id': s:qf_id, 'items': [{'text':l:text}]})
607+
else
608+
call setqflist([{'text':l:text}], 'a')
609+
endif
579610
endif
580611
let g:asyncrun_status = "success"
581612
else
582613
let l:text = 'with code '.s:async_code
583614
let l:text = "[Finished in ".l:last." seconds ".l:text."]"
584-
call setqflist([{'text':l:text}], 'a')
615+
if exists('s:qf_id')
616+
call setqflist([], 'a', {'id': s:qf_id, 'lines': [l:text]})
617+
else
618+
call setqflist([{'text':l:text}], 'a')
619+
endif
585620
let g:asyncrun_status = "failure"
586621
endif
587622
let s:async_state = 0
@@ -842,8 +877,15 @@ function! s:AsyncRun_Job_Start(cmd)
842877
call setqflist([], ' ', l:title)
843878
endif
844879
endif
880+
if g:asyncrun_qf_id == 1
881+
let s:qf_id = getqflist({'id':0}).id
882+
endif
845883
if !s:async_info.strip
846-
call setqflist([{'text':l:arguments}], 'a')
884+
if exists('s:qf_id')
885+
call setqflist([], 'a', {'id': s:qf_id, 'lines': [l:arguments]})
886+
else
887+
call setqflist([{'text':l:arguments}], 'a')
888+
endif
847889
endif
848890
let l:name = 'g:AsyncRun_Job_OnTimer'
849891
let s:async_timer = timer_start(100, l:name, {'repeat':-1})

0 commit comments

Comments
 (0)