godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.14k stars 93 forks source link

Include argument types when autocompleting virtual methods and generating signal handlers #5122

Open sshilovsky opened 2 years ago

sshilovsky commented 2 years ago

Describe the project you are working on

I'm working with godot tutorial currently

Describe the problem or limitation you are having in your project

The code editing experience could be improved a little. Currently, lack of type definition in a generated method's argument disables autocompletion of the argument's own methods. For example:

func _on_Player_input_event(camera, event, position, normal, shape_idx):
    camera. # autocomplete doesn't work
func _on_Player_input_event(camera: Node, event: InputEvent, position: Vector3, normal: Vector3, shape_idx: int):
    camera. # autocomplete works

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

Include argument types declaration when generating signal handlers or overridden virtual methods.

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

func _on_Player_input_event(camera: Node, event: InputEvent, position: Vector3, normal: Vector3, 
shape_idx: int):
    pass # This is how a generated signal handler should look like

func _process(delta: float): # This is how an autocompleted virtual method override declaration should look like (": float" is added)

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

Yes, the arguments' types can be filled in manually.

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

Yes, because this is a core feature that should be available by default.

Calinou commented 2 years ago

You can enable type hint generation for autocompletion in the editor settings (which also applies to signal function creation). This feature is disabled by default as it could be confusing for beginners, but maybe it's time to enable it by default for 4.0.

Mickeon commented 2 years ago

I always thought the two should be split, somehow. As in, type hint generation for normal methods, and type hint generation for signals. For example, I personally don't like to see _process(delta: float) being generated because it's a method I see very frequently, thus specifying the type feels redundant, and the autocompletion works even without float.

sshilovsky commented 2 years ago
# Autocomplete example:
func _physics_process(delta: float) -> void:

the returned type void is probably redundant though.