fix(lsp): call show_document with correct args

Closes https://github.com/neovim/neovim/issues/21177
This commit is contained in:
Mathias Fussenegger 2022-12-04 15:57:46 +01:00
parent 48b84d6d6e
commit 67e1390dc8
2 changed files with 31 additions and 1 deletions

View File

@ -579,7 +579,10 @@ M['window/showDocument'] = function(_, result, ctx, _)
range = result.selection,
}
local success = util.show_document(location, client.offset_encoding, true, result.takeFocus)
local success = util.show_document(location, client.offset_encoding, {
reuse_win = true,
focus = result.takeFocus,
})
return { success = success or false }
end

View File

@ -2689,6 +2689,33 @@ describe('LSP', function()
eq(10, pos.col)
end)
it('jumps to a Location if focus is true via handler', function()
exec_lua(create_server_definition)
local result = exec_lua([[
local server = _create_server()
local client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd })
local result = {
uri = 'file:///fake/uri',
selection = {
start = { line = 0, character = 9 },
['end'] = { line = 0, character = 9 }
},
takeFocus = true,
}
local ctx = {
client_id = client_id,
method = 'window/showDocument',
}
vim.lsp.handlers['window/showDocument'](nil, result, ctx)
vim.lsp.stop_client(client_id)
return {
cursor = vim.api.nvim_win_get_cursor(0)
}
]])
eq(1, result.cursor[1])
eq(9, result.cursor[2])
end)
it('jumps to a Location if focus not set', function()
local pos = show_document(location(0, 9, 0, 9), nil, true)
eq(1, pos.line)