camspiers / snap

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

Search cached grep results #56

Open spywhere opened 3 years ago

spywhere commented 3 years ago

Is it possible to search a grep result using another consumer?

This setup is not quite working for me...

local snap = require('snap')
snap.run({
  producer = snap.get('consumer.fzf')(snap.get('consumer.cache')(snap.get('producer.vim.currentbuffer'))),
  select = snap.get('select.vimgrep').select,
  multiselect = snap.get('select.vimgrep').multiselect,
  views = { snap.get('preview.vimgrep') }
})

The flow is

  1. Snap will initiate the ripgrep command with no query (this would produce a large result of each line in each file)
  2. Cache it using the cache consumer
  3. Filtering it with FZF

Which in turn similar to just a ripgrep filtering, but it only run a ripgrep command once.

camspiers commented 3 years ago

It's documented I the README, search for steps.

camspiers commented 3 years ago

Subsequent configured steps can be activated using C-q. You might need to change the -M parameter via vimgrep args if you find not enough content for each line is being placed in the results buffer.

spywhere commented 3 years ago

This setup looks good to me...

snap.run {
  producer = snap.get'producer.ripgrep.vimgrep',
  steps = {{
    consumer = snap.get'consumer.fzf',
    config = {prompt = "FZF>"}
  }},
  select = snap.get'select.vimgrep'.select,
  multiselect = snap.get'select.vimgrep'.multiselect,
  views = {snap.get'preview.vimgrep'}
}

It working great if I did some filtering with ripgrep first. However, if I open up the ripgrep then C-q immediately, fzf is taking some time to do the processing, and even throwing some errors. Not sure if there is too much result to be processed here.


With filtering first,

https://user-images.githubusercontent.com/1087399/123526744-18bfdc00-d704-11eb-9754-0b65e6509103.mov


Without filtering first,

https://user-images.githubusercontent.com/1087399/123526750-2aa17f00-d704-11eb-92c8-a6c5baebf89c.mov

camspiers commented 3 years ago

Interesting, I suspect that it is only working when it has all the results. I need to iterate on this apparently. For now I think it's only going to work when you have all the results from ripgrep. Apologies.

spywhere commented 3 years ago

No worry, I can live with it for now. Thanks for the great plugin by the way, I really like how things get composed together.

camspiers commented 3 years ago

I've recently released a new configuration API which generates fucntions that call snap.run with reasonable configuration given a minimal API (less verbose). Under the hood it's really just doing all the appropriate composition and calling snap.run but it makes making mappings easier for common use cases. It's now documented in the readme. However it doesn't support steps/next yet.

Let me know what you think if you give it a try.

spywhere commented 3 years ago

This issue (https://github.com/camspiers/snap/issues/1) seems to be exactly what I'm looking for, which is also seems to be the solution suggested above.