GDScript in VSCode doesn't autocomplete nodes declared as properties

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By nanoblit

Hello. I was going through the signals tutorial and I couldn’t get autocompletion to work correctly. Here’s the code:

extends Node2D

onready var sprite: Sprite = $Sprite

func _on_Timer_timeout() -> void:
	sprite.visible = !sprite.visible

Written like this “sprite.” won’t autocomplete the “visible” property, but when I write it like this:

func _on_Timer_timeout() -> void:
	var sprite: Sprite = $Sprite
	sprite.visible = !sprite.visible

It does autocomplete.
Am I doing something wrong?
Thanks in advance.

:bust_in_silhouette: Reply From: BananaBread

Hey, my best guess would be that in the first scenario, Godot would have to first run the script to actually find out what type the variable sprite is. After running the game, it should remember its type in some sort of cache and offer you autocompletion.

When you actually type the variable (= give it a type), the engine does not have to run the script to determine what autocomplete options it should give you. I’d say it does this, because offering you autocomplete of all attributes and methods in gdscript would be either messy, laggy or both.