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 refine like Ivy #793

Closed
baldore opened this issue Apr 22, 2021 · 18 comments
Closed

Search refine like Ivy #793

baldore opened this issue Apr 22, 2021 · 18 comments
Labels
enhancement Enhancement to performance, inner workings or existent features

Comments

@baldore
Copy link

baldore commented Apr 22, 2021

Is your feature request related to a problem? Please describe.
It's not, unless there's already a way to do this with Telescope.

Describe the solution you'd like
I was trying a little bit of Emacs and I found Ivy, which has pretty cool features. One I found really interesting is that you can refine the search multiple times by accepting the current results and filtering those results again and again. The way you do this is by pressing shift + space.

Describe alternatives you've considered
Tried with Fzf, which has a way to "ignore" results with !. This is not related to this feature request, but it should be great to know how to do this. Example: !.test will show all the results that DON'T HAVE .test extension.

Additional context
Example from Emacs:
ivy

As you can see, each time the search expression disappears, is because it starts from zero with the filtered results.

Let me know what do you think, also about the question of Fzf "ignore".

@baldore baldore added the enhancement Enhancement to performance, inner workings or existent features label Apr 22, 2021
@windwp
Copy link
Contributor

windwp commented Apr 23, 2021

it already have a PR #771

@elianiva
Copy link
Member

that PR only implements the layout, not the "refresh"

@elianiva
Copy link
Member

simplescreenrecorder-2021-04-24_09.23.03.mp4

I made a very rough proof of concept, someone needs to implement a better version

@baldore
Copy link
Author

baldore commented Apr 24, 2021

@elianiva that looks pretty cool! Additionally to that, do you know how to do the ignore part? Regex maybe?

@Conni2461
Copy link
Member

I am not sure if this should be part of core. We can already do this with https://github.com/nvim-telescope/telescope-fzf-native.nvim just with space separated terms. Its also more powerful because it has suffix/prefix/exact/equal matching

@tjdevries
Copy link
Member

I was trying a little bit of emacs...

That's a ban from this repo! 😂

Yeah, the search refine would be cool. We can add this to 1.0 (might get pushed back depending on complexity)

@VVKot
Copy link
Contributor

VVKot commented May 20, 2021

As a temporary workaround you can send all results into a quickfix list and then call builtin.quickfix to get them back into Telescope.

@tmke8
Copy link

tmke8 commented Jun 17, 2021

As a temporary workaround you can send all results into a quickfix list and then call builtin.quickfix to get them back into Telescope.

I tried this but it's excruciatingly slow and doesn't seem to work right. So, I first did live_grep, then ctrl-q to send everything to the quickfix list and then :Telescope quickfix to refine. But it seems quickfix is searching through the files referenced in the quickfix list and not just through the entries themselves, which makes it very slow.

What works better for my purposes is to just use normal vim search (/) in the quickfix window.

@VVKot
Copy link
Contributor

VVKot commented Jun 17, 2021

@thomkeh I feel like we're talking about different things. In your description, I'd imagine that you do some search between live_grep and "ctrl-q to send to quickfix", so that number of things sent to quickfix list is manageable. QF list is notoriously slow for large entry count.

Not sure about "quickfix is search through the files", for me it seems to search through actual entires + filenames". If you can consistently repro your case - probably worth filing a separate issue.

@tmke8
Copy link

tmke8 commented Jun 17, 2021

@VVKot ah, sorry, the "it searches through the files instead of the entries" was just my theory to try to explain the slowness. Because with just 270 entries, it brought my whole nvim to a complete standstill such that I had to kill the nvim process.

But what do you mean by "do some search between live_grep and ctrl-q"? Can I search on live_grep results somehow?

@VVKot
Copy link
Contributor

VVKot commented Jun 18, 2021

@thomkeh understood, 270 is definitely something that nvim should easily handle!

