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

feature: allow different source in the current picker depending on the input #532

Open
1 task done
kristijanhusak opened this issue Jan 16, 2025 · 0 comments
Open
1 task done
Labels
enhancement New feature or request

Comments

@kristijanhusak
Copy link
Contributor

Did you check the docs?

  • I have read all the snacks.nvim docs

Is your feature request related to a problem? Please describe.

I'm aware this is a very complex feature, but I'll write it down in case you ever get to it.

Sublime text has this neat feature where you find files, and once you press @ it switches to "symbols" mode. For example, in snacks repo, doing preview@ would open up lua/snacks/picker/preview.lua in the background while picker is still visible, and start showing lsp symbols results in the same picker, which can also be fuzzy matched.
Here's a short recording:

sublime-file-symbol-picker.mp4

Describe the solution you'd like

I'd like to be able to create a custom picker that would achieve something similar, or ideally the same thing.

For starters, it would be good enough to be able to hook into something like on_prompt_change hook to get the input prompt value, and get the last "valid" item in a more graceful way.

Describe alternatives you've considered

Currently, I hacked this up, where it opens up the files picker, and once @ is typed, it closes the files picker with the last selected file, and opens up lsp_symbols picker.

    vim.keymap.set('n', '<C-p>', function()
      local should_open_symbols = false
      -- Last valid item selected. Once `@` is typed, current item in the `confirm` callback is no longer valid
      local last_item = nil
      local main_picker = Snacks.picker.files({
        on_change = function(_, item)
          if item then
            last_item = item
          end
        end,
        confirm = function(picker, item)
          if last_item and should_open_symbols then
            picker:close()
            vim.schedule(function()
              vim.cmd(('e %s'):format(last_item.cwd .. '/' .. last_item.file))
              Snacks.picker.lsp_symbols()
            end)
            return
          end
          vim.cmd(('e %s'):format(item.cwd .. '/' .. item.file))
        end,
      })

      local win = main_picker.input.win
      win:on(
        { 'TextChangedI' },
        Snacks.util.throttle(function()
          local line = win:line()
          if line:match('@$') then
            should_open_symbols = true
            main_picker:action('confirm')
            return
          end
        end, { ms = 30 })
      )
    end)

Additional context

No response

@kristijanhusak kristijanhusak added the enhancement New feature or request label Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant