Editting Script from Tool doesn't update opened script in Script Editor

Godot Version

4.4

Question

Hi there, I’ve been building a custom script editor addon, but encountering an issue where if the script I’m editting in my tool saves is open in the Script Editor, the changes aren’t reflected.

  • It does change if the script I’m editting was closed initially.
  • It does not change if the script was opened initially and then closed and reopened.
    I’ve tried a number of things at the end of saving like:
	ResourceLoader.load(path, "", ResourceLoader.CACHE_MODE_REPLACE)
	EditorInterface.get_resource_filesystem().update_file(script_file.resource_path)
	script_file.reload()

what does help is if I add

EditorInterface.get_resource_filesystem().reimport_files([script_file.resource_path])

But this requires closing and reopening the script. Which I thought I could maybe work with if I can find a solution to closing and reopening the script through code, but can’t find any solutions for that.