Skip to content

Commit

Permalink
Merge pull request #945 from Spartan322/4.3.1-cherry-pick/bugs-gdscript
Browse files Browse the repository at this point in the history
[4.3] Cherry-picks for the 4.3 (4.3.1) branch - 1st gdscript bugs batch
  • Loading branch information
Spartan322 authored Jan 23, 2025
2 parents e4ad7ad + bd7961a commit b1a0177
Show file tree
Hide file tree
Showing 89 changed files with 496 additions and 183 deletions.
20 changes: 10 additions & 10 deletions core/variant/variant_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,20 +1042,20 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorInArrayFind<PackedColorArray, Array>>(Variant::OP_IN, Variant::PACKED_COLOR_ARRAY, Variant::ARRAY);
register_op<OperatorEvaluatorInArrayFind<PackedVector4Array, Array>>(Variant::OP_IN, Variant::PACKED_VECTOR4_ARRAY, Variant::ARRAY);

register_op<OperatorEvaluatorInArrayFind<int, PackedByteArray>>(Variant::OP_IN, Variant::INT, Variant::PACKED_BYTE_ARRAY);
register_op<OperatorEvaluatorInArrayFind<float, PackedByteArray>>(Variant::OP_IN, Variant::FLOAT, Variant::PACKED_BYTE_ARRAY);
register_op<OperatorEvaluatorInArrayFind<int64_t, PackedByteArray>>(Variant::OP_IN, Variant::INT, Variant::PACKED_BYTE_ARRAY);
register_op<OperatorEvaluatorInArrayFind<double, PackedByteArray>>(Variant::OP_IN, Variant::FLOAT, Variant::PACKED_BYTE_ARRAY);

register_op<OperatorEvaluatorInArrayFind<int, PackedInt32Array>>(Variant::OP_IN, Variant::INT, Variant::PACKED_INT32_ARRAY);
register_op<OperatorEvaluatorInArrayFind<float, PackedInt32Array>>(Variant::OP_IN, Variant::FLOAT, Variant::PACKED_INT32_ARRAY);
register_op<OperatorEvaluatorInArrayFind<int64_t, PackedInt32Array>>(Variant::OP_IN, Variant::INT, Variant::PACKED_INT32_ARRAY);
register_op<OperatorEvaluatorInArrayFind<double, PackedInt32Array>>(Variant::OP_IN, Variant::FLOAT, Variant::PACKED_INT32_ARRAY);

register_op<OperatorEvaluatorInArrayFind<int, PackedInt64Array>>(Variant::OP_IN, Variant::INT, Variant::PACKED_INT64_ARRAY);
register_op<OperatorEvaluatorInArrayFind<float, PackedInt64Array>>(Variant::OP_IN, Variant::FLOAT, Variant::PACKED_INT64_ARRAY);
register_op<OperatorEvaluatorInArrayFind<int64_t, PackedInt64Array>>(Variant::OP_IN, Variant::INT, Variant::PACKED_INT64_ARRAY);
register_op<OperatorEvaluatorInArrayFind<double, PackedInt64Array>>(Variant::OP_IN, Variant::FLOAT, Variant::PACKED_INT64_ARRAY);

register_op<OperatorEvaluatorInArrayFind<int, PackedFloat32Array>>(Variant::OP_IN, Variant::INT, Variant::PACKED_FLOAT32_ARRAY);
register_op<OperatorEvaluatorInArrayFind<float, PackedFloat32Array>>(Variant::OP_IN, Variant::FLOAT, Variant::PACKED_FLOAT32_ARRAY);
register_op<OperatorEvaluatorInArrayFind<int64_t, PackedFloat32Array>>(Variant::OP_IN, Variant::INT, Variant::PACKED_FLOAT32_ARRAY);
register_op<OperatorEvaluatorInArrayFind<double, PackedFloat32Array>>(Variant::OP_IN, Variant::FLOAT, Variant::PACKED_FLOAT32_ARRAY);

