From 3baf22173a0c45041ff30707c8d1c955ebf2a2b0 Mon Sep 17 00:00:00 2001 From: haorenW1025 Date: Tue, 26 May 2020 04:03:37 +0000 Subject: [PATCH] feat: Add FirstDiagnostic and LastDiagnostic(#22) --- lua/jumpLoc.lua | 18 +++++++++++++++++- plugin/diagnostic.vim | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lua/jumpLoc.lua b/lua/jumpLoc.lua index 1be61fa..7fd6ff1 100644 --- a/lua/jumpLoc.lua +++ b/lua/jumpLoc.lua @@ -43,7 +43,7 @@ function M.get_prev_loc() return #M.location end -function jumpToLocation(i) +local function jumpToLocation(i) if i >= 1 and i <= #M.location then api.nvim_command("silent! ll"..i) M.openLineDiagnostics() @@ -92,6 +92,22 @@ function M.jumpPrevLocationCycle() end end +function M.jumpFirstLocation() + M.location = api.nvim_call_function('getloclist', {0}) + jumpToLocation(1) + if #M.location == 0 then + return api.nvim_command("echohl WarningMsg | echo 'No diagnostics found' | echohl None") + end +end + +function M.jumpLastLocation() + M.location = api.nvim_call_function('getloclist', {0}) + jumpToLocation(#M.location) + if #M.location == 0 then + return api.nvim_command("echohl WarningMsg | echo 'No diagnostics found' | echohl None") + end +end + -- Open line diagnostics when jump -- Don't do anything if diagnostic_auto_popup_while_jump == 0 -- NOTE need to delay a certain amount of time to show correctly diff --git a/plugin/diagnostic.vim b/plugin/diagnostic.vim index 68776b0..5555a94 100644 --- a/plugin/diagnostic.vim +++ b/plugin/diagnostic.vim @@ -8,6 +8,8 @@ command! PrevDiagnosticCycle lua require'jumpLoc'.jumpPrevLocationCycle() command! NextDiagnostic lua require'jumpLoc'.jumpNextLocation() command! NextDiagnosticCycle lua require'jumpLoc'.jumpNextLocationCycle() command! OpenDiagnostic lua require'jumpLoc'.openDiagnostics() +command! FirstDiagnostic lua require'jumpLoc'.jumpFirstLocation() +command! LastDiagnostic lua require'jumpLoc'.jumpLastLocation() " lua require'diagnostic'.modifyCallback()