Open HolonProduction opened 3 months ago
Also if we decide to change stuff in this API it would be a good time to evaluate whether the p_force
parameter on update_code_completion_options
is really needed. From my reading it just adds a special case were completion is canceled if the cursor is behind a brace (
.
Once again this feels a bit arbitrary and was probably also a solution for some GDScript use case (the argument hint for methods does not show when there are options, so after an open brace we don't want to show options so that users see the hint. But in the case of argument options we want to trigger, and to do that we set p_force
.)
We should test whether the GDScript Language handles this case gracefully on its own (which it should)
Describe the project you are working on
Godot
Describe the problem or limitation you are having in your project
The usage of
CodeEdit
s completion functionality is not well documented, in an attempt to fix this, I found the interface to be confusing and not easy to use.Overall the design doesn't match the expectations that users have when interacting with the feature (especially for completion prefixes as seen in godotengine/godot#73968 )
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Overall: My main problem is that we have a signal and a virtual method which share a name but not a purpose. Most users want godot to trigger completion when necessary and just populate the options, this use case fits the signal. The virtual method can be used if godots checks for triggering are not sufficient for the use case.
To make this clearer to the user, those two purposes will be split into two separate names now. Checks whether completion should be triggered will now be done by
check_for_code_completion
which comes with a default implementation which leverages the completion prefixes. If those checks are not enough users can implement them on their own with the new virtual method_check_for_code_completion
. In contrast to before, this method has no responsibility for populating the options, it will just callrequest_code_completion
when necessary. Checks can be skipped by calling this method directly (which should be done when using the shortcut).request_code_completion
has now only one job, to list options.More specific details:
request_code_completion
(checks that would apply to the signal).Those checks have two purposes, to cite from the documentation:
Those checks are meant to regulate when completion is triggered when typing in the code edit. Those checks will now be performed by
check_for_code_completion
.This seems a bit arbitrary and I guess it was tailor made at some point, to make argument option completion possible for GDScript. This is not required anymore though since the GDScript Language handles this on its own now (as can be seen when triggering autocompletion in such a situation with the shortcut, and thus bypassing the checks).
p_force
parameter will be removedrequest_code_completion(false)
will be replaced bycheck_for_code_completion
._request_code_completion
will be marked as deprecatedThe p_force parameter will always be
true
. Users can use it like a method that is connected to the signal.check_for_code_completion
when something is typed inside(It will call to
request_code_completion
if the shortcut is used)This is currently automatically done and the prefix array might add additional symbols. This behavior is not well documented and hard for users to find. The checkbox makes clear that characters don't need to be added as prefixes, and also gives users an option to disable it and only trigger with specific characters.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
A user will be able to have something working with this minimal example:
Internally it is mostly renaming some stuff, moving some stuff between methods and rewriting and removing some checks.
If this enhancement will not be used often, can it be worked around with a few lines of script?
Renaming stuff to make it easier to understand:
Connecting automatically:
Disabling chars as completion prefixes:
Is there a reason why this should be core and not an add-on in the asset library?
Usability on a builtin node