Repository: godotengine/godot
File: scene/gui/code_edit.cpp (C++)

Code before:
						code_completion_rect.position.y = caret_pos.y + (theme_cache.line_spacing / 2.0f);
						if (draw_code_hint && code_hint_draw_below) {
							code_completion_rect.position.y += code_hint_minsize.y;
						}
					}

					const int scroll_width = code_completion_options_count > theme_cache.code_completion_max_lines ? theme_cache.code_completion_scroll_width : 0;
					const int code_completion_base_width = theme_cache.font->get_string_size(code_completion_base, HORIZONTAL_ALIGNMENT_LEFT, -1, theme_cache.font_size).width;
					if (caret_pos.x - code_completion_base_width + code_completion_rect.size.width + scroll_width > get_size().width) {
						code_completion_rect.position.x = get_size().width - code_completion_rect.size.width - scroll_width;
					} else {
						code_completion_rect.position.x = caret_pos.x - code_completion_base_width;
					}

					draw_style_box(theme_cache.code_completion_style, Rect2(code_completion_rect.position - theme_cache.code_completion_style->get_offset(), code_completion_rect.size + theme_cache.code_completion_style->get_minimum_size() + Size2(scroll_width, 0)));
					if (theme_cache.code_completion_background_color.a > 0.01) {
						RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(code_completion_rect.position, code_completion_rect.size + Size2(scroll_width, 0)), theme_cache.code_completion_background_color);
					}

					code_completion_scroll_rect.position = code_completion_rect.position + Vector2(code_completion_rect.size.width, 0);
					code_completion_scroll_rect.size = Vector2(scroll_width, code_completion_rect.size.height);

					code_completion_line_ofs = CLAMP((code_completion_force_item_center < 0 ? code_completion_current_selected : code_completion_force_item_center) - lines / 2, 0, code_completion_options_count - lines);
					RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(code_completion_rect.position.x, code_completion_rect.position.y + (code_completion_current_selected - code_completion_line_ofs) * row_height), Size2(code_completion_rect.size.width, row_height)), theme_cache.code_completion_selected_color);

					const String &lang = TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain())->get_locale();
					for (int i = 0; i < lines; i++) {
						int l = code_completion_line_ofs + i;
						ERR_CONTINUE(l < 0 || l >= code_completion_options_count);

						Ref<TextLine> tl;
						tl.instantiate();
						tl->add_string(code_completion_options[l].display, theme_cache.font, theme_cache.font_size, lang);

						int yofs = (row_height - tl->get_size().y) / 2;
						Point2 title_pos(code_completion_rect.position.x, code_completion_rect.position.y + i * row_height + yofs);

						/* Draw completion icon if it is valid. */
						const Ref<Texture2D> &icon = code_completion_options[l].icon;
						Rect2 icon_area(code_completion_rect.position.x, code_completion_rect.position.y + i * row_height, icon_area_size.width, icon_area_size.height);
						if (icon.is_valid()) {
							Size2 icon_size = icon_area.size * 0.7;
							icon->draw_rect(ci, Rect2(icon_area.position + (icon_area.size - icon_size) / 2, icon_size));
						}
						title_pos.x = icon_area.position.x + icon_area.size.width + theme_cache.code_completion_icon_separation;

						tl->set_width(code_completion_rect.size.width - (icon_area_size.x + theme_cache.code_completion_icon_separation));
						if (rtl) {
							if (code_completion_options[l].default_value.get_type() == Variant::COLOR) {
								draw_rect(Rect2(Point2(code_completion_rect.position.x, icon_area.position.y), icon_area_size), (Color)code_completion_options[l].default_value);
							}

Review comment (refactor):
`TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain())->get_locale()` could be some helper method in Control, it's verbose and repeated everywhere.

Code after:
						if (draw_code_hint && code_hint_draw_below) {
							code_completion_rect.position.y += code_hint_minsize.y;
						}
					}

					const int scroll_width = code_completion_options_count > theme_cache.code_completion_max_lines ? theme_cache.code_completion_scroll_width : 0;
					const int code_completion_base_width = theme_cache.font->get_string_size(code_completion_base, HORIZONTAL_ALIGNMENT_LEFT, -1, theme_cache.font_size).width;
					if (caret_pos.x - code_completion_base_width + code_completion_rect.size.width + scroll_width > get_size().width) {
						code_completion_rect.position.x = get_size().width - code_completion_rect.size.width - scroll_width;
					} else {
						code_completion_rect.position.x = caret_pos.x - code_completion_base_width;
					}

					draw_style_box(theme_cache.code_completion_style, Rect2(code_completion_rect.position - theme_cache.code_completion_style->get_offset(), code_completion_rect.size + theme_cache.code_completion_style->get_minimum_size() + Size2(scroll_width, 0)));
					if (theme_cache.code_completion_background_color.a > 0.01) {
						RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(code_completion_rect.position, code_completion_rect.size + Size2(scroll_width, 0)), theme_cache.code_completion_background_color);
					}

					code_completion_scroll_rect.position = code_completion_rect.position + Vector2(code_completion_rect.size.width, 0);
					code_completion_scroll_rect.size = Vector2(scroll_width, code_completion_rect.size.height);

					code_completion_line_ofs = CLAMP((code_completion_force_item_center < 0 ? code_completion_current_selected : code_completion_force_item_center) - lines / 2, 0, code_completion_options_count - lines);
					RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(code_completion_rect.position.x, code_completion_rect.position.y + (code_completion_current_selected - code_completion_line_ofs) * row_height), Size2(code_completion_rect.size.width, row_height)), theme_cache.code_completion_selected_color);

					const String &lang = _get_locale();
					for (int i = 0; i < lines; i++) {
						int l = code_completion_line_ofs + i;
						ERR_CONTINUE(l < 0 || l >= code_completion_options_count);

						Ref<TextLine> tl;
						tl.instantiate();
						tl->add_string(code_completion_options[l].display, theme_cache.font, theme_cache.font_size, lang);

						int yofs = (row_height - tl->get_size().y) / 2;
						Point2 title_pos(code_completion_rect.position.x, code_completion_rect.position.y + i * row_height + yofs);

						/* Draw completion icon if it is valid. */
						const Ref<Texture2D> &icon = code_completion_options[l].icon;
						Rect2 icon_area(code_completion_rect.position.x, code_completion_rect.position.y + i * row_height, icon_area_size.width, icon_area_size.height);
						if (icon.is_valid()) {
							Size2 icon_size = icon_area.size * 0.7;
							icon->draw_rect(ci, Rect2(icon_area.position + (icon_area.size - icon_size) / 2, icon_size));
						}
						title_pos.x = icon_area.position.x + icon_area.size.width + theme_cache.code_completion_icon_separation;

						tl->set_width(code_completion_rect.size.width - (icon_area_size.x + theme_cache.code_completion_icon_separation));
						if (rtl) {
							if (code_completion_options[l].default_value.get_type() == Variant::COLOR) {
								draw_rect(Rect2(Point2(code_completion_rect.position.x, icon_area.position.y), icon_area_size), (Color)code_completion_options[l].default_value);
							}
							tl->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_RIGHT);