register_op<OperatorEvaluatorInArrayFind<int, PackedFloat64Array>>(Variant::OP_IN, Variant::INT, Variant::PACKED_FLOAT64_ARRAY);
register_op<OperatorEvaluatorInArrayFind<float, PackedFloat64Array>>(Variant::OP_IN, Variant::FLOAT, Variant::PACKED_FLOAT64_ARRAY);
register_op<OperatorEvaluatorInArrayFind<int64_t, PackedFloat64Array>>(Variant::OP_IN, Variant::INT, Variant::PACKED_FLOAT64_ARRAY);
register_op<OperatorEvaluatorInArrayFind<double, PackedFloat64Array>>(Variant::OP_IN, Variant::FLOAT, Variant::PACKED_FLOAT64_ARRAY);

register_op<OperatorEvaluatorInArrayFind<String, PackedStringArray>>(Variant::OP_IN, Variant::STRING, Variant::PACKED_STRING_ARRAY);
register_op<OperatorEvaluatorInArrayFind<StringName, PackedStringArray>>(Variant::OP_IN, Variant::STRING_NAME, Variant::PACKED_STRING_ARRAY);
Expand Down
40 changes: 25 additions & 15 deletions editor/code_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ void GotoLineDialog::ok_pressed() {
text_editor->remove_secondary_carets();
text_editor->unfold_line(line_number);
text_editor->set_caret_line(line_number);
text_editor->set_code_hint("");
text_editor->cancel_code_completion();
hide();
}

Expand Down Expand Up @@ -177,6 +179,8 @@ bool FindReplaceBar::_search(uint32_t p_flags, int p_from_line, int p_from_col)
text_editor->unfold_line(pos.y);
text_editor->select(pos.y, pos.x, pos.y, pos.x + text.length());
text_editor->center_viewport_to_caret(0);
text_editor->set_code_hint("");
text_editor->cancel_code_completion();

line_col_changed_for_result = true;
}
Expand Down Expand Up @@ -1301,23 +1305,35 @@ void CodeTextEditor::toggle_inline_comment(const String &delimiter) {
text_editor->end_complex_operation();
}

void CodeTextEditor::goto_line(int p_line) {
void CodeTextEditor::goto_line(int p_line, int p_column) {
text_editor->remove_secondary_carets();
text_editor->deselect();
text_editor->unfold_line(p_line);
callable_mp((TextEdit *)text_editor, &TextEdit::set_caret_line).call_deferred(p_line, true, true, 0, 0);
text_editor->unfold_line(CLAMP(p_line, 0, text_editor->get_line_count() - 1));
text_editor->set_caret_line(p_line, false);
text_editor->set_caret_column(p_column, false);
text_editor->set_code_hint("");
text_editor->cancel_code_completion();
// Defer in case the CodeEdit was just created and needs to be resized.
callable_mp((TextEdit *)text_editor, &TextEdit::adjust_viewport_to_caret).call_deferred(0);
}

void CodeTextEditor::goto_line_selection(int p_line, int p_begin, int p_end) {
text_editor->remove_secondary_carets();
text_editor->unfold_line(p_line);
callable_mp((TextEdit *)text_editor, &TextEdit::set_caret_line).call_deferred(p_line, true, true, 0, 0);
callable_mp((TextEdit *)text_editor, &TextEdit::set_caret_column).call_deferred(p_begin, true, 0);
text_editor->unfold_line(CLAMP(p_line, 0, text_editor->get_line_count() - 1));
text_editor->select(p_line, p_begin, p_line, p_end);
text_editor->set_code_hint("");
text_editor->cancel_code_completion();
callable_mp((TextEdit *)text_editor, &TextEdit::adjust_viewport_to_caret).call_deferred(0);
}

void CodeTextEditor::goto_line_centered(int p_line) {
goto_line(p_line);
void CodeTextEditor::goto_line_centered(int p_line, int p_column) {
text_editor->remove_secondary_carets();
text_editor->deselect();
text_editor->unfold_line(CLAMP(p_line, 0, text_editor->get_line_count() - 1));
text_editor->set_caret_line(p_line, false);
text_editor->set_caret_column(p_column, false);
text_editor->set_code_hint("");
text_editor->cancel_code_completion();
callable_mp((TextEdit *)text_editor, &TextEdit::center_viewport_to_caret).call_deferred(0);
}

Expand Down Expand Up @@ -1445,13 +1461,7 @@ void CodeTextEditor::goto_error() {
corrected_column -= tab_count * (indent_size - 1);
}

if (text_editor->get_line_count() != error_line) {
text_editor->unfold_line(error_line);
}
text_editor->remove_secondary_carets();
text_editor->set_caret_line(error_line);
text_editor->set_caret_column(corrected_column);
text_editor->center_viewport_to_caret();
goto_line_centered(error_line, corrected_column);
}
}

