Skip to content

Expose reload_scripts as reload_open_files - #83267

Closed
KANAjetzt wants to merge 1 commit into
godotengine:masterfrom
KANAjetzt:feat_expose_reload_scripts
Closed

KANAjetzt wants to merge 1 commit into
godotengine:masterfrom
KANAjetzt:feat_expose_reload_scripts

Conversation

@KANAjetzt

@KANAjetzt KANAjetzt commented Oct 13, 2023 •

Copy link
Copy Markdown
Contributor

Expose the reload_scripts method to match the current state of the 3.x branch.

As described in #83118, it is possible to replicate this method with GDScript:

static func reload_script(text_edit: TextEdit, source_code: String) -> void:
	var column := text_edit.get_caret_column()
	var row := text_edit.get_caret_line()
	var scroll_position_h := text_edit.get_h_scroll_bar().value
	var scroll_position_v := text_edit.get_v_scroll_bar().value

	text_edit.text = source_code
	text_edit.set_caret_column(column)
	text_edit.set_caret_line(row)
	text_edit.scroll_horizontal = scroll_position_h
	text_edit.scroll_vertical = scroll_position_v

	text_edit.tag_saved_version()

and set the text_editor/behavior/files/auto_reload_scripts_on_external_change setting to true.

Personally, I would prefer calling EditorInterface.get_script_editor().reload_scripts(), but I might not be aware of possible pitfalls caused by exposing this method.

This would also improve the porting of existing 3.5 plugins.

closes godotengine/godot-proposals#8111

@KANAjetzt
KANAjetzt requested review from a team as code owners October 13, 2023 13:41
@AThousandShips

AThousandShips commented Oct 13, 2023 •

Copy link
Copy Markdown
Member

Please remove the special characters from the commit message and make it match the title of the PR

Also please open a proper proposal as asked on the issue, having a proper proposal where the proper arguments for this feature is important to gauge if this is needed

Comment thread editor/plugins/script_editor_plugin.cpp Outdated
Comment thread doc/classes/ScriptEditor.xml Outdated
@AThousandShips

AThousandShips commented Oct 13, 2023 •

Copy link
Copy Markdown
Member

@twaritwaikar do you recall if exposing this (i.e. making public) in 3.x was meant to be used in scripting, or was it renamed since it was made public on the c++ side?

This was done in #53900 but only for the 3.x side, so the fact that this was not done in 4.x to me implies that it was not intended to be exposed as such

Edit: these changes were ported to 4.x in #62157 where this was not exposed

@Qubus0

Qubus0 commented Oct 13, 2023

Copy link
Copy Markdown

This is useful (and used) for all plugins that modify any (active) scripts.
I'm not sure why it would not be intended to be exposed. Would there be any downside to having it exposed or is it a case of needing a certain degree of usefulness to be justified?

@AThousandShips

Copy link
Copy Markdown
Member

Exposing internal methods, especially in the editor, binds the development to maintain compatibility and stability, so that's why I asked for a proposal to gauge the need and justification for this

If it can be worked around, how needed it is, etc.

Because exposing a method isn't a trivial thing that comes with possible issues and a burden of maintenance

@KANAjetzt
KANAjetzt force-pushed the feat_expose_reload_scripts branch from 2f93ffe to 3a245a9 Compare October 14, 2023 10:33
@KANAjetzt

Copy link
Copy Markdown
Contributor Author

What can I do to make the Linux check pass?

@AThousandShips

Copy link
Copy Markdown
Member

See the error message, you need to reorder the entries of the documentation, they need to be ge sorted

@KANAjetzt

KANAjetzt commented Oct 17, 2023 •

Copy link
Copy Markdown
Contributor Author

Sorry for that unnecessary check, I hope I got it now 😅
The doctool got stuck when trying to delete the cache while VSCode was running.

@Paulb23

Paulb23 commented Oct 29, 2023

Copy link
Copy Markdown
Member

Don't see a solid reason against exposing this for plugins, but I'm thinking we should start moving away from the script naming in this file a little bit as reload_scripts doesn't just reload Script, but any open file i.e TextFile and JSON.

So we should bind it as reload_open_files or something along those lines.

@KANAjetzt
KANAjetzt force-pushed the feat_expose_reload_scripts branch 2 times, most recently from 467d9ea to 5e07dcb Compare October 30, 2023 10:07
@KANAjetzt KANAjetzt changed the title Expose ScriptEditor.reload_scripts() Expose reload_scripts as reload_open_files Oct 30, 2023
@KANAjetzt

Copy link
Copy Markdown
Contributor Author

