Skip to content

Conversation

Blackmorse
Copy link

Description

When calling LSP-Telescope functions (lsp_definitions, lsp_references, etc.), users may want to customize how the target buffer opens.

Currently:

  • With multiple results, customization is possible using the get_selection_window option:
require('telescope.builtin').lsp_definitions({
  get_selection_window = function() ... end,
})
  • With a single result, Telescope bypasses the picker and relies on jump_type, which only accepts string values (tab, tab drop, split, vsplit, never).
  • This makes customization in the single-result case very limited.

This PR extends jump_type to also accept a function.
When a function is provided, it will be executed instead of the predefined commands, giving users the same level of flexibility as in the multi-result case.

Example use case

I want to choose the exact window in which a reference is opened when navigating with lsp_definitions.

Today: I can do this with a window-picker when multiple definitions are found.
Limitation: When only one definition is found, I have no such option.

With this PR, I can achieve it like so:

require('telescope.builtin').lsp_definitions(
    {
      get_selection_window = function()
        return require('window-picker').pick_window({ include_current_win = true });
      end,
      jump_type = function ()
        local window = require('window-picker').pick_window({ include_current_win = true, reuse_win = false });
        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?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list relevant details about your configuration

  • Manually tested with the configuration shown above.
  • Verified that behavior with multiple references remains unchanged
  • Verified that with a single reference, the provided function is executed (e.g. window-picker is triggered) and the reference opens in the selected window

Configuration:

  • Neovim version (nvim --version): 0.11.2
  • Operating system and version: MacOS

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)

@Blackmorse
Copy link
Author

Hi @jamestrew,

This is the second time I’m submitting this change, but I haven’t received any feedback yet. This feature is quite important for my workflow - I even maintain a personal fork of Telescope just to use it, and some of my own plugins depend on it.

However, I believe this feature is generic enough to benefit the wider community. I’d really appreciate any feedback or suggestions on this PR. I’m more than willing to make improvements or rework it as needed. If the decision is to reject it, I’d also appreciate understanding the reasoning behind that choice.

Thank you!

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.

1 participant