summaryrefslogtreecommitdiff
path: root/.config/nvim/lua
diff options
context:
space:
mode:
authorKyren223 <contact@kyren.codes>2026-05-22 01:52:28 +0300
committerKyren223 <contact@kyren.codes>2026-05-22 01:52:28 +0300
commit11909289f9352d760d86c1e42793d44030d66ecb (patch)
treee99d6f5cf36986a52f2c9162283d8618adf97abf /.config/nvim/lua
parentdf6c13b25be321489925a06db023dcc5d9fef06f (diff)
changes
Diffstat (limited to '.config/nvim/lua')
-rw-r--r--.config/nvim/lua/extra.lua56
-rw-r--r--.config/nvim/lua/keymaps.lua4
2 files changed, 41 insertions, 19 deletions
diff --git a/.config/nvim/lua/extra.lua b/.config/nvim/lua/extra.lua
index ad8b6bd..ddf65ce 100644
--- a/.config/nvim/lua/extra.lua
+++ b/.config/nvim/lua/extra.lua
@@ -495,7 +495,7 @@ vim.keymap.set({ 'i', 'n', 'v' }, '<C-q>', '<cmd>CompileClose<cr><cmd>wqa<cr>')
-- NOTE: Jump to next error based on compile()
----------------------------------------------------------------------------
-function JumpToError(direction)
+function JumpToDiagnostic(direction, is_error, is_warning)
vim.defer_fn(function()
vim.cmd('w')
end, 10)
@@ -508,18 +508,20 @@ function JumpToError(direction)
return
end
- local error_parsers = {
+ local warning_parsers = {
function(line)
- -- Clang: ABS:LINE:COL: error: ...
- local file, lnum = line:match('^(.-):(%d+):%d+:%s+error:')
+ -- Clang: ABS:LINE:COL: warning: ...
+ local file, lnum = line:match('^(.-):(%d+):%d+:%s+warning:')
if file and lnum then
return { file = file, line = tonumber(lnum) }
end
end,
+ }
+ local error_parsers = {
function(line)
- -- Clang: ABS:LINE:COL: warning: ...
- local file, lnum = line:match('^(.-):(%d+):%d+:%s+warning:')
+ -- Clang: ABS:LINE:COL: error: ...
+ local file, lnum = line:match('^(.-):(%d+):%d+:%s+error:')
if file and lnum then
return { file = file, line = tonumber(lnum) }
end
@@ -550,26 +552,38 @@ function JumpToError(direction)
local lines = vim.api.nvim_buf_get_lines(BuildTerminalBuf, 0, -1, false)
-- vim.notify('Build buffer line count: ' .. #lines, 'warn')
- local errors = {}
+ local diagnostics = {}
for _, line in ipairs(lines) do
- for _, f in ipairs(error_parsers) do
- local err = f(line)
- if err then
- table.insert(errors, err)
- break
+ if is_warning then
+ for _, f in ipairs(warning_parsers) do
+ local warning = f(line)
+ if warning then
+ table.insert(diagnostics, warning)
+ break
+ end
+ end
+ end
+
+ if is_error then
+ for _, f in ipairs(error_parsers) do
+ local error = f(line)
+ if error then
+ table.insert(diagnostics, error)
+ break
+ end
end
end
end
- vim.notify('Error count: ' .. #errors, 'warn')
- if #errors == 0 then
+ -- vim.notify('Diagnostics count: ' .. #diagnostics, 'warn')
+ if #diagnostics == 0 then
return
end
local win = 0
local current_file = vim.api.nvim_buf_get_name(win)
local filtered = {}
- for _, e in ipairs(errors) do
+ for _, e in ipairs(diagnostics) do
if e.file == current_file then
table.insert(filtered, e)
end
@@ -615,11 +629,19 @@ function JumpToError(direction)
end
function JumpToNextError()
- return JumpToError(1)
+ return JumpToDiagnostic(1, true, false)
end
function JumpToPrevError()
- return JumpToError(-1)
+ return JumpToDiagnostic(-1, true, false)
+end
+
+function JumpToNextWarning()
+ return JumpToDiagnostic(1, true, true)
+end
+
+function JumpToPrevWarning()
+ return JumpToDiagnostic(-1, true, true)
end
----------------------------------------------------------------------------
diff --git a/.config/nvim/lua/keymaps.lua b/.config/nvim/lua/keymaps.lua
index 2ceec0b..f05ffc3 100644
--- a/.config/nvim/lua/keymaps.lua
+++ b/.config/nvim/lua/keymaps.lua
@@ -116,8 +116,8 @@ local keymaps = {
{ { 'n', 'i' }, '<M-Enter>', '<cmd>Lspsaga code_action<cr>', { desc = 'Code Actions' } },
-- { 'n', '<leader>e', next_diagnostic(severity.ERROR), { desc = 'Goto [E]rror' } },
-- { 'n', '<leader>E', prev_diagnostic(severity.ERROR), { desc = 'Goto [E]rror (prev)' } },
- { 'n', '<leader>w', next_diagnostic(severity.WARN), { desc = 'Goto [W]arning' } },
- { 'n', '<leader>W', prev_diagnostic(severity.WARN), { desc = 'Goto [W]arning (prev)' } },
+ -- { 'n', '<leader>w', next_diagnostic(severity.WARN), { desc = 'Goto [W]arning' } },
+ -- { 'n', '<leader>W', prev_diagnostic(severity.WARN), { desc = 'Goto [W]arning (prev)' } },
{ 'n', '<leader>D', cursor_diagnostics, { desc = '[D]iagnostics under cursor' } },
}