nvim-telescope / telescope.nvim

Find, Filter, Preview, Pick. All lua, all the time.
MIT License
15.01k stars 818 forks source link

Make search progress more user friendly #1713

Open bercly0b opened 2 years ago

bercly0b commented 2 years ago

Hi guys. I'm trying to switch from fzf to telescope and there is one thing that blocks me.

Is your feature request related to a problem? Please describe. When I'm searching (find_files, live_grep), I don't understand the search is over and nothing is found or the search is in progress. In gif, after a few seconds, the total number of files will change

telescope gif

![telesope](https://user-images.githubusercontent.com/29758632/150763530-06ceb3e1-5dd3-461c-83a0-5b9e16ddcd18.gif)

Describe the solution you'd like In fzf.vim search progress is more user friendly

fzf gif

![fzf](https://user-images.githubusercontent.com/29758632/150763543-d8eb6662-f0de-4b5d-b277-3882e70168d8.gif)

Is it possible to make the same "live" progress in a telescope?

alefpereira commented 2 years ago

Dear @bercly0b, have you tried telescope-fzf-native? I'm away from my computer now but I'm almost sure it behaves the same as in the fzf gif.

bercly0b commented 2 years ago

Hi @alefpereira Thanks you for your answer. Yes, I tried telescope-fzf-native, but I have the same result. It shows the count of files and only updates this number after a few seconds.. here is my telescope config

alefpereira commented 2 years ago

@bercly0b I'm curious about that.

I see you have a lot of patterns in your file_ignore_patterns table, if I'm not wrong, those patterns are filtered by telescope, only after the file list is retrieved by the external command, this may be causing this strange behavior in your setup.

Try to remove those patterns from telescope and use a custom fd command for it to filter them before passing the file list to telescope.

I use this command fd --type file --type symlink --hidden --exclude .git, but you can custom the way you want:

require('telescope').setup({
  defaults = {
    pickers = {
      find_files = {
        find_command = {
          'fd',
          '--type',
          'file',
          '--type',
          'symlink',
          '--hidden',
          '--exclude', 
          '.git',
          -- put your other patterns here
        }
      }
    }
  }
}) 
alefpereira commented 2 years ago

@bercly0b please let me know if it worked.

I'm almost sure the custom fd command will do the trick for the find_files, but if it doesn't work, or if you just want a faster finder for git repositories, try to use git_files instead. The fd command is really fast, but for a git repository, git_files is faster.

There is even this recipe that setup a function to use git_files if you are working on a git repository and if you are not, it will fallback to find_files, you can then set a keymap to it.

bercly0b commented 2 years ago

With fd and removing the file_ignore_patterns table it works much better! Thanks a lot, now I can switch to telescope from fzf.vim

But there is one interesting thing. When I just open the picker, it provides "live" search progress. But when I start typing, it causes a delay in displaying the search progress. I specifically did not ignore node_modules in this example to provide a large number of files to search for..

gif

![telescope-fd](https://user-images.githubusercontent.com/29758632/153564320-b57e4be9-f543-4ecc-81ca-0df983fd3541.gif)

hbiel commented 2 years ago

I think it would be helpful to have an visual indicator while a search process is running in the background. Like FZF does with this animated circle of dots for example.

This could also be displayed on right side of the prompt where the result count is shown.

alefpereira commented 2 years ago

You're welcome @bercly0b, glad to help.

I tested both telescope and the terminal fzf tool in the linux repository which have more than 75K files and I notice the behaviour you mentioned in telescope.

For me it seems that telescope do the sorting in two different moments/stages, one as you type, and the other, showing a different sorting after a second or so, runs on background, or maybe debounced idk, while in fzf its done only as you type. This doesn't mean that telescope-fzf-native implementation is slower than fzf but sure the UX feels slower and a bit odd.

I also tested both telescope-fzf-native and the fzf tool in my home dir with fd --hidden -I which brought over 900K files. I notice that the time it took for telescope to show the "second sorting" was almost if not the same as with 75K files. This brings me the feeling that this is caused by how telescope interface interacts with the fzf-native search result, and not the sorting itself freezing or being slow.

alefpereira commented 2 years ago

In fzf the animated dots are shown during the files load, the search shows a percentage like (42%) in the right side of the number of files, for me I'm already content with only the files counting growing, but both indications would be good to have.

@bercly0b, @hbiel I'm not a Telescope member but I like to contribute to projects I really like in my free time. But I'm not having much of that these days, If you guys could help, at least with some analysis or understanding how telescope handles this, we could work on that together.

hbiel commented 2 years ago

In fzf the animated dots are shown during the files load, the search shows a percentage like (42%) in the right side of the number of files, for me I'm already content with only the files counting growing, but both indications would be good to have.

@bercly0b, @hbiel I'm not a Telescope member but I like to contribute to projects I really like in my free time. But I'm not having much of that these days, If you guys could help, at least with some analysis or understanding how telescope handles this, we could work on that together.

I feel the same, not having as much time myself. But i can try. :-)

What i found so far regarding the progress indicator:

The picker has an an status_updater which can be called to update the status text in the prompt. This is defined here: https://github.com/nvim-telescope/telescope.nvim/blob/f262e7d56d37625613c5de0df5a933cccacf13c5/lua/telescope/pickers.lua#L1194-L1223

This updater uses the function get_status_text to determine which text to display: This function can be customized via user configuration, the defaults are set here: https://github.com/nvim-telescope/telescope.nvim/blob/f262e7d56d37625613c5de0df5a933cccacf13c5/lua/telescope/config.lua#L363-L390

This even has some commented code which should display an indicator whether the search is completed or still running. Simply uncommenting it and using the status_icon in the returned text doesn't work however as opts isn't set. Changing opts to self helps but then the icon never gets updated to the checkmark.

Something seems to be missing here.

bercly0b commented 2 years ago

@hbiel thanks you for links to code. I found what was missing, and I have made PR into my fork.

And I think there are a couple more things that need to be discussed:

I think it would be great if someone from the telescope team will advise us

Conni2461 commented 2 years ago

We talked about adding search animations some time ago but the whole ui is currently bottle necking so its not on top of our priority list. The ui rewrite happens here #1491

jelmansouri commented 2 months ago

Hi! Was looking into the same issue as using the raw fzf command feels more snappy than telescope on large code bases such as the UnrealEngine one. I need to do more thorough timing but the overall timing of a similar search seems close, but the fact that results starts showing up progressively makes it feel like actually fzf is quite faster.

jamestrew commented 1 month ago

@jelmansouri telescope won't be as fast as raw fzf see https://github.com/nvim-telescope/telescope.nvim/issues/2884#issuecomment-1905061100