Merge pull request #69550 from Rindbee/fix-script-editor-not-reload-via-lsp

Fix internal editor not updating when using external editor via LSP
This commit is contained in:
Rémi Verschelde 2023-02-09 14:01:33 +01:00 committed by GitHub
commit b12bf7ff02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 7 deletions

View file

@ -2528,7 +2528,7 @@ void ScriptEditor::reload_scripts(bool p_refresh_only) {
} }
Ref<Script> scr = edited_res; Ref<Script> scr = edited_res;
if (scr != nullptr) { if (scr.is_valid()) {
Ref<Script> rel_scr = ResourceLoader::load(scr->get_path(), scr->get_class(), ResourceFormatLoader::CACHE_MODE_IGNORE); Ref<Script> rel_scr = ResourceLoader::load(scr->get_path(), scr->get_class(), ResourceFormatLoader::CACHE_MODE_IGNORE);
ERR_CONTINUE(!rel_scr.is_valid()); ERR_CONTINUE(!rel_scr.is_valid());
scr->set_source_code(rel_scr->get_source_code()); scr->set_source_code(rel_scr->get_source_code());
@ -2537,12 +2537,8 @@ void ScriptEditor::reload_scripts(bool p_refresh_only) {
} }
Ref<TextFile> text_file = edited_res; Ref<TextFile> text_file = edited_res;
if (text_file != nullptr) { if (text_file.is_valid()) {
Error err; text_file->reload_from_file();
Ref<TextFile> rel_text_file = _load_text_file(text_file->get_path(), &err);
ERR_CONTINUE(!rel_text_file.is_valid());
text_file->set_text(rel_text_file->get_text());
text_file->set_last_modified_time(rel_text_file->get_last_modified_time());
} }
} }

View file

@ -108,6 +108,7 @@ void GDScriptTextDocument::didSave(const Variant &p_param) {
scr->reload(true); scr->reload(true);
} }
scr->update_exports(); scr->update_exports();
ScriptEditor::get_singleton()->reload_scripts(true);
ScriptEditor::get_singleton()->update_docs_from_script(scr); ScriptEditor::get_singleton()->update_docs_from_script(scr);
} }
} }

View file

@ -67,5 +67,10 @@ Error TextFile::load_text(const String &p_path) {
ERR_FAIL_COND_V_MSG(s.parse_utf8((const char *)w) != OK, ERR_INVALID_DATA, "Script '" + p_path + "' contains invalid unicode (UTF-8), so it was not loaded. Please ensure that scripts are saved in valid UTF-8 unicode."); ERR_FAIL_COND_V_MSG(s.parse_utf8((const char *)w) != OK, ERR_INVALID_DATA, "Script '" + p_path + "' contains invalid unicode (UTF-8), so it was not loaded. Please ensure that scripts are saved in valid UTF-8 unicode.");
text = s; text = s;
path = p_path; path = p_path;
#ifdef TOOLS_ENABLED
if (ResourceLoader::get_timestamp_on_load()) {
set_last_modified_time(FileAccess::get_modified_time(path));
}
#endif // TOOLS_ENABLED
return OK; return OK;
} }