Skip to content
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

[Editor] Fix return of EditorTranslationParserPlugin._get_comments #99297

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AThousandShips
Copy link
Member

@AThousandShips AThousandShips commented Nov 15, 2024

Method used passed arguments as return data which does not work with extensions, switched to using a Dictionary return. This might work in extensions after fixing typed array copying, but unsure, and I think this return format is safer in any case to use, and is the standard in most of the virtual methods like this (also any binding for this will have to use const_cast as the resulting methods will pass as const TypedArray<String> &)

Follow-up to:

See also:

Method used passed arguments as return data which does not work with
extensions, switched to using a `Dictionary` return.
<description>
If overridden, called after [method _parse_file] to get comments for the parsed entries. This method should fill the arrays with the same number of elements and in the same order as [method _parse_file].
If overridden, called after [method _parse_file] to get comments for the parsed entries. This method should fill the arrays with the same number of elements and in the same order as [method _parse_file]. The returned [Dictionary] should contain two elements, [code]msgids_comment[/code] and [code]msgids_context_plural_comment[/code] each a typed [Array] of [String]s.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure what exactly this should say but started out with this

for (int i = 0; i < ids_comment.size(); i++) {
r_ids_comment->append(ids_comment[i]);
if (GDVIRTUAL_CALL(_get_comments, ret)) {
if (ret.has("msgids_comment")) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure if this should error if we don't have these, if so I'll change it

@AThousandShips AThousandShips requested review from a team and dalexeev November 15, 2024 19:23
@AThousandShips
Copy link
Member Author

To illustrate the issue, this is the signature of the related _parse_file method, which is being fixed in the related PR:

        virtual void _parse_file(const String &p_path, const TypedArray<String> &p_msgids, const TypedArray<Array> &p_msgids_context_plural);

Haven't generated the headers for the current state but _get_comments will have the same signature and you need to const_cast those arguments, which is very unintuitive and fragile

@dalexeev
Copy link
Member

dalexeev commented Nov 19, 2024

I'm not familiar with the GDExtension issue, but it looks good to me as long as _get_comments() is consistent with _parse_file() (so I would prefer #92175 to be merged or at least approved first). However, I have a question:

  1. If we decide to break _parse_file() compatibility, maybe it makes sense to combine _parse_file() and _get_comments() into a single method that returns a table (Array[PackedStringArray], Array[Array], or Array[Dictionary]) with the columns msgid, msgctxt, msgid_plural, and comment? The required column would be msgid, the others can be left blank. I don't think it makes sense to separate msgids and msgids_context_plural as it is now, because it's all a single table under the hood anyway.
  2. If we want to maintain maximum compatibility, we could add a _parse_file_ext() or _parse_file_2() method and deprecate _parse_file(). This is more related to Fix some arguments being passed as references in virtual functions #92175, as _get_comments() did not appear in any stable release.

@AThousandShips
Copy link
Member Author

AThousandShips commented Nov 19, 2024

That makes sense, will test some alternatives for deprecation and update as needed

I'm not familiar enough with the code here to say if merging the two methods into one is feasible, but if it is might merging the two, dropping _get_comments and deprecating _parse_file, work?

The new method could be _parse_file_and_comments or something, would be less obscure to have as a replacement maybe

That way we could possibly detect if _parse_file_and_comments or what we call it is bound, and otherwise call the outdated one

Would depend on if we consider deprecation worth it, unsure what happens in other languages but it is possible to use it in godot-cpp but requires casting, I don't know how it works in C# though so confirming how the current methods work or don't work for plugins made in C# would be good

It does seem that these cases do work with plugins in GDScript so that's a reason to deprecate over entirely replacing, but will test with GDScript soon to confirm

@raulsntos
Copy link
Member

I don't know how it works in C# though so confirming how the current methods work or don't work for plugins made in C# would be good

I haven't tested personally but since Arrays in C# are reference types I imagine they may work. #99195 uses the method so, assuming the PR works, it would prove that the method works in C#.

Also, how is the GDExtension validation not complaining about breaking compatibility? Does it not check virtual methods?

@dalexeev
Copy link
Member

Also, how is the GDExtension validation not complaining about breaking compatibility? Does it not check virtual methods?

EditorTranslationParserPlugin._get_comments() is not in 4.3 stable. Only #92175 breaks compatibility, this PR can be considered as a non-breaking part of #92175.

@dalexeev
Copy link
Member

I'm not familiar enough with the code here to say if merging the two methods into one is feasible, but if it is might merging the two, dropping _get_comments and deprecating _parse_file, work?

The new method could be _parse_file_and_comments or something, would be less obscure to have as a replacement maybe

That way we could possibly detect if _parse_file_and_comments or what we call it is bound, and otherwise call the outdated one

I guess it depends on how we handle other cases in #92175. Yes, the fact that it seems to work in GDScript and C# is an argument for deprecation instead of removal/replacement. However, I don't think EditorTranslationParserPlugin is used very often, so breaking compatibility there is more acceptable than with core APIs like Object, Node, etc.

@AThousandShips
Copy link
Member Author

I'll see about some options today for this and #92175

@AThousandShips
Copy link
Member Author

AThousandShips commented Dec 3, 2024

Will try investigate this properly this week

Edit: haven't been able to find the time to investigate this yet but will try next week

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants