Skip to content

Commit

Permalink
Merge pull request #74809 from Chaosus/completion_color_xyzw
Browse files Browse the repository at this point in the history
Add coloring for completion of vector components
  • Loading branch information
akien-mga committed Sep 4, 2023
2 parents fa3428f + 3580237 commit dd4fae6
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 5 deletions.
4 changes: 3 additions & 1 deletion core/object/script_language.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,14 +344,16 @@ class ScriptLanguage : public Object {
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);
Expand Down
3 changes: 3 additions & 0 deletions doc/classes/EditorSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
4 changes: 3 additions & 1 deletion editor/code_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions editor/editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions modules/gdscript/gdscript_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
13 changes: 13 additions & 0 deletions modules/gdscript/gdscript_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 4 additions & 0 deletions modules/gdscript/gdscript_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,10 @@ class GDScriptParser {
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();

Expand Down
7 changes: 4 additions & 3 deletions servers/rendering/shader_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit dd4fae6

Please sign in to comment.