Thanks, @Paulb23 - I went ahead and changed it to your suggestion. Is there something to do now on the project converter side?

@KANAjetzt
KANAjetzt force-pushed the feat_expose_reload_scripts branch 2 times, most recently from 04d8004 to 7631d87 Compare March 18, 2024 16:05
@KANAjetzt

Copy link
Copy Markdown
Contributor Author

I added the function to the rename map, I hope we can get this merged for 4.3 👀

Comment thread doc/classes/ScriptEditor.xml Outdated
@KANAjetzt
KANAjetzt force-pushed the feat_expose_reload_scripts branch from e369043 to 2687a6c Compare April 27, 2024 20:41
Expose the reload_scripts method to match the current state of the 3.x branch.
Bind it as `reload_open_files` in contrast to `reload_scripts` in 3.x to more accurately reflect its function.

closes godotengine/godot-proposals#8111

clarifies the description of the method's internals

Co-authored-by: Chris Cranford <ccranfor@redhat.com>
@KANAjetzt
KANAjetzt force-pushed the feat_expose_reload_scripts branch from 2687a6c to 8c32133 Compare September 8, 2024 20:17
@svetogam

Copy link
Copy Markdown

The absence of this feature is painful to me. Two of my plugins would benefit from it. I hope it can get merged soon!

@Zephilinox

Copy link
Copy Markdown
Contributor

I also need this, my usecase is generating gdscript code in open files. the file on disk and the data in memory is updated, but the opened scripts in the editor do not get updated

@Naros

Naros commented Sep 17, 2025

Copy link
Copy Markdown
Contributor

Correct me, but isn't this now exposed in ScriptLanguageExtension::_reload_scripts ?

@Zephilinox

Copy link
Copy Markdown
Contributor

I did try that before but it didn't work. I suspect it's referring to script resources, and not the open script in the script editor, or maybe it's broken or I'm using it wrong 😂

@dawdle-deer

Copy link
Copy Markdown
Contributor

Correct me, but isn't this now exposed in ScriptLanguageExtension::_reload_scripts ?

ScriptLanguageExtension is undocumented, so I'm shooting in the dark to an extent, but I believe it's unrelated. Internally, when changes to gdscript files are saved, a call is made to GDScriptTextDocument::reload_script, which calls ScriptEditor::get_singleton()->reload_scripts(true). It would make sense to expose this API in a similarly simple fashion.

@dawdle-deer dawdle-deer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@akien-mga
akien-mga requested a review from KoBeWi December 1, 2025 20:00
@Qubus0

Qubus0 commented Dec 1, 2025

Copy link
Copy Markdown

Correct me, but isn't this now exposed in ScriptLanguageExtension::_reload_scripts ?

reload_open_files reloads script editors, not the scripts themselves. changes to the script are applied just fine, but if a script is changed programmatically (ex: preprocessors) and still open in a text editor, the editor doesn't update, forcing you to close and reopen to get the new changes. if you accidentally save it'll just override those changes

@kitbdev kitbdev left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can cause unsaved changes to be lost without confirmation.
It would be better to expose _test_script_times_on_disk (and maybe _update_modified_scripts_for_external_editor which is usually called after it?, effectively _on_find_in_files_modified_files) if needed.

text_editor/behavior/files/auto_reload_scripts_on_external_change is now true by default, so it won't show the confirmation dialog unless its unsaved.

A workaround is to send the ScriptEditor NOTIFICATION_APPLICATION_FOCUS_IN, since it calls _test_script_times_on_disk:

EditorInterface.get_script_editor().notification(Window.NOTIFICATION_APPLICATION_FOCUS_IN)

<param index="0" name="refresh_only" type="bool" default="false" />
<description>
Reload all currently opened files if [param refresh_only] is [code]false[/code]. When [param refresh_only] is [code]true[/code], only modified files are reloaded.
[b]Note:[/b] This method has no effect if an external editor is currently active.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does work when an external editor is active.

@KANAjetzt

Copy link
Copy Markdown
Contributor Author

@kitbdev Thanks for your comment, sounds good to me. If you have a full picture of how to best expose this to plugin devs, feel free to open a new PR with your suggestions. It has been a while since I looked at the engine code, but I am also happy to dive back in if necessary.

@Repiteo

Repiteo commented Feb 19, 2026

Copy link
Copy Markdown
Contributor

Superseded by #116187; thanks for your contribution!

@Repiteo Repiteo closed this Feb 19, 2026
@Repiteo Repiteo removed this from the 4.x milestone Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose ScriptEditor.reload_scripts()

10 participants