godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.84k stars 20.96k forks source link

GDScript editor autocompletion is displaying the wrong type for a defined variable #92566

Open rcanpahali opened 4 months ago

rcanpahali commented 4 months ago

Tested versions

System information

Apple M1 Pro - macOS 14.5 (23F79)

Issue description

I already defined my npc variable as a PackedScene in the line 6, but for some reason, the editor IntelliSense in the suggestions shows its type as any, and I couldn't see the actual methods related to the PackedScene.

npc.instantiate() method is working fine but the method is not shown in the auto-complete list,

image

Steps to reproduce

To reproduce the steps, simply create a script as follows:

extends Node2D

@export var npc_list: Array[PackedScene]

func spawn_npc() -> void:
    var npc: PackedScene = npc_list.pick_random()
    var new_npc = npc.instantiate()

Minimal reproduction project (MRP)

Archive.zip

HolonProduction commented 4 months ago

85224 should have fixed that but I made an oversight. We use the analyzer logic to test whether the assigned type is compatible. The analyzer allows assigning variant types to everything, and pick_random returns a variant which for the analyzer is compatible with PackedScene (though unsave). So we end up with the type of the assigned expression but a variant doesn't has much value for autocompletion.

Edit: Just to clarify this any icon is used for all local variables at the moment. The type of the variable has no influence on it. I consider the scope of this issue to be the not working autocompletion. It might make sense to create a separate issue to request a better icon for local variables though.

Joseph-D-Bradshaw commented 4 months ago

Not sure if related, but I realise that type hints are not working (also giving me "any", which I see is not an issue here).

But for example.

var mesh: MeshInstance3D = get_child(0)
mesh.get_surface_override_material(0)  # this gives no autocompletion

I find that I am needing to use the as keyword a lot to get autocompletion to work.

HolonProduction commented 4 months ago

Not sure if related, but I realise that type hints are not working (also giving me "any", which I see is not an issue here).

As long as you are still on 4.2 no need to worry, https://github.com/godotengine/godot/pull/85224 should've fixed that. If you are using 4.3 please open an issue with an MRP about it.