camspiers / snap

A fast finder system for neovim.
The Unlicense
490 stars 17 forks source link

How to make snap fall back to file searching from a git search? #26

Closed bangedorrunt closed 3 years ago

bangedorrunt commented 3 years ago

Hi, I'm wondering if it is possible to make snap automatically fall back to file searching if the working dir is not git project.

camspiers commented 3 years ago

That is a good question, I think it should be fairly simple to introduce two new consumers, one a combination consumer and the other a conditional consumer:

combine(producer1, producer2)

And:

try(producer1, producer2)

"combine" would just combine the results of two or more producers, and "try" would use the first, then if no results occur will try the second, and then the third if provided etc.

Thanks for the ideas!

camspiers commented 3 years ago

Resolved in https://github.com/camspiers/snap/commit/e19696700a6188cc145ba587de131195d1731fc8

You can now do something like:

snap.run {
  producer = snap.get'consumer.fzf'(
    snap.get'consumer.try'(
      snap.get'producer.git.file',
      snap.get'producer.ripgrep.file'
    ),
  ),
  select = snap.get'select.file'.select,
  multiselect = snap.get'select.file'.multiselect,
  views = {snap.get'preview.file'}
}
camspiers commented 3 years ago

I hope this example also helps to illustrate the flexibility of the producer consumer pattern.

bangedorrunt commented 3 years ago

Wow, that's great. I really like the try and combine idea. Cheers!