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

Highlight autocompletion suggestions from the direct class (as opposed to inherited classes) #4339

Open
Calinou opened this issue Apr 3, 2022 · 7 comments

Comments

@Calinou
Copy link
Member

Calinou commented Apr 3, 2022

Related to #4189.

Describe the project you are working on

The Godot editor 🙂

Describe the problem or limitation you are having in your project

The script editor's autocompletion dialog currently doesn't distinguish between suggestions provided by the direct class and inherited classes.

For example, if you're extending MeshInstance3D, autocompletion suggestions coming from MeshInstance3D properties and methods will look identical to those coming from Node3D.

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

Highlight autocompletion suggestions from the direct class (as opposed to inherited classes). This could be writing them in bold, using a different color (such as a partial blend of the editor accent color), or something else.

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

@EricEzaM posted an example from Rider in #4189 (comment):

image

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

No, as the script editor's code completion dialog is not extensible with add-ons.

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

See above.

@Calinou Calinou changed the title Highlight autocompletion suggestsions from the direct class (as opposed to inherited classes) Highlight autocompletion suggestions from the direct class (as opposed to inherited classes) Apr 3, 2022
@EricEzaM
Copy link

EricEzaM commented Apr 4, 2022

Styling: using a bold font would mean adding the bold version of Jetbrains Mono to the editor fonts, which includes quite a bit of boilerplate. Probably not worth it - might be better to just stick to a slightly accented color.

Implementation: Using the new "location" property added in godotengine/godot#58931, it is possible to do this styling. However there is one hiccup: using the parent mask is not so trivial unfortunately. Due to the way the GDScript language code completion code works, the location value which has the "parent [class] mask" applied includes the "recursion depth", which is used to track the recursion depth of the functions that recursively collect all the identifiers from classes and their parents. (see gdscript_editor.cpp _find_identifiers_in_base)

The problem: This recursion depths is not strictly one-per class. In a test I did, a property in the file I was using had a location of 257 (LOCATION_PARENT_MASK | 1) rather than 256 (LOCATION_PARENT_MASK | 0), so this makes it hard to use this value for anything other than sorting. I'm not too familiar with the GDScript code complete, but I think it is possible to sometimes have a recursion depth of 1 to be the local class, and other times it be on the parent class. It might be ok to treat a value of 257 as being a local value (i.e. check for == 1 in the below if statement too), but I'm not sure.

Once that is sorted, I just had to add this code to the code edit draw code (plus some other stuff just to pass the location to the code edit):

if (code_completion_options[l].location == ScriptLanguage::LOCATION_LOCAL ||
   (code_completion_options[l].location & ~ScriptLanguage::LOCATION_PARENT_MASK) == 0) {
	// Draw text line in different color
} else {
	// Draw text line in normal color
}

Note in the image below, thing1, thing2 are in the local file, so should be coloured too, but they were found with recursion_depth > 0 so the above check goes to the "else" statement.
image

@Calinou
Copy link
Member Author

Calinou commented Apr 4, 2022

Styling: using a bold font would mean adding the bold version of Jetbrains Mono to the editor fonts, which includes quite a bit of boilerplate. Probably not worth it - might be better to just stick to a slightly accented color.

We have support for fake bold in master now 🙂

@Mickeon
Copy link

Mickeon commented Apr 9, 2022

I do like that accented colour, actually. I don't think it fits for direct classes, though. If it can be done, I wonder if the colour could symbolise something else entirely...

@just-like-that
Copy link

just-like-that commented Apr 16, 2022

Highlight autocompletion suggestions from the direct class (as opposed to inherited classes).

I also recommend to display direct classes with a precedence above inherited classes.

@EricEzaM
Copy link

Highlight autocompletion suggestions from the direct class (as opposed to inherited classes).

I also recommend to display direct classes with a precedence above inherited classes.

That is already the case in 4.0

@T3mak
Copy link

T3mak commented Sep 3, 2022

I think it would be great to be able to show/hide parameters from each class on button clicks so that autocomplete isn't cluttered with a bunch of parameters

@Mickeon
Copy link

Mickeon commented Sep 3, 2022

Just like Visual Studio?
image

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

No branches or pull requests

5 participants