godot: Autocompletion breaks until the editor is restarted when a cyclic reference occurs

Godot version

4.0.3 stable

System information

Windows 10

Issue description

Something is breaking the autocompletion when I used 2nd degree or more member of a variable.

Here’s an exemple:

class_name MyClassA extends Node2D

func get_num():
	return 1

var classB : MyClassB

func _ready() -> void:
	Global.classA = self
	
	pass

And

class_name MyClassB extends Node2D

var classA : MyClassA

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	classA.classB.classA.get_num()
	pass

If you rename get_num to get_numb for exemple, the autocompletion in MyClassB will continue to show get_num (and CTRL+Click to it will refer to get.num), and I need to reload all the project because all future autocompletion will be outdated (like it stopped to update)

By the way, maybe it’s related to https://github.com/godotengine/godot/issues/78003

I tested with the 4.1Beta, it still present

(First issue, I hope it’s complete enough 😄)

Steps to reproduce

  • Download the sample project
  • Rename get_num to get_numb (or something else) in MyClassA
  • Try to autocomplete in MyClassB script after classA.classB.classA.

Minimal reproduction project

Issue.zip

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 4
  • Comments: 15 (5 by maintainers)

Most upvoted comments

Just tried with the Godot 4.1 RC 1, and it’s still there

I tried to reproduce on master using the scripts that have no cyclic reference, and wasn’t able to. Using the mrp from the original issue which has cyclic references, I was able to.

When auto completion shows old names, outdated class types are set by the analyzer. This happens because the new parser created by code_completion is not part of the GDScriptCache, so when the analyzer encounters the same type which is currently completed on, it will use an old parser ref from the script, which might still have some old class types, depending on the idle parse time (I could only reproduce when being fast enough, and also needed some tries before it happened). Invalidating the gdscript cache for the current script when autocompleting could probably solve this issue.

On a different note, with #84266 I wasn’t able to reproduce even with the cyclic references, I suppose it forces an update on the cache. This isn’t the correct fix for this issue though.

Also the bug I found here, does not really fit all users who reported on having this problem in this thread. There have been some fixes with GDScript caching so I could imagine, that some more grave issues were already fixed by them. Did anyone with the problem give it a try with the last dev build?

I think I’m running into this quite a bit, I’m running on a modified version of 4.3dev3 and was wondering if something I did in my modifications was causing the behavior but after looking at this and other similar issues it seems to be a known issue. I find myself restarting the editor a lot when coding. If I’m mostly in the same file it’s fine, but the moment I need to edit a file that’s referenced by a lot of others, I ran into the issue and have to restart.

Since the restart seems to fix it I guess a possible solution would be some sort of “clean and rebuild autocomplete cache” or something? Perhaps adding a button to the GDScript “File menu” similar to the existing “Soft Reload Tool Script” but a “Rebuild Autocompletion Cache” button? (When I was trying to find solutions that was one of the first things/places I looked)

I’m not sure if rebuilding the cache matters, I tried deleting and regenerating the .godot folder which contains all cache files but autocompletion remains broken

I think I’m running into this quite a bit, I’m running on a modified version of 4.3dev3 and was wondering if something I did in my modifications was causing the behavior but after looking at this and other similar issues it seems to be a known issue. I find myself restarting the editor a lot when coding. If I’m mostly in the same file it’s fine, but the moment I need to edit a file that’s referenced by a lot of others, I ran into the issue and have to restart.

Since the restart seems to fix it I guess a possible solution would be some sort of “clean and rebuild autocomplete cache” or something? Perhaps adding a button to the GDScript “File menu” similar to the existing “Soft Reload Tool Script” but a “Rebuild Autocompletion Cache” button? (When I was trying to find solutions that was one of the first things/places I looked)

I confirm that the issue is still there in Godot 4.1.1 stable.

Godot v4.1.1.stable - Windows 10.0.22621 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3060 (NVIDIA; 31.0.15.3713) - AMD Ryzen 5 5500 (12 Threads))

class_name Foo extends Node

func bar() -> int:
    return 5
class_name Mob extends Node

@onready var foo: Foo = get_node("Foo")

func _ready():
    foo.bar() // autocomplete succeeds
extends Node

@onready var mob: Mob = get_node("Mob")

func _ready():
    mob.foo.bar() // autocomplete fails