Skip to content
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 autocomplete options in a more useful way #4189

Closed
EricEzaM opened this issue Mar 8, 2022 · 11 comments · Fixed by godotengine/godot#58931 or godotengine/godot#59633
Closed

Sort autocomplete options in a more useful way #4189

EricEzaM opened this issue Mar 8, 2022 · 11 comments · Fixed by godotengine/godot#58931 or godotengine/godot#59633
Milestone

Comments

@EricEzaM
Copy link

EricEzaM commented Mar 8, 2022

Describe the project you are working on

N/A

Describe the problem or limitation you are having in your project

The sorting of autocompletion options is not very productive.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Improve the sorting of the options to take into account the contents of (in order)

  • The immediate context (e.g. the containing file (see image 1 and 2 below), or the class referenced (see image 3 below))
  • The inherited classes (in order of inheritance)
  • Other global identifiers

Godot Currently (4.0)
godot windows tools 64_CpZ2wr9u1x
godot windows tools 64_Oi134QFhdJ
godot windows tools 64_8p2M0towMt

Good Example, Visual Studio. Just some random WPF project I had lying around
devenv_lpRJ7yu6Y9

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

I looked at the code... would require a bit of work changing how code completion works, see GDScriptLanguage::complete_code.
I am not really familiar with the code, there is heaps of it, and it's not really commented so I tried and promptly gave up on trying to do it.

Probably done by adding an additional property to ScriptCodeCompletionOption, something like 'location', which would specify the script path or class name from which the option comes from. e.g. 'Node', 'res://test/my_script.gd', 'Object', 'res://test/base_script.gd'

Then, when filtering (in CodeEdit) use the value of the 'location' to determine the "weight" of the option. You would have access to the Script there, so would be able to get a list of all the classes from which the script inherits (if any), and then loop through that list and assign weight to each. This File = highest weight, Last base class = lower weight, globals = lowest weight.

Just thinking out loud here, such a simple method may not work with some complexities, like accessing members of a 'static' class, like the Input. example in the images above.

If this enhancement will not be used often, can it be worked around with a few lines of script?

Nope

Is there a reason why this should be core and not an add-on in the asset library?

Its the editor

@KoBeWi
Copy link
Member

KoBeWi commented Mar 8, 2022

I created an issue about it once: godotengine/godot#21726
There was even a nice PR fixing it, but it was never merged and then author gave up :<

@EricEzaM
Copy link
Author

EricEzaM commented Mar 8, 2022

@KoBeWi Ah, sorry, I tried to search but did "code complete" as my query. It may have come up anyway, but I missed it. I thought there would be an issue regarding it as I noticed it clearly coming from VS/Rider, so others would have too.

@EricEzaM
Copy link
Author

EricEzaM commented Mar 8, 2022

Ok, I tried something. Here is the commit so you can see the changes: godotengine/godot@master...EricEzaM:better-code-completion

Basic logic:

  • Add location property to ScriptCodeCompletionOption. It is an int, but has a corresponding enum, and more importantly one of the enum values is a mask, LOCATION_PARENT_MASK = (1 << 8),. This allows you, for example, to sort closer ancestors differently from more distant ancestors. The class itself will be value 256, while the class it inherits will have its location at 257, and then its parent at 258, etc.
  • When creating options, pass a location. This can be easily calculated if the options are created in a loop, where the loop is looping over parent classes and getting the class info for them. const int location = classes_processed | ScriptCodeCompletionOption::LOCATION_PARENT_MASK;
  • When you have all the options, simply sort on location. The lowest values will be highest priority. If two locations are the same, sort alphanumerically.

Note as of writing the implementation ONLY works for "attributes" on "Native" data types, like Input, as shown below. I'm not sure how well this will scale to other cases of completion, but only one way to find out! No more time to do it today though.

image

Also, future wishlist/stretch-goal item: Serialise and save which code completion options are selected in which contexts, and how often. Then push these options closer to the top. Like with Input, is_action_just_pressed would probably be pretty common so push that to the top.

@AaronRecord
Copy link

See also #99, #1216

@EricEzaM
Copy link
Author

EricEzaM commented Mar 9, 2022

Haha wow, yep, a straight up dupe of 99. Oops! I knew it was likely to be have reported somewhere before.

@AaronRecord
Copy link

AaronRecord commented Mar 10, 2022

Haha wow, yep, a straight up dupe of 99. Oops! I knew it was likely to be have reported somewhere before.

If it makes you feel better, I knew the issue I was looking for and it still took me a few minutes to find it :)

@EricEzaM
Copy link
Author

Rider also makes options from the direct class bold:
image

@Calinou
Copy link
Member

Calinou commented Mar 28, 2022

Rider also makes options from the direct class bold: image

It might be worth opening a dedicated proposal for this. I'd really like to see this 🙂

@Zireael07
Copy link

At any rate, it should be reopened temporarily as the PR was reverted pending some improvements to the code.

@Calinou
Copy link
Member

Calinou commented Mar 28, 2022

Reopening, as this was reverted by godotengine/godot#59629.

@EricEzaM
Copy link
Author

It might be worth opening a dedicated proposal for this. I'd really like to see this 🙂

Theoretically it should be pretty easy with the additions in the linked PR. Theoretically :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants