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

[3.x] Improve GDScript autocomplete type detection with the most-specific types available #62074

Open
wants to merge 4 commits into
base: 3.x
Choose a base branch
from

Conversation

Macksaur
Copy link
Contributor

@Macksaur Macksaur commented Jun 15, 2022

See #39228 #53318 #61978. This change would fix those issues in 3.x. It may fix others that depend on autocomplete type information.

This change also improves #31818. The correct signals now show up in obj.connect(<autocomplete here>) in many new scenarios.

@Macksaur
Copy link
Contributor Author

Macksaur commented Jun 15, 2022

Test Case: #62074 improve-autocomplete-specific-types.zip

In Testing.tscn open the root node script and place your cursor at the end of each line in _ready() and autocomplete the variables. Observe they match the names in the comments. Also try to autocomplete the signal names in connect()!

Also you can run the test without this PR in 3.x/3.4! Note the stark difference in completions offered. There are a lot of missing completions and significantly reduced signals available to autocomplete in 3.x without this PR.

image

Here's a snippet of the completions offered to signals.

@Macksaur Macksaur force-pushed the 3.x-improve-autocomplete-specific-types branch from 24bb5fd to 4bab7c0 Compare June 18, 2022 19:26
@Macksaur
Copy link
Contributor Author

After too much time contemplating #58676 I felt that there was more opportunity to push this further. I refactored the changes into the GDScriptParser and started to take advantage of the increased availability of type traits.


Instead of overly restrictive compiler errors, is/as operators are now much more relaxed (and behave like (thing as Object) as Derived) and instead only produce warnings if the type conversion is thought to be impossible.

image

Also, ternary if can now correctly discern the common type between its arguments and now provides only the correct completions that are guaranteed to be available. INCOMPATIBLE_TERNARY is still, of course, a valid warning when the types can't be coerced. (randf() is here used to prevent constant folding into a specific-type in the test).

image

These particular changes have been made in part to gather comments and allow for thinking out loud around the subject. They may be slightly too much for 3.x despite not introducing any breaking changes (🤔?). The original PR can always be cherry picked and cleaned up form 24bb5fd.

This all looks to be very simple to add to 4.0 if this is a desirable PR.

@Macksaur Macksaur marked this pull request as ready for review June 18, 2022 20:26
@Macksaur Macksaur requested review from a team as code owners June 18, 2022 20:26
@akien-mga akien-mga changed the title [3.x][GDscript] Improve autocomplete type detection with the most-specific types available [3.x] Improve GDScript autocomplete type detection with the most-specific types available Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants