improve jump to next diagnostic

master
ray-x 4 weeks ago
parent d3c7e03113
commit fd1f7e9a3d

@ -516,14 +516,14 @@ In `playground` folder, there is a `init.lua` and source code for you to play wi
| n | \<Leader\>re | rename (lsp default) |
| n | \<Leader\>gi | hierarchy incoming calls |
| n | \<Leader\>go | hierarchy outgoing calls |
| n | \<Space\>ff | format buffer (LSP)
| v | \<Space\>ff | format selection range (LSP)
| n | \<Space\>ff | format buffer (LSP) |
| v | \<Space\>ff | format selection range (LSP) |
| n | gi | implementation |
| n | \<Space\> D | type definition |
| n | gL | show line diagnostic |
| n | gG | show diagnostic for all buffers |
| n | ]d | next diagnostic |
| n | [d | previous diagnostic |
| n | ]d | next diagnostic error or fallback |
| n | [d | previous diagnostic error or fallback |
| n | \<Leader\> dt | diagnostic toggle(enable/disable) |
| n | ]r | next treesitter reference/usage |
| n | [r | previous treesitter reference/usage |

@ -210,7 +210,7 @@ _NgConfigValues = {
},
fold = {
prefix = '',
separator = '',
separator = '',
},
-- Treesitter

@ -335,15 +335,39 @@ local function diag_signs()
break
end
end
if vim.tbl_isempty(t) or (t[1] and t[1].text and t[1].text:find('W')) and signs_valid == true then
if
vim.tbl_isempty(t) or (t[1] and t[1].text and t[1].text:find('W')) and signs_valid == true
then
log('set signs ', text)
return {
return {
text = text,
}
end
end
end
-- goto next Error if none found, go to first
function M.goto_next(opts)
opts = opts or {}
local bufnr = api.nvim_get_current_buf()
local diags = diagnostic.get(bufnr, { severity = vim.diagnostic.severity.ERROR })
if diags and #diags > 0 then
opts.severity = vim.diagnostic.severity.ERROR
return diagnostic.goto_next(opts)
end
diagnostic.goto_next(opts)
end
function M.goto_prev(opts)
opts = opts or {}
local bufnr = api.nvim_get_current_buf()
local diags = diagnostic.get(bufnr, { severity = vim.diagnostic.severity.ERROR })
if diags and #diags > 0 then
opts.severity = vim.diagnostic.severity.ERROR
return diagnostic.goto_prev(opts)
end
diagnostic.goto_prev(opts)
end
-- local diag_hdlr_async = function()
-- local debounce = require('navigator.debounce').debounce_trailing
-- return debounce(100, diag_hdlr)
@ -521,9 +545,12 @@ function M.get_line_diagnostic()
local lnum = api.nvim_win_get_cursor(0)[1] - 1
local diags = diagnostic.get(api.nvim_get_current_buf(), { lnum = lnum })
table.sort(diags, function(diag1, diag2)
return diag1.severity or 0 < diag2.severity or 0
end)
local l = 0
local cmp = function(d1, d2)
return d1.severity < d2.severity
end
table.sort(diags, cmp)
return diags
end
@ -548,6 +575,18 @@ function M.show_diagnostics(pos)
if diags == nil or next(diags) == nil then
return
end
-- if there is diagnostic at cursor position, show only that diagnostic
local line_length = #api.nvim_buf_get_lines(bufnr, lnum, lnum + 1, true)[1]
local diags_cursor = vim.tbl_filter(function(d)
return d.lnum == lnum
and math.min(d.col, line_length - 1) <= col
and (d.end_col >= col or d.end_lnum > lnum)
end, diags)
if #diags_cursor > 0 then
opt.scope = 'cursor'
diags = diags_cursor
end
local diag1 = diags[1]
opt.offset_x = -1 * (col - diag1.col)
diagnostic.open_float(bufnr, opt)

@ -132,11 +132,12 @@ function NG_custom_fold_text()
spaces[2] = { '@keyword' }
end
end
local sep2 = ' ' .. string.rep(sep, 3) .. ' '
table.insert(line_syntax, { sep2, { '@comment' } })
local sep2 = ' ' .. string.rep(sep, 1) .. ' '
table.insert(line_syntax, { '', { '@tag' } })
table.insert(line_syntax, { sep2, { '@tag' } })
table.insert(line_syntax, { tostring(line_count), { '@number' } })
table.insert(line_syntax, { ' lines', { '@text.title' } })
table.insert(line_syntax, { sep2, { '@comment' } })
table.insert(line_syntax, { sep2, { '@tag' } })
return line_syntax
end

@ -56,8 +56,8 @@ local key_maps = {
{ key = 'gL', func = require('navigator.diagnostics').show_diagnostics, desc = 'show_diagnostics' },
{ key = 'gG', func = require('navigator.diagnostics').show_buf_diagnostics, desc = 'show_buf_diagnostics' },
{ key = '<Leader>dt', func = require('navigator.diagnostics').toggle_diagnostics, desc = 'toggle_diagnostics' },
{ key = ']d', func = vim.diagnostic.goto_next, desc = 'next diagnostics' },
{ key = '[d', func = vim.diagnostic.goto_prev, desc = 'prev diagnostics' },
{ key = ']d', func = require('navigator.diagnostics').goto_next, desc = 'next diagnostics error or fallback' },
{ key = '[d', func = require('navigator.diagnostics').goto_prev, desc = 'prev diagnostics error or fallback' },
{ key = ']O', func = vim.diagnostic.set_loclist, desc = 'diagnostics set loclist' },
{ key = ']r', func = require('navigator.treesitter').goto_next_usage, desc = 'goto_next_usage' },
{ key = '[r', func = require('navigator.treesitter').goto_previous_usage, desc = 'goto_previous_usage' },

Loading…
Cancel
Save