From f9c67c40bcb38bc0f7738c858eb038aa2f1f1697 Mon Sep 17 00:00:00 2001 From: Maria Solano Date: Sun, 1 Feb 2026 04:18:16 -0800 Subject: [PATCH] fix(lsp): call `on_list` before reading `loclist` #37645 Problem: `on_list` is supposed to replace the default list-handler. With the current order of these `if` statements `on_list` won't be called if `loclist` is true. Solution: Change the order of the relevant blocks. (cherry picked from commit 0501c5fd0959895b18d8166c6c034cdf1832edf3) --- runtime/lua/vim/lsp/buf.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua index ae83a516e8..6cc7dfee91 100644 --- a/runtime/lua/vim/lsp/buf.lua +++ b/runtime/lua/vim/lsp/buf.lua @@ -789,12 +789,12 @@ function M.references(context, opts) bufnr = bufnr, }, } - if opts.loclist then - vim.fn.setloclist(0, {}, ' ', list) - vim.cmd.lopen() - elseif opts.on_list then + if opts.on_list then assert(vim.is_callable(opts.on_list), 'on_list is not a function') opts.on_list(list) + elseif opts.loclist then + vim.fn.setloclist(0, {}, ' ', list) + vim.cmd.lopen() else vim.fn.setqflist({}, ' ', list) vim.cmd('botright copen')