fix(lsp): reuse_win prioritizes windows/tabs currently displayed #36486

Problem: reuse_win will always jump to the first window containing the
target buffer rather even if the buffer is displayed in the current
window/tab

Solution: check to see if the buffer is already displayed in the
current window or any window of the current buffer
This commit is contained in:
Toby She
2025-11-12 23:43:25 -05:00
committed by GitHub
parent 4143bcbd37
commit 4dd9137215
2 changed files with 8 additions and 3 deletions

View File

@@ -243,8 +243,9 @@ local function get_locations(method, opts)
vim.bo[b].buflisted = true
local w = win
if opts.reuse_win then
w = vim.fn.win_findbuf(b)[1] or w
if opts.reuse_win and api.nvim_win_get_buf(w) ~= b then
w = vim.fn.bufwinid(b)
w = w >= 0 and w or vim.fn.win_findbuf(b)[1] or win
if w ~= win then
api.nvim_set_current_win(w)
end