changes
This commit is contained in:
@@ -102,5 +102,7 @@ return {
|
||||
vim.keymap.set('n', 'H', '<cmd>ClangdSwitchSourceHeader<cr>', { desc = '[H]eader and Source Switcher' })
|
||||
vim.keymap.set('n', '<leader>e', JumpToNextError)
|
||||
vim.keymap.set('n', '<leader>E', JumpToPrevError)
|
||||
vim.keymap.set('n', '<leader>w', JumpToNextWarning)
|
||||
vim.keymap.set('n', '<leader>W', JumpToPrevWarning)
|
||||
end,
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
@@ -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' } },
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
(#any-of? @keyword
|
||||
"kr_proc" "inlined"
|
||||
"u8" "u16" "u32" "u64"
|
||||
"i8" "i16" "i32" "i64"
|
||||
"i8" "i16" "i32" "i64" "i128"
|
||||
"f32" "f64"
|
||||
"b8" "b32" "b64"
|
||||
"rune" "usize" "isize" "uptr" "iptr"
|
||||
|
||||
Reference in New Issue
Block a user