ecode icon indicating copy to clipboard operation
ecode copied to clipboard

Implement glob match for path and extension search in Locate bar

Open Curculigo opened this issue 1 year ago • 17 comments

I want to list all files that have .txt extension in an opened folder.

Curculigo avatar Sep 24 '24 19:09 Curculigo

How? All at once? How would you do it in other editor? If you just want to search for a file use the universal locator... CTRL+K or Alt+1.

SpartanJ avatar Sep 24 '24 19:09 SpartanJ

Sorry. I mean listing them, not opening them all at once. I will choose which ones to open in the list.

Curculigo avatar Sep 24 '24 20:09 Curculigo

Go To Locate (Ctrl+k or Alt+1 or click in "Locate" below -> write: .txt. It should be enough.

SpartanJ avatar Sep 24 '24 20:09 SpartanJ

Will it do a search recursively in all sub-directories of the opened folder?

Curculigo avatar Sep 24 '24 20:09 Curculigo

Yes, exactly. When you open a folder it generates the complete list of files from the extensions supported and you can find any file from the locator.

SpartanJ avatar Sep 24 '24 20:09 SpartanJ

Can I tell it to search only in a specific sub-directory? I don't want to open that directory as the new folder.

Curculigo avatar Sep 24 '24 20:09 Curculigo

You can filter from path, so if you need to search some sub-directory you write the partial path: root/subdir/etc and it will list files from there.

SpartanJ avatar Sep 24 '24 20:09 SpartanJ

Will something like root/subdir/etc/.txt work?

Curculigo avatar Sep 24 '24 20:09 Curculigo

Yes, it's a fuzzy search, it will try to approximate the result: Screenshot_20240924_171229

SpartanJ avatar Sep 24 '24 20:09 SpartanJ

I don't think the feature works as intended. Do you still have llvm-mingw? Try opening llvm-mingw-20240917-ucrt-x86_64 as a folder and listing all header files (.h extension) in the include directory. The list is definitely not complete.

Curculigo avatar Sep 24 '24 20:09 Curculigo

I found another quirk. Try to list all files in the bin directory with bin\. It will not list all files in bin as intended and will also list files not in bin, e.g: files in lib. Btw, I think forward slash should be used instead of backward slash. I tried with forward slash (bin/) and it doesn't work.

Curculigo avatar Sep 24 '24 20:09 Curculigo

I don't think you understood how the feature works, it's a fuzzy search, given low density information like .h won't give you good results, it's not trying to filter directories or files, it's just doing a quick string matching, some improvements can be done to have better approximations for your use case: for example, I could give more weight to recognized extensions if written, or try to prioritize filtering folders if a folder separator is used (/ or \). Fuzzy search is more oriented to do file search than what you're trying to achieve, it's a very common feature in modern editors. I'll change the feature request title to "improve fuzzy search for path and extension matching".

SpartanJ avatar Sep 24 '24 20:09 SpartanJ

This is the first time I hear about fuzzy search. Is it the same thing as the search suggestions in the address bar of Firefox? It will suggest to you the URLs in history or bookmarks based on what you have typed.

Curculigo avatar Sep 25 '24 00:09 Curculigo

I'm simply using this feature wrong. There is no enhancement needed.

Understood, but I do think it's a good idea to have a mode where filtering works the way you're looking for, I'm thinking I can add and extra mode as these ones and filter with a glob pattern match.

This is the first time I hear about fuzzy search. Is it the same thing as the search suggestions in the address bar of Firefox? It will suggest to you the URLs in history or bookmarks based on what you have typed.

They use a fuzzy search too, probably different because they match against different kind of information but yes.

SpartanJ avatar Sep 25 '24 00:09 SpartanJ

I'm simply using this feature wrong. There is no enhancement needed.

Understood, but I do think it's a good idea to have a mode where filtering works the way you're looking for, I'm thinking I can add and extra mode as these ones and filter with a glob pattern match.

I found more quirks of the feature. This is the reason why I deleted my previous comments. It's really weird. For example, it can't provide suggestions for the x86_64-w64-mingw32 directory. I typed x86 and it suggested some header files whose names started with x86 to me. But immediately after I typed _, it started to suggest nonsense. Why can't it handle x86_ correctly?

Curculigo avatar Sep 25 '24 00:09 Curculigo

It's just a probabilistic algorithm, it will assign some score based on the consequent matches found in a string and sort the list by score. If it was nonsense to you it's probably because there are no good matches with _. The idea is that approximate a result based on what the user wrote even if it's not exactly that. It's a veeery simple algorithm, it can be improved, there are many fuzzy match implementations.

SpartanJ avatar Sep 25 '24 00:09 SpartanJ

I ended up implementing it for me, it can be useful having the possibility of glob matching the directory tree:

https://github.com/user-attachments/assets/6420cad2-f2bb-4243-a25c-79cdb5beb377

SpartanJ avatar Sep 25 '24 02:09 SpartanJ