dumb-jump icon indicating copy to clipboard operation
dumb-jump copied to clipboard

sorting of results to show references first

Open vjohansen opened this issue 6 years ago • 9 comments

Hi

When there is many results from dump-jump-go the dropdown shows multiple results. These seem to have a "random" ordering (maybe the file structure ordering).

Most of the time you want a definition not a reference so I think the results should be sorted to show references first:

  • classes
  • functions
  • the rest

This could be done the dumb way with regexes. If you search for xyz then classes will look like "class xyz". For functions: "def xyz" (python), "(void|int|string|other return types) xyz" (C#).

vjohansen avatar Oct 24 '18 09:10 vjohansen

Thanks for opening this! In theory I absolutely agree with what you have here and it would be better to have it this way. That said, in practice I very rarely find myself needing to jump to anything that is common enough to have more than a few matches (or actually any). Although I understand this could be more a reflection of the programming language and/or the style of the programmer.

To implement this we would have to re-apply each set/type of regular expression against the result set to re-group the results for sorting this, because for speed we concatenate all regular expressions together, so we only have a single regex search on a project per jump. This would certainly add overhead, but I am not exactly sure how much since it's probably pretty safe to assume a result set will be relatively small compared a project/repo which could be huge.

Alternatively you might consider using a mixture of dumb-jump-go-prefer-external or dumb-jump-functions-only

Long story short, I'd be happy to consider a PR that implemented this, but I am unlikely to add this myself. Although I'd be happy to discuss further if I am missing anything. I'll leave this ticket open for further discussion. Thanks again!

jacktasia avatar Oct 24 '18 17:10 jacktasia

Thanks for the comment. I will use dumb-jump a bit more to see if it is an issue in practice

vjohansen avatar Oct 24 '18 19:10 vjohansen

In my opinion the sorting feature is a must. In most cases user wants to find function or class definition and the results containing these keywords should be first. I would even consider not just sort, but even hide the results which don't match the regex. That is why in most IDE's this feature called jump to definition. I've encountered a problem connected with this issue in my project. I have a C++ project in which i use Log() macro to print debug messages and information. When i try to find the definition of it with dump-jump it just shows me all the calls of this macro, and the actual definition

#define Log()

is in the middle of this huge list. I need to scroll down around 50 results to find the definition. It makes dump-jump almost useless. It is faster to just gper "#define Log" in such cases.

I have another great example why this feature is a must. In python: image

The first results is not a function, not even the same word but just the same symbols inside a string 😕

Maybe it is possible to add some custom regex which is nil by default and don't affect the performance?

VladasZ avatar Nov 27 '18 22:11 VladasZ

@VladasZ Thanks for the report! Seems like it's either:

  1. It looks like the variable regex is bad it should only be matching os = and not -sos=. Try doing (setq dumb-jump-functions-only t) and try it again. If it then works as expected please open a new issue for the bad variable regex and I'll fix it.

  2. or less likely the regexes are all failing (finding no results) and dumb-jump-fallback-search is kicking in, which by default will just look for the symbol. You can test this theory by doing (setq dumb-jump-fallback-search nil) and trying your search again.

Thanks for your help!

jacktasia avatar Nov 27 '18 22:11 jacktasia

@jacktasia Yeah. (setq dumb-jump-functions-only t) helped with Python. I should have checked it before posting. Thank you. I've also tried (dumb-jump-go-prefer-external), but C++ definitions and classes are still in the exact middle of a huge list: image

VladasZ avatar Nov 27 '18 22:11 VladasZ

@VladasZ Thanks for the info. I can't reproduce your python issue though. What searcher/version are you using? The c++ issue is definitely real. I think our rules are have too much going on at once. We probably want to break them up more. Please create a new issue for just that if you have a moment. Thanks!

jacktasia avatar Nov 27 '18 23:11 jacktasia

@jacktasia melpa is currently down. I will investigate this issue after it is back to normal.

VladasZ avatar Nov 28 '18 13:11 VladasZ

@jacktasia image The bug occurs only if there is = sign after the sequence + The Silver Searcher is installed. Interesting that after uninstalling The Silver Searcher the bug still persists. I've tested it on macOS and Ubuntu and had the same result.

VladasZ avatar Nov 28 '18 19:11 VladasZ

@VladasZ Nice catch! This definitely means there's an issue with the regex itself. This will allow me to fix it pretty easily and add a new not test case for this. Thanks!

jacktasia avatar Nov 28 '18 19:11 jacktasia