diff --git a/core/script_language.h b/core/script_language.h index ec06e1355d..314b047027 100644 --- a/core/script_language.h +++ b/core/script_language.h @@ -256,6 +256,7 @@ struct ScriptCodeCompletionOption { Kind kind = KIND_PLAIN_TEXT; String display; String insert_text; + Color font_color; RES icon; ScriptCodeCompletionOption() {} diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 9e1a5f2d43..d8648310b6 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -837,7 +837,14 @@ void CodeTextEditor::_complete_request() { } for (List::Element *E = entries.front(); E; E = E->next()) { - E->get().icon = _get_completion_icon(E->get()); + ScriptCodeCompletionOption *e = &E->get(); + e->icon = _get_completion_icon(*e); + e->font_color = completion_font_color; + if (e->insert_text.begins_with("\"") || e->insert_text.begins_with("\'")) { + e->font_color = completion_string_color; + } else if (e->insert_text.begins_with("#") || e->insert_text.begins_with("//")) { + e->font_color = completion_comment_color; + } } text_editor->code_complete(entries, forced); } @@ -910,7 +917,10 @@ bool CodeTextEditor::_add_font_size(int p_delta) { } void CodeTextEditor::update_editor_settings() { - text_editor->set_syntax_coloring(EditorSettings::get_singleton()->get("text_editor/highlighting/syntax_highlighting")); + completion_font_color = EDITOR_GET("text_editor/highlighting/completion_font_color"); + completion_string_color = EDITOR_GET("text_editor/highlighting/string_color"); + completion_comment_color = EDITOR_GET("text_editor/highlighting/comment_color"); + text_editor->set_highlight_all_occurrences(EditorSettings::get_singleton()->get("text_editor/highlighting/highlight_all_occurrences")); text_editor->set_highlight_current_line(EditorSettings::get_singleton()->get("text_editor/highlighting/highlight_current_line")); text_editor->set_indent_using_spaces(EditorSettings::get_singleton()->get("text_editor/indent/type")); @@ -1407,11 +1417,8 @@ Variant CodeTextEditor::get_edit_state() { state["breakpoints"] = text_editor->get_breakpoints_array(); state["bookmarks"] = text_editor->get_bookmarks_array(); - state["syntax_highlighter"] = TTR("Standard"); - Ref syntax_highlighter = text_editor->get_syntax_highlighting(); - if (syntax_highlighter.is_valid()) { - state["syntax_highlighter"] = syntax_highlighter->_get_name(); - } + Ref syntax_highlighter = text_editor->get_syntax_highlighter(); + state["syntax_highlighter"] = syntax_highlighter->_get_name(); return state; } diff --git a/editor/code_editor.h b/editor/code_editor.h index d3090b28c1..450c85c64b 100644 --- a/editor/code_editor.h +++ b/editor/code_editor.h @@ -174,6 +174,9 @@ class CodeTextEditor : public VBoxContainer { void _zoom_changed(); void _reset_zoom(); + Color completion_font_color; + Color completion_string_color; + Color completion_comment_color; CodeTextEditorCodeCompleteFunc code_complete_func; void *code_complete_ud; diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 2f669d9006..0da7e5210a 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -3603,6 +3603,7 @@ void EditorNode::register_editor_types() { ClassDB::register_class(); ClassDB::register_virtual_class(); ClassDB::register_virtual_class(); + ClassDB::register_class(); ClassDB::register_virtual_class(); ClassDB::register_class(); ClassDB::register_class(); diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 5f293f1fb3..3a1a0d5b01 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -420,7 +420,6 @@ void EditorSettings::_load_defaults(Ref p_extra_config) { _load_default_text_editor_theme(); // Highlighting - _initial_set("text_editor/highlighting/syntax_highlighting", true); _initial_set("text_editor/highlighting/highlight_all_occurrences", true); _initial_set("text_editor/highlighting/highlight_current_line", true); _initial_set("text_editor/highlighting/highlight_type_safe_lines", true); diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 237aefb1b9..67268e0027 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -51,6 +51,165 @@ #include "servers/display_server.h" #include "text_editor.h" +/*** SYNTAX HIGHLIGHTER ****/ + +String EditorSyntaxHighlighter::_get_name() const { + ScriptInstance *si = get_script_instance(); + if (si && si->has_method("_get_name")) { + return si->call("_get_name"); + } + return "Unnamed"; +} + +Array EditorSyntaxHighlighter::_get_supported_languages() const { + ScriptInstance *si = get_script_instance(); + if (si && si->has_method("_get_supported_languages")) { + return si->call("_get_supported_languages"); + } + return Array(); +} + +Ref EditorSyntaxHighlighter::_create() const { + Ref syntax_highlighter; + syntax_highlighter.instance(); + if (get_script_instance()) { + syntax_highlighter->set_script(get_script_instance()->get_script()); + } + return syntax_highlighter; +} + +void EditorSyntaxHighlighter::_bind_methods() { + ClassDB::bind_method(D_METHOD("_get_edited_resource"), &EditorSyntaxHighlighter::_get_edited_resource); + + BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_name")); + BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_supported_languages")); + BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_supported_extentions")); +} + +//// + +void EditorStandardSyntaxHighlighter::_update_cache() { + highlighter->set_text_edit(text_edit); + highlighter->clear_keyword_colors(); + highlighter->clear_member_keyword_colors(); + highlighter->clear_color_regions(); + + highlighter->set_symbol_color(EDITOR_GET("text_editor/highlighting/symbol_color")); + highlighter->set_function_color(EDITOR_GET("text_editor/highlighting/function_color")); + highlighter->set_number_color(EDITOR_GET("text_editor/highlighting/number_color")); + highlighter->set_member_variable_color(EDITOR_GET("text_editor/highlighting/member_variable_color")); + + /* Engine types. */ + const Color type_color = EDITOR_GET("text_editor/highlighting/engine_type_color"); + List types; + ClassDB::get_class_list(&types); + for (List::Element *E = types.front(); E; E = E->next()) { + String n = E->get(); + if (n.begins_with("_")) { + n = n.substr(1, n.length()); + } + highlighter->add_keyword_color(n, type_color); + } + + /* User types. */ + const Color usertype_color = EDITOR_GET("text_editor/highlighting/user_type_color"); + List global_classes; + ScriptServer::get_global_class_list(&global_classes); + for (List::Element *E = global_classes.front(); E; E = E->next()) { + highlighter->add_keyword_color(E->get(), usertype_color); + } + + /* Autoloads. */ + Map autoloads = ProjectSettings::get_singleton()->get_autoload_list(); + for (Map::Element *E = autoloads.front(); E; E = E->next()) { + const ProjectSettings::AutoloadInfo &info = E->value(); + if (info.is_singleton) { + highlighter->add_keyword_color(info.name, usertype_color); + } + } + + const Ref