Skip to content
This repository was archived by the owner on Jul 6, 2021. It is now read-only.

Commit 3baf221

Browse files
committed
feat: Add FirstDiagnostic and LastDiagnostic(#22)
1 parent 25e1b4b commit 3baf221

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

lua/jumpLoc.lua

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function M.get_prev_loc()
4343
return #M.location
4444
end
4545

46-
function jumpToLocation(i)
46+
local function jumpToLocation(i)
4747
if i >= 1 and i <= #M.location then
4848
api.nvim_command("silent! ll"..i)
4949
M.openLineDiagnostics()
@@ -92,6 +92,22 @@ function M.jumpPrevLocationCycle()
9292
end
9393
end
9494

95+
function M.jumpFirstLocation()
96+
M.location = api.nvim_call_function('getloclist', {0})
97+
jumpToLocation(1)
98+
if #M.location == 0 then
99+
return api.nvim_command("echohl WarningMsg | echo 'No diagnostics found' | echohl None")
100+
end
101+
end
102+
103+
function M.jumpLastLocation()
104+
M.location = api.nvim_call_function('getloclist', {0})
105+
jumpToLocation(#M.location)
106+
if #M.location == 0 then
107+
return api.nvim_command("echohl WarningMsg | echo 'No diagnostics found' | echohl None")
108+
end
109+
end
110+
95111
-- Open line diagnostics when jump
96112
-- Don't do anything if diagnostic_auto_popup_while_jump == 0
97113
-- NOTE need to delay a certain amount of time to show correctly

plugin/diagnostic.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ command! PrevDiagnosticCycle lua require'jumpLoc'.jumpPrevLocationCycle()
88
command! NextDiagnostic lua require'jumpLoc'.jumpNextLocation()
99
command! NextDiagnosticCycle lua require'jumpLoc'.jumpNextLocationCycle()
1010
command! OpenDiagnostic lua require'jumpLoc'.openDiagnostics()
11+
command! FirstDiagnostic lua require'jumpLoc'.jumpFirstLocation()
12+
command! LastDiagnostic lua require'jumpLoc'.jumpLastLocation()
1113

1214
" lua require'diagnostic'.modifyCallback()
1315

0 commit comments

Comments
 (0)