aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeni Chasnovski <evgeni.chasnovski@gmail.com>2025-01-23 10:42:00 +0200
committerMathias Fußenegger <mfussenegger@users.noreply.github.com>2025-01-23 17:04:23 +0100
commita450fda4ededdd93e3dc571d82a6737f6b9d50d9 (patch)
treeac365a7a2082865e421f4151e9eadeb6fe7cb2e9
parent34d808b73cbcb0a43636d826282193ab1ca8c148 (diff)
downloadrneovim-a450fda4ededdd93e3dc571d82a6737f6b9d50d9.tar.gz
rneovim-a450fda4ededdd93e3dc571d82a6737f6b9d50d9.tar.bz2
rneovim-a450fda4ededdd93e3dc571d82a6737f6b9d50d9.zip
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.
-rw-r--r--runtime/doc/lsp.txt2
-rw-r--r--runtime/lua/vim/lsp/buf.lua2
-rw-r--r--runtime/lua/vim/lsp/handlers.lua8
3 files changed, 6 insertions, 6 deletions
diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt
index fffd668919..351f9a56ac 100644
--- a/runtime/doc/lsp.txt
+++ b/runtime/doc/lsp.txt
@@ -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 })
<
diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua
index 8efc6996dd..c57fdbee18 100644
--- a/runtime/lua/vim/lsp/buf.lua
+++ b/runtime/lua/vim/lsp/buf.lua
@@ -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 })
diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua
index 5da4033f89..a86ea99413 100644
--- a/runtime/lua/vim/lsp/handlers.lua
+++ b/runtime/lua/vim/lsp/handlers.lua
@@ -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')