@@ -6,16 +6,15 @@ local M = {}
66
77function M .get_next_loc ()
88 M .location = api .nvim_call_function (' getloclist' , {0 })
9- if # M .location = = 0 then
9+ if # M .location < = 0 then
1010 return - 1
11- elseif # M .location == 1 then
12- return 1
1311 end
1412
1513 local cur_row = api .nvim_call_function (' line' , {" ." })
1614 local cur_col = api .nvim_call_function (' col' , {" ." })
15+
1716 for i , v in ipairs (M .location ) do
18- if v [' lnum' ] > cur_row or (v [' lnum' ] == cur_row and v [' col' ] > cur_col ) then
17+ if v [' lnum' ] > cur_row or (v [' lnum' ] == cur_row and v [' col' ] > cur_col + 1 ) then
1918 return i
2019 end
2120 end
@@ -26,19 +25,22 @@ function M.get_prev_loc()
2625 M .location = api .nvim_call_function (' getloclist' , {0 })
2726 if # M .location == 0 then
2827 return - 1
29- elseif # M .location == 1 then
30- return 1
3128 end
3229
3330 local cur_row = api .nvim_call_function (' line' , {" ." })
3431 local cur_col = api .nvim_call_function (' col' , {" ." })
32+
3533 for i , v in ipairs (M .location ) do
36- if v [' lnum' ] > cur_row or (v [' lnum' ] == cur_row and v [' col' ] > cur_col ) then
37- return i
38- elseif v [' lnum' ] == cur_row and v [' col' ] == cur_col then
34+ local is_next = v [' lnum' ] > cur_row or (v [' lnum' ] == cur_row and v [' col' ] > cur_col );
35+ local is_prev = v [' lnum' ] == cur_row and cur_col > v [' col' ];
36+ local same_pos = v [' lnum' ] == cur_row and v [' col' ] == cur_col ;
37+ if is_next or same_pos then
3938 return i - 1
39+ elseif is_prev then
40+ return i
4041 end
4142 end
43+
4244 return - 1
4345end
4446
5355-- Show warning text when no next location is available
5456function M .jumpNextLocation ()
5557 local i = M .get_next_loc ()
56- if i >= 0 then
58+ if i >= 1 then
5759 jumpToLocation (i )
5860 else
5961 api .nvim_command (" echohl WarningMsg | echo 'no next diagnostic' | echohl None" )
6264
6365function M .jumpPrevLocation ()
6466 local i = M .get_prev_loc ()
65- if i >= 0 then
67+ if i >= 1 then
6668 jumpToLocation (i )
6769 else
6870 api .nvim_command (" echohl WarningMsg | echo 'no prev diagnostic' | echohl None" )
7173
7274function M .jumpNextLocationCycle ()
7375 local next_i = M .get_next_loc ()
74- if next_i > - 1 then
76+ if next_i > 0 then
7577 jumpToLocation (next_i )
7678 elseif M .get_prev_loc () >= 0 then
7779 jumpToLocation (1 )
7880 else
79- return api .nvim_command (" echohl WarningMsg | echo 'no next diagnostic ' | echohl None" )
81+ return api .nvim_command (" echohl WarningMsg | echo 'No diagnostics found ' | echohl None" )
8082 end
8183end
8284
0 commit comments