feat(lsp): respect 'switchbuf' for jump commands, drop reuse_win #38510

Problem:
LSP jump operations such as `buf.definition`/`buf.type_definition` do
not follow the 'switchbuf' option. Instead their behavior is controlled
by `vim.lsp.LocationOpts.reuse_win`. When `reuse_win=true`, the effect
is very similar to `set switchbuf=useopen`.

Note that functions like `buf.definition` open the quickfix
window when there are multiple results, and jumping between quickfix
entries already follows 'switchbuf', so unifying the behavior is more
intuitive.

Solution:
Follow the 'switchbuf' option and drop `reuse_win`.

We can achieve this behavior by using :cfirst when the quickfix list has
only one item, rather than customizing the jump logic as before.
This commit is contained in:
Yi Ming
2026-03-30 22:54:55 +08:00
committed by GitHub
parent f062c6fd43
commit 57797ed7d4
4 changed files with 45 additions and 61 deletions

View File

@@ -5326,7 +5326,8 @@ describe('LSP', function()
n.feed(':vnew<CR>')
api.nvim_win_set_buf(0, result.bufnr)
api.nvim_win_set_cursor(0, { 3, 6 })
n.feed(':=vim.lsp.buf.definition({ reuse_win = true })<CR>')
n.feed(':set switchbuf=usetab<CR>')
n.feed(':=vim.lsp.buf.definition()<CR>')
eq(displayed_result_win, api.nvim_get_current_win())
exec_lua(function()
vim.lsp.get_client_by_id(result.client_id):stop()