mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
feat(diagnostic): add on_jump
callback option
This commit is contained in:
@@ -21,7 +21,7 @@ API
|
|||||||
|
|
||||||
DIAGNOSTICS
|
DIAGNOSTICS
|
||||||
|
|
||||||
• todo
|
• "float" in |vim.diagnostic.JumpOpts|. Use "on_jump" instead.
|
||||||
|
|
||||||
HIGHLIGHTS
|
HIGHLIGHTS
|
||||||
|
|
||||||
|
@@ -465,13 +465,9 @@ Lua module: vim.diagnostic *diagnostic-api*
|
|||||||
file or not. Similar to 'wrapscan'.
|
file or not. Similar to 'wrapscan'.
|
||||||
• {severity}? (`vim.diagnostic.SeverityFilter`) See
|
• {severity}? (`vim.diagnostic.SeverityFilter`) See
|
||||||
|diagnostic-severity|.
|
|diagnostic-severity|.
|
||||||
• {float}? (`boolean|vim.diagnostic.Opts.Float`, default: `false`)
|
• {on_jump}? (`fun(diagnostic:vim.Diagnostic?, bufnr:integer)`)
|
||||||
If `true`, call |vim.diagnostic.open_float()| after
|
Optional callback invoked with the diagnostic that was
|
||||||
moving. If a table, pass the table as the {opts}
|
jumped to.
|
||||||
parameter to |vim.diagnostic.open_float()|. Unless
|
|
||||||
overridden, the float will show diagnostics at the new
|
|
||||||
cursor position (as if "cursor" were passed to the
|
|
||||||
"scope" option).
|
|
||||||
• {winid}? (`integer`, default: `0`) Window ID
|
• {winid}? (`integer`, default: `0`) Window ID
|
||||||
|
|
||||||
*vim.diagnostic.NS*
|
*vim.diagnostic.NS*
|
||||||
|
@@ -1075,15 +1075,25 @@ local function goto_diagnostic(diagnostic, opts)
|
|||||||
vim.cmd('normal! zv')
|
vim.cmd('normal! zv')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local float_opts = opts.float
|
if opts.float then
|
||||||
if float_opts then
|
vim.deprecate('opts.float', 'opts.on_jump', '0.14')
|
||||||
|
local float_opts = opts.float ---@type table|boolean
|
||||||
float_opts = type(float_opts) == 'table' and float_opts or {}
|
float_opts = type(float_opts) == 'table' and float_opts or {}
|
||||||
vim.schedule(function()
|
|
||||||
|
opts.on_jump = function(_, bufnr)
|
||||||
M.open_float(vim.tbl_extend('keep', float_opts, {
|
M.open_float(vim.tbl_extend('keep', float_opts, {
|
||||||
bufnr = api.nvim_win_get_buf(winid),
|
bufnr = bufnr,
|
||||||
scope = 'cursor',
|
scope = 'cursor',
|
||||||
focus = false,
|
focus = false,
|
||||||
}))
|
}))
|
||||||
|
end
|
||||||
|
|
||||||
|
opts.float = nil ---@diagnostic disable-line
|
||||||
|
end
|
||||||
|
|
||||||
|
if opts.on_jump then
|
||||||
|
vim.schedule(function()
|
||||||
|
opts.on_jump(diagnostic, api.nvim_win_get_buf(winid))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -1287,7 +1297,9 @@ end
|
|||||||
function M.goto_prev(opts)
|
function M.goto_prev(opts)
|
||||||
vim.deprecate('vim.diagnostic.goto_prev()', 'vim.diagnostic.jump()', '0.13')
|
vim.deprecate('vim.diagnostic.goto_prev()', 'vim.diagnostic.jump()', '0.13')
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
opts.float = if_nil(opts.float, true)
|
|
||||||
|
opts.float = if_nil(opts.float, true) ---@diagnostic disable-line
|
||||||
|
|
||||||
goto_diagnostic(M.get_prev(opts), opts)
|
goto_diagnostic(M.get_prev(opts), opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1360,12 +1372,8 @@ end
|
|||||||
--- (default: `false`)
|
--- (default: `false`)
|
||||||
--- @field package _highest? boolean
|
--- @field package _highest? boolean
|
||||||
---
|
---
|
||||||
--- If `true`, call |vim.diagnostic.open_float()| after moving.
|
--- Optional callback invoked with the diagnostic that was jumped to.
|
||||||
--- If a table, pass the table as the {opts} parameter to |vim.diagnostic.open_float()|.
|
--- @field on_jump? fun(diagnostic:vim.Diagnostic?, bufnr:integer)
|
||||||
--- Unless overridden, the float will show diagnostics at the new cursor
|
|
||||||
--- position (as if "cursor" were passed to the "scope" option).
|
|
||||||
--- (default: `false`)
|
|
||||||
--- @field float? boolean|vim.diagnostic.Opts.Float
|
|
||||||
---
|
---
|
||||||
--- Window ID
|
--- Window ID
|
||||||
--- (default: `0`)
|
--- (default: `0`)
|
||||||
@@ -1434,7 +1442,7 @@ end
|
|||||||
function M.goto_next(opts)
|
function M.goto_next(opts)
|
||||||
vim.deprecate('vim.diagnostic.goto_next()', 'vim.diagnostic.jump()', '0.13')
|
vim.deprecate('vim.diagnostic.goto_next()', 'vim.diagnostic.jump()', '0.13')
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
opts.float = if_nil(opts.float, true)
|
opts.float = if_nil(opts.float, true) ---@diagnostic disable-line
|
||||||
goto_diagnostic(M.get_next(opts), opts)
|
goto_diagnostic(M.get_next(opts), opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@ -7,6 +7,7 @@ local exec_lua = n.exec_lua
|
|||||||
local eq = t.eq
|
local eq = t.eq
|
||||||
local neq = t.neq
|
local neq = t.neq
|
||||||
local matches = t.matches
|
local matches = t.matches
|
||||||
|
local retry = t.retry
|
||||||
local api = n.api
|
local api = n.api
|
||||||
local pcall_err = t.pcall_err
|
local pcall_err = t.pcall_err
|
||||||
local fn = n.fn
|
local fn = n.fn
|
||||||
@@ -1094,7 +1095,7 @@ describe('vim.diagnostic', function()
|
|||||||
})
|
})
|
||||||
vim.api.nvim_win_set_buf(0, _G.diagnostic_bufnr)
|
vim.api.nvim_win_set_buf(0, _G.diagnostic_bufnr)
|
||||||
vim.api.nvim_win_set_cursor(0, { 1, 1 })
|
vim.api.nvim_win_set_cursor(0, { 1, 1 })
|
||||||
vim.diagnostic.jump({ count = 1, float = false })
|
vim.diagnostic.jump({ count = 1 })
|
||||||
local next = vim.diagnostic.get_next({ namespace = _G.diagnostic_ns })
|
local next = vim.diagnostic.get_next({ namespace = _G.diagnostic_ns })
|
||||||
return { next.lnum, next.col }
|
return { next.lnum, next.col }
|
||||||
end)
|
end)
|
||||||
@@ -1111,7 +1112,7 @@ describe('vim.diagnostic', function()
|
|||||||
})
|
})
|
||||||
vim.api.nvim_win_set_buf(0, _G.diagnostic_bufnr)
|
vim.api.nvim_win_set_buf(0, _G.diagnostic_bufnr)
|
||||||
vim.api.nvim_win_set_cursor(0, { 1, 1 })
|
vim.api.nvim_win_set_cursor(0, { 1, 1 })
|
||||||
vim.diagnostic.jump({ count = 1, float = false })
|
vim.diagnostic.jump({ count = 1 })
|
||||||
local next = vim.diagnostic.get_next({ namespace = _G.diagnostic_ns })
|
local next = vim.diagnostic.get_next({ namespace = _G.diagnostic_ns })
|
||||||
return { next.lnum, next.col }
|
return { next.lnum, next.col }
|
||||||
end)
|
end)
|
||||||
@@ -1412,6 +1413,23 @@ describe('vim.diagnostic', function()
|
|||||||
end)
|
end)
|
||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('supports on_jump() handler', function()
|
||||||
|
exec_lua(function()
|
||||||
|
_G.jumped = false
|
||||||
|
|
||||||
|
vim.diagnostic.jump({
|
||||||
|
count = 1,
|
||||||
|
on_jump = function()
|
||||||
|
_G.jumped = true
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end)
|
||||||
|
|
||||||
|
retry(nil, nil, function()
|
||||||
|
eq(true, exec_lua('return _G.jumped'))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('get()', function()
|
describe('get()', function()
|
||||||
|
Reference in New Issue
Block a user