Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lsp_jump_type): jump type can be passed as a function #2959

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Blackmorse
Copy link

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

  • Opening while many references has been found is working as before
  • 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:

  • My code follows the style guidelines of this project (stylua)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (lua annotations)

@jamestrew
Copy link
Contributor

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.

@Blackmorse
Copy link
Author

@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

@Blackmorse
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants