-
-
Notifications
You must be signed in to change notification settings - Fork 23.6k
GDScript: Add an @override annotation for enforcing proper override semantics
#110133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| if (function_node->is_static) { | ||
| push_error(R"("@override" annotation cannot be applied to static functions.)", p_annotation); | ||
| return false; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should probably also add an exclusion rule for @abstract here, since an abstract method can never override something.
8ed9856 to
a1bd733
Compare
f96ee6f to
dd4696b
Compare
| _add_code_completion_option(p_type, p_display_text, p_insert_text, p_text_color, p_icon, p_value, p_location, {}); | ||
| } | ||
|
|
||
| void CodeEdit::_add_code_completion_option(CodeCompletionKind p_type, const String &p_display_text, const String &p_insert_text, const Color &p_text_color, const Ref<Resource> &p_icon, const Variant &p_value, int p_location, const Vector<ScriptLanguage::TextEdit> &additional_edits) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This happened because I didn't know how to properly get TextEdit and CodePos exposed to scripting, and add_code_completion_option is available to scripting. The ClassDB bind methods are unable to handle the extra default argument, so the original add_code_completion_option became a bouncer to this method.
| for (const ScriptLanguage::TextEdit &edit : selected_option.additional_edits) { | ||
| ScriptLanguage::CodePos start = edit.start; | ||
| ScriptLanguage::CodePos end = edit.end; | ||
|
|
||
| int nb_lines = this->get_text().size(); | ||
|
|
||
| this->remove_text(start.line, start.column, end.line, end.column); | ||
| this->insert_text(edit.new_text, start.line, start.column); | ||
|
|
||
| int new_nb_lines = this->get_text().size(); | ||
| // TODO: Does the caret magically move or do we need to update it? | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another mental TODO here is that this currently applies each time for a multi-caret completion.
Given that the positions in ScriptLanguage::TextEdit are absolute, and are not aware of the fact that a completion could be used for multiple carets, we might want to only apply them once after all carets have completed
|
Salvages #103859 |
dd4696b to
0ca3bfa
Compare
0ca3bfa to
6d2dbb8
Compare
@override annotation for enforcing proper override semantics@override annotation for enforcing proper override semantics
|
Haven't checked your codes but I'm not sure if there is a method list with methods defined in the parent when |
This PR adds the
@overrideannotation, which is used to enforce that a method overrides a method in a parent class. A method that is declared@overridebut does not actually override anything will be treated as an error.Methods that override without explicitly declaring
@overridewill trigger anIMPLICIT_FUNCTION_OVERRIDEwarning.To support this feature, this PR also adds a new feature to
CodeCompletionOption- anon_appliedcallback. This can be used to make additional changes in the editor after the suggestion has been applied. TheGDScriptLanguagemakes use of this to automatically apply the@overrideannotation when generating a stub for a method override.Partially addresses godotengine/godot-proposals#12310