How can I force Godot script editor to reload script's source code?

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

I’m trying to create a code-generation editor plugin, somewhat similar in nature to what “connect signal” dialog does, when it appends a connected method to the script.

I’m at a point, where I have a Script object, and can actually modify its source code. But my changes aren’t immediately visible in the Godot script editor. So far I’ve tried changing the Script.source_code property; calling emit_changed() on a Script after I perform my modifications; using File and re-writing the source code on the filesystem; calling update_file() on EditorFileSystem; calling edit_script() on EditorInterface; and various combinations of all of these.

No matter what I do, my changes to the script sourcecode become visible only if I either close the script in the editor and reopen it from the scene explorer, or if I alt-tab to a different window and then back to Godot again.

How can I achieve behavior similar to what “Connect a Signal to a Method” dialog does?

:bust_in_silhouette: Reply From: dmitriy_shmilo

Found it! It’s an undocumented private function in \editor\plugins\script_editor_plugin.cpp called _reload_scripts.

Looking for this in Godot 4.x in 2024. Also need to refresh (or at least close/open) a script that is in the Script Editor which I am changing via a gdscript tool.

Can’t find this func anymore. There is (in the cpp source) EditorInterface.get_script_editor().reload_scripts() but it refuses to work.