docs(lsp): document on_list deduplication #39941

Problem:
Deduplicating LSP locations in the default handler changes list behavior for every user, while some configurations may intentionally return matching locations from multiple clients.

Solution:
Document how users can deduplicate locations in an on_list handler with vim.list.unique().

Co-authored-by: Deepak kudi <deepakkudi23@adsl-172-10-9-116.dsl.sndg02.sbcglobal.net>
Co-authored-by: Puneet Dixit <236133619+puneetdixit200@users.noreply.github.com>
This commit is contained in:
Puneet Dixit
2026-05-27 19:51:45 +05:30
committed by GitHub
parent cad5a4cf5c
commit 5acb2a1d33
2 changed files with 41 additions and 0 deletions

View File

@@ -332,6 +332,26 @@ end
--- vim.lsp.buf.definition({ on_list = on_list })
--- vim.lsp.buf.references(nil, { on_list = on_list })
--- ```
--- The list can be transformed before it is shown. For example, to remove
--- duplicate locations returned by multiple clients:
--- ```lua
--- local function on_list(what)
--- vim.list.unique(what.items, function(item)
--- return ('%s\0%d\0%d\0%d\0%d'):format(
--- item.filename or '',
--- item.lnum or 0,
--- item.col or 0,
--- item.end_lnum or 0,
--- item.end_col or 0
--- )
--- end)
--- vim.fn.setqflist({}, ' ', what)
--- vim.cmd('botright copen')
--- end
---
--- vim.lsp.buf.definition({ on_list = on_list })
--- vim.lsp.buf.references(nil, { on_list = on_list })
--- ```
--- See |setqflist-what| for the structure of the `what` parameter.
--- @field on_list? fun(what: vim.fn.setqflist.what)
---