Expand Down
4 changes: 2 additions & 2 deletions editor/code_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ class CodeTextEditor : public VBoxContainer {
/// by adding or removing comment delimiter
void toggle_inline_comment(const String &delimiter);

void goto_line(int p_line);
void goto_line(int p_line, int p_column = 0);
void goto_line_selection(int p_line, int p_begin, int p_end);
void goto_line_centered(int p_line);
void goto_line_centered(int p_line, int p_column = 0);
void set_executing_line(int p_line);
void clear_executing_line();

Expand Down
18 changes: 7 additions & 11 deletions editor/plugins/script_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ void ScriptEditor::_goto_script_line(Ref<RefCounted> p_script, int p_line) {
if (ScriptTextEditor *script_text_editor = Object::cast_to<ScriptTextEditor>(current)) {
script_text_editor->goto_line_centered(p_line);
} else if (current) {
current->goto_line(p_line, true);
current->goto_line(p_line);
}

_save_history();
Expand Down Expand Up @@ -1859,17 +1859,13 @@ void ScriptEditor::get_breakpoints(List<String> *p_breakpoints) {
}

void ScriptEditor::_members_overview_selected(int p_idx) {
ScriptEditorBase *se = _get_current_editor();
if (!se) {
return;
int line = members_overview->get_item_metadata(p_idx);
ScriptEditorBase *current = _get_current_editor();
if (ScriptTextEditor *script_text_editor = Object::cast_to<ScriptTextEditor>(current)) {
script_text_editor->goto_line_centered(line);
} else if (current) {
current->goto_line(line);
}
// Go to the member's line and reset the cursor column. We can't change scroll_position
// directly until we have gone to the line first, since code might be folded.
se->goto_line(members_overview->get_item_metadata(p_idx));
Dictionary state = se->get_edit_state();
state["column"] = 0;
state["scroll_position"] = members_overview->get_item_metadata(p_idx);
se->set_edit_state(state);
}

void ScriptEditor::_help_overview_selected(int p_idx) {
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/script_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class ScriptEditorBase : public VBoxContainer {
virtual Variant get_edit_state() = 0;
virtual void set_edit_state(const Variant &p_state) = 0;
virtual Variant get_navigation_state() = 0;
virtual void goto_line(int p_line, bool p_with_error = false) = 0;
virtual void goto_line(int p_line, int p_column = 0) = 0;
virtual void set_executing_line(int p_line) = 0;
virtual void clear_executing_line() = 0;
virtual void trim_trailing_whitespace() = 0;
Expand Down
17 changes: 7 additions & 10 deletions editor/plugins/script_text_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,16 +304,14 @@ void ScriptTextEditor::_warning_clicked(const Variant &p_line) {

void ScriptTextEditor::_error_clicked(const Variant &p_line) {
if (p_line.get_type() == Variant::INT) {
code_editor->get_text_editor()->remove_secondary_carets();
code_editor->get_text_editor()->set_caret_line(p_line.operator int64_t());
goto_line_centered(p_line.operator int64_t());
} else if (p_line.get_type() == Variant::DICTIONARY) {
Dictionary meta = p_line.operator Dictionary();
const String path = meta["path"].operator String();
const int line = meta["line"].operator int64_t();
const int column = meta["column"].operator int64_t();
if (path.is_empty()) {
code_editor->get_text_editor()->remove_secondary_carets();
code_editor->get_text_editor()->set_caret_line(line);
goto_line_centered(line, column);
} else {
Ref<Resource> scr = ResourceLoader::load(path);
if (!scr.is_valid()) {
Expand Down Expand Up @@ -458,16 +456,16 @@ void ScriptTextEditor::tag_saved_version() {
code_editor->get_text_editor()->tag_saved_version();
}

void ScriptTextEditor::goto_line(int p_line, bool p_with_error) {
code_editor->goto_line(p_line);
void ScriptTextEditor::goto_line(int p_line, int p_column) {
code_editor->goto_line(p_line, p_column);
}

void ScriptTextEditor::goto_line_selection(int p_line, int p_begin, int p_end) {
code_editor->goto_line_selection(p_line, p_begin, p_end);
}

void ScriptTextEditor::goto_line_centered(int p_line) {
code_editor->goto_line_centered(p_line);
void ScriptTextEditor::goto_line_centered(int p_line, int p_column) {
code_editor->goto_line_centered(p_line, p_column);
}

void ScriptTextEditor::set_executing_line(int p_line) {
Expand Down Expand Up @@ -921,8 +919,7 @@ void ScriptTextEditor::_breakpoint_item_pressed(int p_idx) {
if (p_idx < 4) { // Any item before the separator.
_edit_option(breakpoints_menu->get_item_id(p_idx));
} else {
code_editor->goto_line(breakpoints_menu->get_item_metadata(p_idx));
callable_mp((TextEdit *)code_editor->get_text_editor(), &TextEdit::center_viewport_to_caret).call_deferred(0); // Needs to be deferred, because goto uses call_deferred().
code_editor->goto_line_centered(breakpoints_menu->get_item_metadata(p_idx));
}
}

Expand Down
4 changes: 2 additions & 2 deletions editor/plugins/script_text_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ class ScriptTextEditor : public ScriptEditorBase {
virtual void convert_indent() override;
virtual void tag_saved_version() override;

virtual void goto_line(int p_line, bool p_with_error = false) override;
virtual void goto_line(int p_line, int p_column = 0) override;
void goto_line_selection(int p_line, int p_begin, int p_end);
void goto_line_centered(int p_line);
void goto_line_centered(int p_line, int p_column = 0);
virtual void set_executing_line(int p_line) override;
virtual void clear_executing_line() override;

Expand Down
4 changes: 2 additions & 2 deletions editor/plugins/text_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ void TextEditor::tag_saved_version() {
code_editor->get_text_editor()->tag_saved_version();
}

void TextEditor::goto_line(int p_line, bool p_with_error) {
code_editor->goto_line(p_line);
void TextEditor::goto_line(int p_line, int p_column) {
code_editor->goto_line(p_line, p_column);
}

void TextEditor::goto_line_selection(int p_line, int p_begin, int p_end) {
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/text_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class TextEditor : public ScriptEditorBase {
virtual PackedInt32Array get_breakpoints() override;
virtual void set_breakpoint(int p_line, bool p_enabled) override{};
virtual void clear_breakpoints() override{};
virtual void goto_line(int p_line, bool p_with_error = false) override;
virtual void goto_line(int p_line, int p_column = 0) override;
void goto_line_selection(int p_line, int p_begin, int p_end);
virtual void set_executing_line(int p_line) override;
virtual void clear_executing_line() override;
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/text_shader_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ void TextShaderEditor::_show_warnings_panel(bool p_show) {

void TextShaderEditor::_warning_clicked(const Variant &p_line) {
if (p_line.get_type() == Variant::INT) {
code_editor->get_text_editor()->set_caret_line(p_line.operator int64_t());
code_editor->goto_line_centered(p_line.operator int64_t());
}
}

Expand Down
31 changes: 29 additions & 2 deletions modules/gdscript/gdscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,16 @@ bool GDScriptNativeClass::_get(const StringName &p_name, Variant &r_ret) const {
if (ok) {
r_ret = v;
return true;
} else {
return false;
}

MethodBind *method = ClassDB::get_method(name, p_name);
if (method && method->is_static()) {
// Native static method.
r_ret = Callable(this, p_name);
return true;
}

return false;
}

void GDScriptNativeClass::_bind_methods() {
Expand Down Expand Up @@ -1056,6 +1063,26 @@ void GDScript::_bind_methods() {
ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "new", &GDScript::_new, MethodInfo("new"));
}

void GDScript::set_path_cache(const String &p_path) {
if (ResourceCache::has(p_path)) {
set_path(p_path, true);
return;
}

if (is_root_script()) {
Script::set_path_cache(p_path);
}

String old_path = path;
path = p_path;
path_valid = true;
GDScriptCache::move_script(old_path, p_path);

for (KeyValue<StringName, Ref<GDScript>> &kv : subclasses) {
kv.value->set_path_cache(p_path);
}
}

void GDScript::set_path(const String &p_path, bool p_take_over) {
if (is_root_script()) {
Script::set_path(p_path, p_take_over);
Expand Down
1 change: 1 addition & 0 deletions modules/gdscript/gdscript.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ class GDScript : public Script {

virtual Error reload(bool p_keep_state = false) override;

virtual void set_path_cache(const String &p_path) override;
virtual void set_path(const String &p_path, bool p_take_over = false) override;
String get_script_path() const;
Error load_source_code(const String &p_path);
Expand Down
15 changes: 12 additions & 3 deletions modules/gdscript/gdscript_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ static GDScriptParser::DataType make_enum_type(const StringName &p_enum_name, co
return type;
}

static GDScriptParser::DataType make_class_enum_type(const StringName &p_enum_name, GDScriptParser::ClassNode *p_class, const String &p_script_path, bool p_meta = true) {
GDScriptParser::DataType type = make_enum_type(p_enum_name, p_class->fqcn, p_meta);

type.class_type = p_class;
type.script_path = p_script_path;

return type;
}

static GDScriptParser::DataType make_native_enum_type(const StringName &p_enum_name, const StringName &p_native_class, bool p_meta = true) {
// Find out which base class declared the enum, so the name is always the same even when coming from other contexts.
StringName native_base = p_native_class;
Expand Down Expand Up @@ -1066,7 +1075,7 @@ void GDScriptAnalyzer::resolve_class_member(GDScriptParser::ClassNode *p_class,
check_class_member_name_conflict(p_class, member.m_enum->identifier->name, member.m_enum);

member.m_enum->set_datatype(resolving_datatype);
GDScriptParser::DataType enum_type = make_enum_type(member.m_enum->identifier->name, p_class->fqcn, true);
GDScriptParser::DataType enum_type = make_class_enum_type(member.m_enum->identifier->name, p_class, parser->script_path, true);

const GDScriptParser::EnumNode *prev_enum = current_enum;
current_enum = member.m_enum;
Expand Down Expand Up @@ -1159,7 +1168,7 @@ void GDScriptAnalyzer::resolve_class_member(GDScriptParser::ClassNode *p_class,
// Also update the original references.
member.enum_value.parent_enum->values.set(member.enum_value.index, member.enum_value);

member.enum_value.identifier->set_datatype(make_enum_type(UNNAMED_ENUM, p_class->fqcn, false));
member.enum_value.identifier->set_datatype(make_class_enum_type(UNNAMED_ENUM, p_class, parser->script_path, false));
} break;
case GDScriptParser::ClassNode::Member::CLASS:
check_class_member_name_conflict(p_class, member.m_class->identifier->name, member.m_class);
Expand Down Expand Up @@ -4135,7 +4144,7 @@ void GDScriptAnalyzer::reduce_identifier(GDScriptParser::IdentifierNode *p_ident
const GDScriptParser::EnumNode::Value &element = current_enum->values[i];
if (element.identifier->name == p_identifier->name) {
StringName enum_name = current_enum->identifier ? current_enum->identifier->name : UNNAMED_ENUM;
GDScriptParser::DataType type = make_enum_type(enum_name, parser->current_class->fqcn, false);
GDScriptParser::DataType type = make_class_enum_type(enum_name, parser->current_class, parser->script_path, false);
if (element.parent_enum->identifier) {
type.enum_type = element.parent_enum->identifier->name;
}
Expand Down
3 changes: 2 additions & 1 deletion modules/gdscript/gdscript_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ Ref<GDScript> GDScriptCache::get_shallow_script(const String &p_path, Error &r_e

Ref<GDScript> script;
script.instantiate();
script->set_path(p_path, true);
script->set_path_cache(p_path);
if (remapped_path.get_extension().to_lower() == "gdc") {
Vector<uint8_t> buffer = get_binary_tokens(remapped_path);
if (buffer.is_empty()) {
Expand Down Expand Up @@ -362,6 +362,7 @@ Ref<GDScript> GDScriptCache::get_full_script(const String &p_path, Error &r_erro
return script;
}
}
script->set_path(p_path, true);

const String remapped_path = ResourceLoader::path_remap(p_path);

Expand Down
Loading

0 comments on commit b1a0177

Please sign in to comment.