From 570e62d0f99dbc99e4f506ad1b874bb1842159d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maria=20Jos=C3=A9=20Solano?= Date: Tue, 13 May 2025 21:39:05 -0500 Subject: [PATCH] docs(diagnostic): add `on_jump` example (#33933) --- runtime/doc/diagnostic.txt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/runtime/doc/diagnostic.txt b/runtime/doc/diagnostic.txt index f59510bea5..cfee7a829e 100644 --- a/runtime/doc/diagnostic.txt +++ b/runtime/doc/diagnostic.txt @@ -180,6 +180,28 @@ the `virtual_lines` handler with the following keymap: >lua end, { desc = 'Toggle diagnostic virtual_lines' }) < + *diagnostic-on-jump-example* +You can use the `on_jump` option from |vim.diagnostic.jump()| to show the +diagnostic that was jumped to using a specific handler. For example, the +following uses the `virtual_lines` handler when jumping to a diagnostic: >lua + + local virt_lines_ns = vim.api.nvim_create_namespace 'on_diagnostic_jump' + + --- @param diagnostic? vim.Diagnostic + --- @param bufnr integer + local function on_jump(diagnostic, bufnr) + if not diagnostic then return end + + vim.diagnostic.show( + virt_lines_ns, + bufnr, + { diagnostic }, + { virtual_lines = { current_line = true }, virtual_text = false } + ) + end + + vim.diagnostic.config({ jump = { on_jump = on_jump } }) + *diagnostic-loclist-example* Whenever the |location-list| is opened, the following `show` handler will show the most recent diagnostics: >lua