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

Search cached grep results #56

Open
spywhere opened this issue Jun 26, 2021 · 7 comments
Open

Search cached grep results #56

spywhere opened this issue Jun 26, 2021 · 7 comments

Comments

@spywhere
Copy link
Contributor

spywhere commented Jun 26, 2021

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
Copy link
Owner

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

@camspiers
Copy link
Owner

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
Copy link
Contributor Author

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,

snap-ripgrep-to-fzf-with-filtering.mov

Without filtering first,

snap-ripgrep-to-fzf-without-filtering.mov

@camspiers
Copy link
Owner

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
Copy link
Contributor Author

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
Copy link
Owner

camspiers commented Jun 26, 2021

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
Copy link
Contributor Author

spywhere commented Jun 27, 2021

This issue (#1) seems to be exactly what I'm looking for, which is also seems to be the solution suggested above.

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

No branches or pull requests

2 participants