Add coloring for completion of vector components

This commit is contained in:
Yuri Rubinsky 2023-03-12 10:33:38 +03:00 committed by Yuri Roubinski
parent f7c48cf803
commit 35802374ac
8 changed files with 34 additions and 5 deletions

View File

@ -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);

View File

@ -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>

View File

@ -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;

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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() {

View File

@ -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();

View File

@ -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;