From 35802374acb826751f03dd2180b64e89f467e99d Mon Sep 17 00:00:00 2001 From: Yuri Rubinsky Date: Sun, 12 Mar 2023 10:33:38 +0300 Subject: [PATCH] Add coloring for completion of vector components --- core/object/script_language.h | 4 +++- doc/classes/EditorSettings.xml | 3 +++ editor/code_editor.cpp | 4 +++- editor/editor_settings.cpp | 1 + modules/gdscript/gdscript_editor.cpp | 3 +++ modules/gdscript/gdscript_parser.cpp | 13 +++++++++++++ modules/gdscript/gdscript_parser.h | 4 ++++ servers/rendering/shader_language.cpp | 7 ++++--- 8 files changed, 34 insertions(+), 5 deletions(-) diff --git a/core/object/script_language.h b/core/object/script_language.h index ad88c3a7d49..3cac360b1a8 100644 --- a/core/object/script_language.h +++ b/core/object/script_language.h @@ -344,14 +344,16 @@ public: Vector> matches; Vector> last_matches = { { -1, -1 } }; // This value correspond to an impossible match int location = LOCATION_OTHER; + String theme_color_name; CodeCompletionOption() {} - CodeCompletionOption(const String &p_text, CodeCompletionKind p_kind, int p_location = LOCATION_OTHER) { + CodeCompletionOption(const String &p_text, CodeCompletionKind p_kind, int p_location = LOCATION_OTHER, const String &p_theme_color_name = "") { display = p_text; insert_text = p_text; kind = p_kind; location = p_location; + theme_color_name = p_theme_color_name; } TypedArray get_option_characteristics(const String &p_base); diff --git a/doc/classes/EditorSettings.xml b/doc/classes/EditorSettings.xml index 83abc963bb0..aa3bf3c5354 100644 --- a/doc/classes/EditorSettings.xml +++ b/doc/classes/EditorSettings.xml @@ -858,6 +858,9 @@ If [code]true[/code], code completion will be triggered automatically after [member text_editor/completion/code_complete_delay]. If [code]false[/code], you can still trigger completion manually by pressing [kbd]Ctrl + Space[/kbd] ([kbd]Cmd + Space[/kbd] on macOS). + + If [code]true[/code] enables the coloring for some items in the autocompletion suggestions, like vector components. + If [code]true[/code], provides autocompletion suggestions for file paths in methods such as [code]load()[/code] and [code]preload()[/code]. diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 6c5c99698db..2123e79475d 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -938,7 +938,9 @@ void CodeTextEditor::_complete_request() { for (const ScriptLanguage::CodeCompletionOption &e : entries) { Color font_color = completion_font_color; - if (e.insert_text.begins_with("\"") || e.insert_text.begins_with("\'")) { + if (!e.theme_color_name.is_empty() && EDITOR_GET("text_editor/completion/colorize_suggestions")) { + font_color = get_theme_color(e.theme_color_name, SNAME("Editor")); + } else if (e.insert_text.begins_with("\"") || e.insert_text.begins_with("\'")) { font_color = completion_string_color; } else if (e.insert_text.begins_with("#") || e.insert_text.begins_with("//")) { font_color = completion_comment_color; diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index b923566bfac..e042d8570fe 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -609,6 +609,7 @@ void EditorSettings::_load_defaults(Ref p_extra_config) { _initial_set("text_editor/completion/complete_file_paths", true); _initial_set("text_editor/completion/add_type_hints", false); _initial_set("text_editor/completion/use_single_quotes", false); + _initial_set("text_editor/completion/colorize_suggestions", true); // Help _initial_set("text_editor/help/show_help_index", true); diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 3019354d93d..6cad3b2b90b 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -1207,6 +1207,9 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base for (const PropertyInfo &E : members) { if (!String(E.name).contains("/")) { ScriptLanguage::CodeCompletionOption option(E.name, ScriptLanguage::CODE_COMPLETION_KIND_MEMBER); + if (GDScriptParser::theme_color_names.has(E.name)) { + option.theme_color_name = GDScriptParser::theme_color_names[E.name]; + } r_result.insert(option.display, option); } } diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 039d46f6789..a0d02b12b51 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -66,6 +66,10 @@ Variant::Type GDScriptParser::get_builtin_type(const StringName &p_type) { return Variant::VARIANT_MAX; } +#ifdef TOOLS_ENABLED +HashMap GDScriptParser::theme_color_names; +#endif + void GDScriptParser::cleanup() { builtin_types.clear(); } @@ -121,6 +125,15 @@ GDScriptParser::GDScriptParser() { #ifdef DEBUG_ENABLED is_ignoring_warnings = !(bool)GLOBAL_GET("debug/gdscript/warnings/enable"); #endif + +#ifdef TOOLS_ENABLED + if (theme_color_names.is_empty()) { + theme_color_names.insert("x", "axis_x_color"); + theme_color_names.insert("y", "axis_y_color"); + theme_color_names.insert("z", "axis_z_color"); + theme_color_names.insert("w", "axis_w_color"); + } +#endif } GDScriptParser::~GDScriptParser() { diff --git a/modules/gdscript/gdscript_parser.h b/modules/gdscript/gdscript_parser.h index 05c5bc2f114..9690784cba2 100644 --- a/modules/gdscript/gdscript_parser.h +++ b/modules/gdscript/gdscript_parser.h @@ -1540,6 +1540,10 @@ public: int get_last_line_number() const { return current.end_line; } #endif +#ifdef TOOLS_ENABLED + static HashMap theme_color_names; +#endif // TOOLS_ENABLED + GDScriptParser(); ~GDScriptParser(); diff --git a/servers/rendering/shader_language.cpp b/servers/rendering/shader_language.cpp index e9421a435e5..1460a918260 100644 --- a/servers/rendering/shader_language.cpp +++ b/servers/rendering/shader_language.cpp @@ -10497,6 +10497,7 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_ const char colv[4] = { 'r', 'g', 'b', 'a' }; const char coordv[4] = { 'x', 'y', 'z', 'w' }; const char coordt[4] = { 's', 't', 'p', 'q' }; + const String theme_color_names[4] = { "axis_x_color", "axis_y_color", "axis_z_color", "axis_w_color" }; int limit = 0; @@ -10527,9 +10528,9 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_ } for (int i = 0; i < limit; i++) { - r_options->push_back(ScriptLanguage::CodeCompletionOption(String::chr(colv[i]), ScriptLanguage::CODE_COMPLETION_KIND_PLAIN_TEXT)); - r_options->push_back(ScriptLanguage::CodeCompletionOption(String::chr(coordv[i]), ScriptLanguage::CODE_COMPLETION_KIND_PLAIN_TEXT)); - r_options->push_back(ScriptLanguage::CodeCompletionOption(String::chr(coordt[i]), ScriptLanguage::CODE_COMPLETION_KIND_PLAIN_TEXT)); + r_options->push_back(ScriptLanguage::CodeCompletionOption(String::chr(colv[i]), ScriptLanguage::CODE_COMPLETION_KIND_PLAIN_TEXT, ScriptLanguage::LOCATION_OTHER, theme_color_names[i])); + r_options->push_back(ScriptLanguage::CodeCompletionOption(String::chr(coordv[i]), ScriptLanguage::CODE_COMPLETION_KIND_PLAIN_TEXT, ScriptLanguage::LOCATION_OTHER, theme_color_names[i])); + r_options->push_back(ScriptLanguage::CodeCompletionOption(String::chr(coordt[i]), ScriptLanguage::CODE_COMPLETION_KIND_PLAIN_TEXT, ScriptLanguage::LOCATION_OTHER, theme_color_names[i])); } } break;