fix(lsp): prefer on_list over loclist in default handler

Problem: setting `loclist = true` makes `on_list` being ignored. This
  was not a problem before, but with `vim.lsp.buf.document_symbol` using
  `loclist = true` as default it is needed to explicitly pass `loclist =
  false` in order to use custom `on_list`.

Solution: prefer `on_list` over `loclist` and document the latter as
  taking effect only in the default handler.
This commit is contained in:
Evgeni Chasnovski 2025-01-23 10:42:00 +02:00 committed by Mathias Fußenegger
parent 34d808b73c
commit a450fda4ed
3 changed files with 6 additions and 6 deletions

View File

@ -1446,7 +1446,7 @@ Lua module: vim.lsp.buf *lsp-buf*
vim.lsp.buf.references(nil, { on_list = on_list })
<
• {loclist}? (`boolean`) Whether to use the |location-list| or the
|quickfix| list. >lua
|quickfix| list in the default handler. >lua
vim.lsp.buf.definition({ loclist = true })
vim.lsp.buf.references(nil, { loclist = false })
<

View File

@ -254,7 +254,7 @@ end
--- ```
--- @field on_list? fun(t: vim.lsp.LocationOpts.OnList)
---
--- Whether to use the |location-list| or the |quickfix| list.
--- Whether to use the |location-list| or the |quickfix| list in the default handler.
--- ```lua
--- vim.lsp.buf.definition({ loclist = true })
--- vim.lsp.buf.references(nil, { loclist = false })

View File

@ -247,12 +247,12 @@ local function response_to_list(map_result, entity, title_fn)
local items = map_result(result, ctx.bufnr)
local list = { title = title, items = items, context = ctx }
if config.loclist then
vim.fn.setloclist(0, {}, ' ', list)
vim.cmd.lopen()
elseif config.on_list then
if config.on_list then
assert(vim.is_callable(config.on_list), 'on_list is not a function')
config.on_list(list)
elseif config.loclist then
vim.fn.setloclist(0, {}, ' ', list)
vim.cmd.lopen()
else
vim.fn.setqflist({}, ' ', list)
vim.cmd('botright copen')