-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Sort code autocompletion options by similarity based on input #65655
Sort code autocompletion options by similarity based on input #65655
Conversation
be5e503
to
d79fda7
Compare
This compiles locally but it doesn't in the checks... |
I assume because you're including an editor header file from outside of the editor folder. So when making a |
Ah, oh boy. This one is going to be... interesting to solve. Oh no... |
d79fda7
to
8bcebc6
Compare
Hastily attempting to address it so that this can be tested as soon as possible. |
I'm very glad you're tackling this long standing issue. But this current solution still does not seem ideal and should probably combine multiple methods of assigning score. For example, in a script extending Node, autocompletion for It's great that it finds matches that use the same letters in the same order. But the algorithm should definitely prioritize a full substring match ( |
It would somewhat do as you say, if the implementation of #59633 were to be completely replaced with this method. But instead, I attempted combining the two. Currently, and before, the order is kind of like this. What I could experiment with, is something along the lines of... "If the score is high enough, it ignores the kind of option and brings it all the way up the list", But honestly, right now I'm very fearful because some checks just do not compile! Honestly the screenshot you showed me is personally odd already, I think I broke something while attempting to make this compile. |
This indeed is probably the kind of thing that should introduce an editor setting or two (group by inheritance level, group by field/method/constant, etc.). Tbh I had no idea how it currently worked, so maybe my suggestion does not work well and would need a greater rewrite which is a lot to ask for. 😅
@Mickeon I'm not really well-versed with C++ but you could try removing the |
8bcebc6
to
d308483
Compare
@RedMser I have updated the calculation. |
d308483
to
a3c87ab
Compare
Ok I have revisited this again. Found more stuff that I may have overlooked in my initial PR, or has been changed since which messed some things up. diff on this PR: https://github.com/Mickeon/godot/compare/editor-autocompletion-sort-by-score...EricEzaM:65655?expand=1 If you want to test, try the build artefact from here when it finishes: https://github.com/EricEzaM/godot/actions/runs/3874969199 Also fixes #71059 P.S. 'Container Sizing' should not be there in 2nd capture. That is a property group. Issue for another PR though. |
@ajreckof it's because it is a local function on the class. It's true that it might be better for things which are local but are bad matches to be pushed lower. |
yeah it feels conter productive for them to show when they are not that much pertinent. I think results should first be sorted for match and on same level of match being sorted by scope. |
Oh I see, that is with this PR? I'll take a look. |
maybe there should be a penalty by how many times it is separated. The more parts there is to find the word the farther it should be ? this would be a more general way to differentiate than just it is in one part it is in multiple parts (don't know how hard it would be to implement sorry) |
I have tried to resolve the feedback above. I ended up adding a levenshtein distance implementation that I pinched from here (wikibooks - cc0). I more or less understand how it works but there is a nice implementation already documented so we're standing on the shoulders of giants etc etc I also got rid of the sorting based on 'kind' (constant, function, signal, etc) it probably added additional complexity without measurable benefit. I kind of hate how there are some 'magic numbers' in the implementation though.... Note one annoying thing is that the text that is highlighted is not actually the sections of text that were 'matched' by the sorting algo. The thing that the highlights uses is just a subsequence search so it sometimes highlights the wrong thing (e.g. download (once action is done running) ps @Kakiroi that long thing was being ranked higher since it had |
To make it really brief, uses a combination `String.similiary`, the category system introduced in a previous PR, and some filtering to yield more predictable results, instead of scattering every completion option at seemingly random. It also gives much higher priority to strings that contain the base in full, closer to the beginning or are perfect matches. Also moves CodeCompletionOptionCompare to code_edit.cpp
… to improve as many different use cases as possible
@EricEzaM Could you guide me to bring this PR to the way it is done in your branch? A git patch, perhaps? |
I think my branch is based on this branch so if you pull it down it should work. I have done that before with other people branches (non-pr). Anyway, @ajreckof expressed interest in investing a solution further since while I was making progress on it, I was still not satisfied and perhaps others would have better ideas. Their solution is looking pretty good, but not polished up yet. @ajreckof Maybe this is a decent time to share your work? |
c8ea22d
to
30cc0bb
Compare
So here is my work https://github.com/ajreckof/godot/tree/editor-autocompletion-sort-by-rules. It is based on your branch too so if you feel like adding it you can always just pull from it. What it does is mostly make the match shown the correct ones. Which subsequence is kept is based on the ordering so that if later on we modify the way matches are ranked the right match will still show the best one. |
Superseded by #75746. Thanks for the contribution nevertheless! |
This PR no longer adds. Maybe another time.
To see how the original algorithm sort-of-behaved, click here:
Added in the String class, the algorithm assigns a likeness value between 0.0 and 1.0 to the String calling it, relying on the
base
String parameter.If either Strings are empty it returns 0.0.
If
base
is not a subsequence of the String it returns 0.0.The algorithm aims to give higher scores to shorter Strings that contain the
base
's characters closer to the beginning of the String, and closer between each other. For example:Showcase
To make it really brief, this PR uses a combination
String.similiary
, the category system introduced in a previous PR, and some filtering to yield more predictable results, instead of scattering every completion option at seemingly random.It also gives much higher priority to strings that contain the base in full, closer to the beginning or are perfect matches,
I may add more mock-ups at a later time. But I'm only one person, not writing on Godot 4 full-time yet. As such...
I encourage people to please try this out by pulling this branch!
Final notes:
Known issues:This PR no longer highlights the characters that are part of the search. I do not know how to accomplish that right now.I do need proper names for the internal function, do suggest, please!If necessary I can open a proposal, but this is not stuff most users are particularly "savvy" about.See Sort code autocompletion options by similarity based on input #65655 (comment)Bugsquad edit: This closes #63706.