Please disregard that, I thought you were doing something like the below (which does not seem to be the case).

  1. Trigger live_grep
  2. Search for something present everywhere (e.g. a space: " ")
  3. Push all there results to quickfix list
  4. Search the quickfix list

Re: search live_grep results - no, there isn't, that's what this issue is about. 😄 However, I think @Conni2461 's suggestion is a good one - you can just use fzf's operators instead, so that you can express your search in a single query:

#793 (comment)

@fedemengo
Copy link

simplescreenrecorder-2021-04-24_09.23.03.mp4
I made a very rough proof of concept, someone needs to implement a better version

@elianiva do you have a branch I can have a look at? I'm trying to do something similar

@fdschmidt93
Copy link
Member

#1115

I havent had a look at this in a while, but it worked well back then

@danielo515
Copy link

@fdschmidt93 why is your implementation limited to fuzzy refining live grep? Can it be used to refine other searches?

Will this feature request cover an scenario like this:
Often times I do a regular grep, refine some terms in telescope and then I want to continue searching from there, but instead of searching within the entries, I want to refine my search within the whole content of the selected files.
Is that already possible by adding my own stuff without modifying Telescope? Or is something like #1115 required?

@fdschmidt93
Copy link
Member

why is your implementation limited to fuzzy refining live grep? Can it be used to refine other searches?

Its not limited to those, but they are the ones for which it would make most sense.

Will this feature request cover an scenario like this:
Often times I do a regular grep, refine some terms in telescope and then I want to continue searching from there, but instead of searching within the entries, I want to refine my search within the whole content of the selected files.
Is that already possible by adding my own stuff without modifying Telescope? Or is something like #1115 required?

If I understand it correctly, it is definitely possible, but you would have to write your own picker chain for this. Check out developers.md in the top level of the repo (am on mobile, cannot link).

@danielo515
Copy link

danielo515 commented May 24, 2022

If I understand it correctly, it is definitely possible, but you would have to write your own picker chain for this. Check out developers.md in the top level of the repo (am on mobile, cannot link).

Thanks, I will have a look at that. I have been reading the code of live_grep and with the arguments it takes it seems not possible to limit the search to a list of files. It takes a list of folders, but that is not enough, I want to limit it to grep over a list of files.

EDIT: I can probably build my own picker taking the live_grep as an example. Thanks for pointing it out.

@Conni2461
Copy link
Member

We now provide a somewhat basic interface to do that with implementations for live_grep and lsp_dynamic_workspace_symbols to go from live to fuzzy with <c-space>. Can also be configured see #2034

It can also be used for other usecases, like find_files but we dont provide a implementation for that, you have to implement it yourself because i still think fzf-natives space delimiter is a better solution because it allows you to go back. With the new refine interface we remove all times that aren't filter and this step can't be reverted and you have to research to get them back. We might change that in the future but right now this is a limitation to consider.

None the less you can still set it up for one or all pickers if you want to with the following snippet

require("telescope").setup {
  -- defaults = { },
  pickers = {
    find_files = {
      mappings = {
        i = {
          ["<c-space>"] = function(prompt_bufnr)
            require("telescope.actions.generate").refine(prompt_bufnr, {
              prompt_to_prefix = true,
              sorter = false,
            })
          end,
        },
      },
    },
  },
  -- extensions = { },
}

This sets it up for find_files only, if you want it for all pickers just move the mapping into defaults table. see :help telescope.setup() for more information about configuration

jesse-c added a commit to jesse-c/dotfiles that referenced this issue Jul 3, 2022
@marcelarie
Copy link
Contributor

Now you just need to add this to your telescope config:

ts.setup {
    pickers = {
        live_grep = {
            mappings = {
                i = { ["<c-f>"] = actions.to_fuzzy_refine },
            },
        },
    },
}

And now you can refine the searches in live_grep as much as you like :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to performance, inner workings or existent features
Projects
None yet
Development

No branches or pull requests