carbon-steel / detour.nvim

Use popup windows to navigate files/buffer and to contain shells/TUIs
MIT License
153 stars 4 forks source link

Detour for code traversal #46

Closed lazymaniac closed 8 months ago

lazymaniac commented 8 months ago

Hey,

I would like to try use Detour for code traversal. Something similar to lspsaga peek definition or glance but as full window popup. Will it be possible to attach detour to lsp actions like goto definition/reference etc to display content of destination in popup?. It will be great if popup will have name of the location so it will be easy to check where I came from by looking at tops of the each nested popups. Absolutely awsesome feature would be option to go back to parent popups like in card deck.

carbon-steel commented 8 months ago

There is a feature in the dev branch that I've completed called ShowPathInTitle that does exactly what you're asking for. I'll later write some example code to show you how to use it.

carbon-steel commented 8 months ago

First, make sure to switch to the dev branch on the plugin (there should be some way to configure that on your package manager). Or, you could wait until I merge this feature into the main branch. I'll probably do it in a week or so.

image

local detour = require('detour')
local features = require('detour.features')
vim.keymap.set('n', '<c-w><enter>', function()
    local popup_id = detour.Detour()
    if popup_id then
        features.ShowPathInTitle(popup_id)
    end
end)

Try it out and let me know what you think :)

lazymaniac commented 8 months ago

Hey, I switched to dev branch and did something like this:

    {
      'gd',
      function()
        local popup_id = detour.Detour()
        if popup_id then
          require('telescope.builtin').lsp_definitions {} -- Open telescope prompt
          features.ShowPathInTitle(popup_id)
        end
      end,
      desc = 'Goto Definition <gd>',
      has = 'definition',
    },
    {
      'gr',
      function()
        local popup_id = detour.Detour()
        if popup_id then
          require('telescope.builtin').lsp_references { include_declaration = false, include_current_line = false }
          features.ShowPathInTitle(popup_id)
        end
      end,
      desc = 'Goto References <gr>',
    },
    {
      'gI',
      function()
        local popup_id = detour.Detour()
        if popup_id then
          require('telescope.builtin').lsp_implementations {}
          features.ShowPathInTitle(popup_id)
        end
      end,
      desc = 'Goto Implementation <gI>',
    },
    {
      'gD',
      function()
        local popup_id = detour.Detour()
        if popup_id then
          require('telescope.builtin').lsp_type_definitions {}
          features.ShowPathInTitle(popup_id)
        end
      end,
      desc = 'Goto Type Definition <gy>',
    },

Looks and works awesome! Thank you. I hope it will help me in understanding large code bases.

Zrzut ekranu 2024-02-08 202207

One more question if I may. Is there option to close all popups at once with a keymap or focus loss?

lazymaniac commented 8 months ago

Oh, nvm, I found how to close all popups at once