summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuri Rubinsky <chaosus89@gmail.com>2023-03-12 10:33:38 +0300
committerYuri Roubinski <chaosus89@gmail.com>2023-08-30 21:13:25 +0300
commit35802374acb826751f03dd2180b64e89f467e99d (patch)
tree5f533547a65615f7dee35e9cb5c68ac8f297a7c4
parentf7c48cf8039d07f113d38cf9115547a75ea1d3c9 (diff)
downloadredot-engine-35802374acb826751f03dd2180b64e89f467e99d.tar.gz
Add coloring for completion of vector components
-rw-r--r--core/object/script_language.h4
-rw-r--r--doc/classes/EditorSettings.xml3
-rw-r--r--editor/code_editor.cpp4
-rw-r--r--editor/editor_settings.cpp1
-rw-r--r--modules/gdscript/gdscript_editor.cpp3
-rw-r--r--modules/gdscript/gdscript_parser.cpp13
-rw-r--r--modules/gdscript/gdscript_parser.h4
-rw-r--r--servers/rendering/shader_language.cpp7
8 files changed, 34 insertions, 5 deletions
diff --git a/core/object/script_language.h b/core/object/script_language.h
index ad88c3a7d4..3cac360b1a 100644
--- a/core/object/script_language.h
+++ b/core/object/script_language.h
@@ -344,14 +344,16 @@ public:
Vector<Pair<int, int>> matches;
Vector<Pair<int, int>> 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<int> get_option_characteristics(const String &p_base);
diff --git a/doc/classes/EditorSettings.xml b/doc/classes/EditorSettings.xml
index 83abc963bb..aa3bf3c535 100644
--- a/doc/classes/EditorSettings.xml
+++ b/doc/classes/EditorSettings.xml
@@ -858,6 +858,9 @@
<member name="text_editor/completion/code_complete_enabled" type="bool" setter="" getter="">
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).
</member>
+ <member name="text_editor/completion/colorize_suggestions" type="bool" setter="" getter="">
+ If [code]true[/code] enables the coloring for some items in the autocompletion suggestions, like vector components.
+ </member>
<member name="text_editor/completion/complete_file_paths" type="bool" setter="" getter="">
If [code]true[/code], provides autocompletion suggestions for file paths in methods such as [code]load()[/code] and [code]preload()[/code].
</member>
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp
index 6c5c99698d..2123e79475 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 b923566bfa..e042d8570f 100644
--- a/editor/editor_settings.cpp
+++ b/editor/editor_settings.cpp
@@ -609,6 +609,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> 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 3019354d93..6cad3b2b90 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 039d46f678..a0d02b12b5 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<String, String> 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 05c5bc2f11..9690784cba 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<String, String> theme_color_names;
+#endif // TOOLS_ENABLED
+
GDScriptParser();
~GDScriptParser();
diff --git a/servers/rendering/shader_language.cpp b/servers/rendering/shader_language.cpp
index e9421a435e..1460a91826 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;