You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-21 14:57:09 +00:00
Merge pull request #97168 from Hilderin/fix-reloading-scripts-already-in-use
Fix reloading scripts already in use
This commit is contained in:
@@ -1974,18 +1974,16 @@ void EditorFileSystem::_update_script_documentation() {
|
||||
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
|
||||
ScriptLanguage *lang = ScriptServer::get_language(i);
|
||||
if (lang->supports_documentation() && efd->files[index]->type == lang->get_type()) {
|
||||
// Reloading the script from disk if resource already in memory. Otherwise, the
|
||||
// ResourceLoader::load will return the last loaded version of the script (without the modifications).
|
||||
// The only have the script already loaded here is to edit the script outside the
|
||||
// editor without being connected to the LSP server.
|
||||
Ref<Resource> res = ResourceCache::get_ref(path);
|
||||
if (res.is_valid()) {
|
||||
res->reload_from_file();
|
||||
}
|
||||
bool should_reload_script = _should_reload_script(path);
|
||||
Ref<Script> scr = ResourceLoader::load(path);
|
||||
if (scr.is_null()) {
|
||||
continue;
|
||||
}
|
||||
if (should_reload_script) {
|
||||
// Reloading the script from disk. Otherwise, the ResourceLoader::load will
|
||||
// return the last loaded version of the script (without the modifications).
|
||||
scr->reload_from_file();
|
||||
}
|
||||
Vector<DocData::ClassDoc> docs = scr->get_documentation();
|
||||
for (int j = 0; j < docs.size(); j++) {
|
||||
EditorHelp::get_doc_data()->add_doc(docs[j]);
|
||||
@@ -2007,6 +2005,25 @@ void EditorFileSystem::_update_script_documentation() {
|
||||
update_script_paths_documentation.clear();
|
||||
}
|
||||
|
||||
bool EditorFileSystem::_should_reload_script(const String &p_path) {
|
||||
if (first_scan) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Ref<Script> scr = ResourceCache::get_ref(p_path);
|
||||
if (scr.is_null()) {
|
||||
// Not a script or not already loaded.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Scripts are reloaded via the script editor if they are currently opened.
|
||||
if (ScriptEditor::get_singleton()->get_open_scripts().has(scr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void EditorFileSystem::_process_update_pending() {
|
||||
_update_script_classes();
|
||||
// Parse documentation second, as it requires the class names to be loaded
|
||||
|
||||
Reference in New Issue
Block a user