feat(lsp_jump_type): jump type can be passed as a function
Description
For builtin LSP actions, there is a parameter called jump_type, which allows choosing how goto_reference will be executed when only one entity is found in another file: "tab", "tab drop", "split", "vsplit", "never".
In this PR, I've added the ability to pass a function as the jump_type parameter. This function will be executed instead of using the predefined commands.
Motivation:
I have the following use case: I want to have the ability to choose the window in which a reference will be opened when navigating to it via lsp_definitions. Currently, when multiple definitions are found, I can achieve this by using a window-picker after opening the telescope. However, when only one definition is found, I don't have this option.
With this PR, I'll be able to solve my problem by using the following invocation:
require('telescope.builtin').lsp_definitions(
{
get_selection_window = function()
local window = require('window-picker').pick_window({ include_current_win = true });
return window
end,
jump_type = function ()
local window = require('window-picker').pick_window({ include_current_win = true });
vim.api.nvim_set_current_win(window)
end
})
Type of change
- New feature (non-breaking change which adds functionality)
- This change requires a documentation update
How Has This Been Tested?
Thoroughly tested manually with aforementioned config
- [x] Opening while many references has been found is working as before
- [x] Opening while one reference has been found execution window-picker and then opening reference it selected window
Configuration:
- Neovim version (nvim --version):
nvim --version
NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1703358377
- Operating system and version: MacOS Monterey 12.6.8
Checklist:
- [x] My code follows the style guidelines of this project (stylua)
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation (lua annotations)
I'm thinking it might be easier to just repurpose the get_selection_window option. One caveat would be that the picker and entry params would be nil but I'm not sure how common it even is to use those params.
@jamestrew , indeed, repurposing get_selection_window option will be nice solution. However, we can't rely on fact that picker and entry params are not widely used - they could be used by someone and 'repurposing' will break their code.
In fact it is two different features and I suggest to keep them as a separate features
Hi @jamestrew,
It's been a while. Could you merge this, or do you have any suggestions for alternatives to them implemetation of this feature? I find this addition essential for my coding patterns, so it would be great to finalize this request.
Thanks!
@jamestrew , any thoughts?