mirror of
https://github.com/neovim/neovim.git
synced 2025-10-13 21:36:05 +00:00
fix(lsp): opts.reuse_win does not jump if buf is already open #33476
Problem:
`vim.lsp.buf.[implementation|definition|...]({ reuse_win = true })` does not
jump cursor to existing window if buffer is already open.
Steps to reproduce:
1. `nvim repro.lua`
2. Insert anything that lsp can read to open the library definition/implementation, e.g., `vim.keymap.set`
3. open `repro.lua` buffer and the library buffer side by side.
4. type `gd` over `set` to jump to the library definition.
The open buffer is scrolled to the target line, but cursor does not jump.
Solution:
Call nvim_set_current_win if necessary.
(cherry picked from commit 6926fc1615
)
This commit is contained in:
@@ -215,7 +215,13 @@ local function get_locations(method, opts)
|
||||
vim.fn.settagstack(vim.fn.win_getid(win), { items = tagstack }, 't')
|
||||
|
||||
vim.bo[b].buflisted = true
|
||||
local w = opts.reuse_win and vim.fn.win_findbuf(b)[1] or win
|
||||
local w = win
|
||||
if opts.reuse_win then
|
||||
w = vim.fn.win_findbuf(b)[1] or w
|
||||
if w ~= win then
|
||||
api.nvim_set_current_win(w)
|
||||
end
|
||||
end
|
||||
api.nvim_win_set_buf(w, b)
|
||||
api.nvim_win_set_cursor(w, { item.lnum, item.col - 1 })
|
||||
vim._with({ win = w }, function()
|
||||
|
Reference in New Issue
Block a user