@@ -69,6 +69,7 @@ local util = require("qf.util")
69
69
70
70
local fix_list = util .fix_list
71
71
local list_items = util .list_items
72
+ local valid_list_items = util .valid_list_items
72
73
local get_height = util .get_height
73
74
74
75
local post_commands = {
@@ -158,12 +159,8 @@ function qf.reopen(list)
158
159
159
160
list = fix_list (list )
160
161
161
- local new = api .nvim_get_current_win ()
162
-
163
- -- api.nvim_set_current_win(prev)
164
-
165
162
if util .get_list_win (list ) == 0 then
166
- -- return
163
+ return
167
164
end
168
165
169
166
print (" Reopening window: " .. list )
@@ -272,7 +269,7 @@ function qf.open(list, stay, silent, weak)
272
269
list = fix_list (list )
273
270
274
271
local opts = qf .config [list ]
275
- local num_items = # list_items (list )
272
+ local num_items = get_list (list , { size = 1 }). size
276
273
277
274
local other
278
275
if list == " c" then
@@ -319,7 +316,7 @@ function qf.open(list, stay, silent, weak)
319
316
end
320
317
321
318
--- Close `list`
322
- --- @param list List
319
+ --- @param list string
323
320
--- @tag qf.close() Qclose LClose VClose
324
321
function qf .close (list )
325
322
list = fix_list (list )
@@ -374,69 +371,56 @@ local is_valid = util.is_valid
374
371
375
372
-- Returns the list entry currently previous to the cursor
376
373
local function follow_prev (list , items , bufnr , line , col )
377
- local last_valid = 1
378
374
local found_buf = false
379
375
for i = 1 , # items do
380
376
local j = # items - i + 1
381
377
local item = items [j ]
382
378
383
- local valid = is_valid (item )
384
- if valid then
385
- -- We overshot the current buffer
386
- if found_buf and item .bufnr ~= bufnr then
387
- return j
388
- elseif item .bufnr == bufnr then
389
- found_buf = true
390
- -- If the current entry is past cursor, of the entry of the cursor has been
391
- -- passed
392
- item .col = math.min (item .col , linelen (item .bufnr , item .lnum ))
393
- if item .lnum < line or (item .lnum == line and (item .col > 0 and col and item .col < col )) then
394
- return j
395
- end
379
+ -- We overshot the current buffer
380
+ if found_buf or item .bufnr == bufnr then
381
+ found_buf = true
382
+ -- If the current entry is past cursor, of the entry of the cursor has been
383
+ -- passed
384
+ item .col = math.min (item .col , linelen (item .bufnr , item .lnum ))
385
+ if
386
+ item .bufnr ~= bufnr
387
+ or item .lnum < line
388
+ or (item .lnum == line and (item .col > 0 and col and item .col < col ))
389
+ then
390
+ return item .idx
396
391
end
397
392
end
398
393
end
399
394
400
- local cur = util .get_list (list , { idx = 0 }).idx
401
- if cur > 1 then
402
- return cur - 1
403
- else
404
- return # items
405
- end
395
+ return get_list (list , { size = 1 }).size
406
396
end
407
397
408
398
-- Returns the first entry after the cursor in buf or the first entry in the
409
399
-- buffer
410
400
local function follow_next (list , items , bufnr , line , col )
411
401
local found_buf = false
412
- for i , item in ipairs (items ) do
413
- local valid = is_valid (item )
414
- if valid then
415
- -- We overshot the current buffer
416
- if found_buf and item .bufnr ~= bufnr then
417
- return i
418
- elseif item .bufnr == bufnr then
419
- found_buf = true
420
- -- If the current entry is past cursor, of the entry of the cursor has been
421
- -- passed
422
- item .col = math.min (item .col , linelen (item .bufnr , item .lnum ))
423
- if item .lnum > line or (item .lnum == line and (item .col > 0 and col and item .col > col )) then
424
- return i
425
- end
402
+ for _ , item in ipairs (items ) do
403
+ -- We overshot the current buffer
404
+ if found_buf or item .bufnr == bufnr then
405
+ found_buf = true
406
+ -- If the current entry is past cursor, of the entry of the cursor has been
407
+ -- passed
408
+ item .col = math.min (item .col , linelen (item .bufnr , item .lnum ))
409
+ if
410
+ item .bufnr ~= bufnr
411
+ or item .lnum > line
412
+ or (item .lnum == line and (item .col > 0 and col and item .col > col ))
413
+ then
414
+ return item .idx
426
415
end
427
416
end
428
417
end
429
418
430
- local cur = util .get_list (list , { idx = 0 }).idx
431
- if cur < # items then
432
- return cur + 1
433
- else
434
- return 1
435
- end
419
+ return 1
436
420
end
437
421
438
422
-- Returns the list entry closest to the cursor vertically
439
- local function follow_nearest (list , items , bufnr , line , col )
423
+ local function follow_nearest (_ , items , bufnr , line , col )
440
424
local i = 1
441
425
local min = nil
442
426
local min_i = nil
@@ -560,49 +544,6 @@ function qf.prev(list, wrap, verbose)
560
544
end
561
545
end
562
546
563
- local function prev_valid (items , idx )
564
- while idx and idx > 1 do
565
- idx = idx - 1
566
- if is_valid (items [idx ]) then
567
- return idx
568
- end
569
- end
570
-
571
- return idx
572
- end
573
-
574
- local function prev_valid_wrap (items , start )
575
- for i = 1 , # items do
576
- local idx = (# items + start - i - 1 ) % # items + 1
577
- if is_valid (items [idx ]) then
578
- return idx
579
- end
580
- end
581
- return 1
582
- end
583
-
584
- local function next_valid_wrap (items , start )
585
- for i = 1 , # items do
586
- local idx = (i + start - 1 ) % # items + 1
587
- if is_valid (items [idx ]) then
588
- return idx
589
- end
590
- end
591
- return 1
592
- end
593
-
594
- local function next_valid (items , idx )
595
- while idx and idx <= # items - 1 do
596
- idx = idx + 1
597
- if is_valid (items [idx ]) then
598
- return idx
599
- end
600
- end
601
-
602
- vim .notify (" No more items" , vim .log .levels .ERROR )
603
- return nil
604
- end
605
-
606
547
--- Wrapping version of [lc]above
607
548
--- Will switch buffer
608
549
--- @tag qf.above() Qabove Labove Vabove
@@ -613,7 +554,7 @@ function qf.above(list, wrap, verbose)
613
554
614
555
list = fix_list (list )
615
556
616
- local items = list_items (list , true )
557
+ local items = valid_list_items (list )
617
558
618
559
if not check_empty (list , # items , verbose ) then
619
560
return
@@ -642,7 +583,7 @@ function qf.below(list, wrap, verbose)
642
583
end
643
584
list = fix_list (list )
644
585
645
- local items = list_items (list , true )
586
+ local items = valid_list_items (list )
646
587
647
588
if not check_empty (list , # items , verbose ) then
648
589
return
726
667
--- @field winid number | nil
727
668
--- @field title string | nil
728
669
--- @field tally boolean | nil
729
- --- @field open boolean
670
+ --- @field open boolean | nil if not specified , open if there are errors
730
671
731
672
--- Set location or quickfix list items
732
673
--- If a compiler is given, the items will be parsed from it
@@ -776,8 +717,9 @@ function qf.set(list, opts)
776
717
vim .cmd (" compiler " .. old_c )
777
718
end
778
719
720
+ local tally = util .tally (list )
779
721
if opts .tally then
780
- qf .tally (list , opts .title or " " )
722
+ qf .tally (list , opts .title or " " , tally )
781
723
end
782
724
783
725
qf .config [list ].last_line = nil
@@ -786,22 +728,52 @@ function qf.set(list, opts)
786
728
api .nvim_set_current_dir (old_cwd )
787
729
end
788
730
789
- if opts .open ~= false then
731
+ if opts .open == true or ( opts . open == nil and tally [ 1 ] > 0 ) then
790
732
qf .open (list , true , true )
791
733
end
792
734
end
793
735
794
736
--- Suffix the chosen list with a summary of the classified number of entries
795
- function qf .tally (list , title )
737
+ --- @param list string
738
+ --- @param title string | nil
739
+ --- @param tally integer[] | nil
740
+ function qf .tally (list , title , tally )
796
741
list = fix_list (list )
797
742
743
+ local info = get_list (list , { title = 1 , id = 0 })
744
+
798
745
if title == nil then
799
- title = get_list ( list , { title = 1 }) .title
746
+ title = info .title
800
747
end
801
748
802
- local s = title : match ( " [^%-]* " ) .. util .tally (list )
749
+ tally = tally or util .tally (list )
803
750
804
- set_list (list , {}, " r" , { title = s })
751
+ local d = require (" qf" ).config .signs
752
+ d = {
753
+ d .E ,
754
+ d .W ,
755
+ d .I ,
756
+ d .N ,
757
+ d .T ,
758
+ }
759
+
760
+ local total_count = 0
761
+ local t = {}
762
+ for i , v in ipairs (tally ) do
763
+ if v > 0 then
764
+ total_count = total_count + 1
765
+ local severity = d [i ]
766
+ t [# t + 1 ] = " %#" .. severity .hl .. " #" .. severity .sign .. " " .. v
767
+ end
768
+ end
769
+
770
+ local tally_str = " - " .. table.concat (t , " " ) .. " %#Normal#"
771
+
772
+ if total_count > 0 then
773
+ local s = title :match (" [^%-]*%s?" ) .. tally_str
774
+
775
+ set_list (list , {}, " r" , { title = s })
776
+ end
805
777
end
806
778
807
779
function qf .filter_text (list , pat )
@@ -880,7 +852,7 @@ function qf.setup_autocmds(config)
880
852
for k , list in pairs ({ c = config .c , l = config .l }) do
881
853
if list .auto_follow then
882
854
au (list .follow_slow and " CursorHold" or " CursorMoved" , function ()
883
- follow (k , list .auto_follow , true )
855
+ follow (k , list .auto_follow , 16 )
884
856
end )
885
857
end
886
858
0 commit comments