nvim-telescope / telescope.nvim

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

Rank tags by symbol, not filename #1369

Open tpict opened 3 years ago

tpict commented 3 years ago

Is your feature request related to a problem? Please describe. The builtin tags picker filters the list based on the filename, not the symbol.

For example, if I typed dog to find the Dog class from a module named animals.py, that class would be ranked below a module named dogma.py that doesn't contain the symbol Dog at all.

Describe the solution you'd like Rank lines that match on the symbol more favorably than those that match on the filename.

Thank you!

tpict commented 3 years ago

I took a crack at implementing this by using opts.fzy_mod to extract the symbol from each line before passing to fzy.score. Results are better, but I think some kind of heuristic is needed to give a bonus score if the filename also matches. I don't know fzy well enough yet to do this.

Before:

image

After:

image

Also, smart case is helpful when navigating tags, especially in OO languages with thing = new Thing() patterns everywhere.

Conni2461 commented 3 years ago

See https://github.com/nvim-telescope/telescope.nvim/blob/f56222738b719f5ae94ed85fdf080690371da0b9/doc/telescope.txt#L789-L807

Does Telescope tags only_sort_tags=true help you? For smart case you should look into https://github.com/nvim-telescope/telescope-fzf-native.nvim. It also support multiple patterns which are separated by a space.

tpict commented 3 years ago

only_sort_tags has the same behavior as my custom code, thanks!

I'm still looking to get the behavior closer to the tags builtin in fzf.vim, where matches get a bonus if the filename matches too. This improves results IMO as definitions tend to be stored in a file with a relevant name. For example, with only_sort_tags, a search for MyClass might bring up results like

  src/stuff/MyClass.js         class MyClass {
> src/aaaa/aaaa/aaa.js         var MyClass = require(...)

where some unrelated file has been ranked more favorably.