Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regression with C# build editor crash due to EditorHelpHighlighter #89861

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions editor/editor_help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3471,7 +3471,9 @@ EditorHelpHighlighter::HighlightData EditorHelpHighlighter::_get_highlight_data(
}

text_edits[p_language]->set_text(p_source);
scripts[p_language]->set_source_code(p_source);
if (scripts[p_language].is_valid()) { // See GH-89610.
scripts[p_language]->set_source_code(p_source);
}
highlighters[p_language]->_update_cache();

HighlightData result;
Expand Down Expand Up @@ -3561,31 +3563,29 @@ EditorHelpHighlighter::EditorHelpHighlighter() {
#ifdef MODULE_MONO_ENABLED
TextEdit *csharp_text_edit = memnew(TextEdit);

Ref<CSharpScript> csharp;
csharp.instantiate();
// See GH-89610.
//Ref<CSharpScript> csharp;
//csharp.instantiate();

Ref<EditorStandardSyntaxHighlighter> csharp_highlighter;
csharp_highlighter.instantiate();
csharp_highlighter->set_text_edit(csharp_text_edit);
csharp_highlighter->_set_edited_resource(csharp);
//csharp_highlighter->_set_edited_resource(csharp);
csharp_highlighter->_set_script_language(CSharpLanguage::get_singleton());

text_edits[LANGUAGE_CSHARP] = csharp_text_edit;
scripts[LANGUAGE_CSHARP] = csharp;
//scripts[LANGUAGE_CSHARP] = csharp;
highlighters[LANGUAGE_CSHARP] = csharp_highlighter;
#endif
}

EditorHelpHighlighter::~EditorHelpHighlighter() {
#ifdef MODULE_GDSCRIPT_ENABLED
memdelete(text_edits[LANGUAGE_GDSCRIPT]);
scripts[LANGUAGE_GDSCRIPT].unref();
highlighters[LANGUAGE_GDSCRIPT].unref();
#endif

#ifdef MODULE_MONO_ENABLED
memdelete(text_edits[LANGUAGE_CSHARP]);
scripts[LANGUAGE_CSHARP].unref();
highlighters[LANGUAGE_CSHARP].unref();
#endif
}

Expand Down
27 changes: 18 additions & 9 deletions editor/plugins/script_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,22 @@ void EditorStandardSyntaxHighlighter::_update_cache() {
}
}

const Ref<Script> scr = _get_edited_resource();
if (scr.is_valid()) {
const ScriptLanguage *scr_lang = script_language;
StringName instance_base;

if (scr_lang == nullptr) {
const Ref<Script> scr = _get_edited_resource();
if (scr.is_valid()) {
scr_lang = scr->get_language();
instance_base = scr->get_instance_base_type();
}
}

if (scr_lang != nullptr) {
/* Core types. */
const Color basetype_color = EDITOR_GET("text_editor/theme/highlighting/base_type_color");
List<String> core_types;
scr->get_language()->get_core_type_words(&core_types);
scr_lang->get_core_type_words(&core_types);
for (const String &E : core_types) {
highlighter->add_keyword_color(E, basetype_color);
}
Expand All @@ -151,9 +161,9 @@ void EditorStandardSyntaxHighlighter::_update_cache() {
const Color keyword_color = EDITOR_GET("text_editor/theme/highlighting/keyword_color");
const Color control_flow_keyword_color = EDITOR_GET("text_editor/theme/highlighting/control_flow_keyword_color");
List<String> keywords;
scr->get_language()->get_reserved_words(&keywords);
scr_lang->get_reserved_words(&keywords);
for (const String &E : keywords) {
if (scr->get_language()->is_control_flow_keyword(E)) {
if (scr_lang->is_control_flow_keyword(E)) {
highlighter->add_keyword_color(E, control_flow_keyword_color);
} else {
highlighter->add_keyword_color(E, keyword_color);
Expand All @@ -162,7 +172,6 @@ void EditorStandardSyntaxHighlighter::_update_cache() {

/* Member types. */
const Color member_variable_color = EDITOR_GET("text_editor/theme/highlighting/member_variable_color");
StringName instance_base = scr->get_instance_base_type();
if (instance_base != StringName()) {
List<PropertyInfo> plist;
ClassDB::get_property_list(instance_base, &plist);
Expand All @@ -187,7 +196,7 @@ void EditorStandardSyntaxHighlighter::_update_cache() {
/* Comments */
const Color comment_color = EDITOR_GET("text_editor/theme/highlighting/comment_color");
List<String> comments;
scr->get_language()->get_comment_delimiters(&comments);
scr_lang->get_comment_delimiters(&comments);
for (const String &comment : comments) {
String beg = comment.get_slice(" ", 0);
String end = comment.get_slice_count(" ") > 1 ? comment.get_slice(" ", 1) : String();
Expand All @@ -197,7 +206,7 @@ void EditorStandardSyntaxHighlighter::_update_cache() {
/* Doc comments */
const Color doc_comment_color = EDITOR_GET("text_editor/theme/highlighting/doc_comment_color");
List<String> doc_comments;
scr->get_language()->get_doc_comment_delimiters(&doc_comments);
scr_lang->get_doc_comment_delimiters(&doc_comments);
for (const String &doc_comment : doc_comments) {
String beg = doc_comment.get_slice(" ", 0);
String end = doc_comment.get_slice_count(" ") > 1 ? doc_comment.get_slice(" ", 1) : String();
Expand All @@ -207,7 +216,7 @@ void EditorStandardSyntaxHighlighter::_update_cache() {
/* Strings */
const Color string_color = EDITOR_GET("text_editor/theme/highlighting/string_color");
List<String> strings;
scr->get_language()->get_string_delimiters(&strings);
scr_lang->get_string_delimiters(&strings);
for (const String &string : strings) {
String beg = string.get_slice(" ", 0);
String end = string.get_slice_count(" ") > 1 ? string.get_slice(" ", 1) : String();
Expand Down
3 changes: 3 additions & 0 deletions editor/plugins/script_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class EditorStandardSyntaxHighlighter : public EditorSyntaxHighlighter {

private:
Ref<CodeHighlighter> highlighter;
ScriptLanguage *script_language = nullptr; // See GH-89610.

public:
virtual void _update_cache() override;
Expand All @@ -87,6 +88,8 @@ class EditorStandardSyntaxHighlighter : public EditorSyntaxHighlighter {

virtual Ref<EditorSyntaxHighlighter> _create() const override;

void _set_script_language(ScriptLanguage *p_script_language) { script_language = p_script_language; }

EditorStandardSyntaxHighlighter() { highlighter.instantiate(); }
};

Expand Down
Loading