godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Suggest missing identifiers in autocompletion #10571

Open HolonProduction opened 2 months ago

HolonProduction commented 2 months ago

Describe the project you are working on

Godot

Describe the problem or limitation you are having in your project

I prefer to connect signals manually in my scripts and not through the panel. Writing out the corresponding function is tedious.

This is an alternative to #8714 (only to the second use case).

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

I recently noticed the following behaviour in intelij and think it would be a cleaner solution to the second case of #8714:

When I write the following code:

extends Button
func _ready():
    pressed.connect(__on_pressed)

func # trigger completion here

I will get __on_pressed as suggestion. This makes it easy to implement the missing method while also avoiding a lot of pitfalls with generating a function without explicit user consent.

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

In editor builds, whenever the Analyzer encounters an IdentifierNode it can't resolve it will add it to a list.

The completion code reads this list when searching for overridable methods. It will suggest the identifiers name as possible method, those options will always show before virtual methods.

Based on a few special cases it will try to guess the method signature from the context of the identifier node.

If this is successfully it inserts this signature together with the name (I would prefer it to also insert a pass on the next line but I'm not sure whether we support multiline insert texts)

If it can't deduce a signature it only inserts the name and an open brace so that the user can add it.

The special cases I currently think of:

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

No

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

Usability

Mickeon commented 2 months ago

Many times I do write the non-existent function, and then copy and paste its name for later. This proposal suits me, particularly so if it fills the whole signature, as well.

(I would prefer it to also insert a pass on the next line but I'm not sure whether we support multiline insert texts)

I believe it would be as simple as including \n in the autocompletion test. Well, the actual problem is that the indentation would have to respect the user's settings.

AThousandShips commented 1 month ago

My issue with this is that it can easily reinforce accidental typos in your code, causing frustration and confusion, I've had that happen in other editors where I accidentally typed something wrong in one place and then it'll suggest the typo

HolonProduction commented 1 month ago

I don't think spelling mistakes are a huge concern for this specific case (but we might need to think more about this if we consider doing more "self-correcting" suggestions)

For a spelling mistake to become relevant a user would need to perform the following steps:

Judging by myself I tend to fix errors before continuing to code, so this seems very unlikely to me.

But I was thinking about adding a new completion option type for this kind of "intelligent" suggestions (in quotes since I don't have a better term right now). This type could then have a different visual identity than other options to make clear that they are guesses to make your code work.

I was thinking about a green text color in combination with a wand icon but I don't have any mock ups yet.