-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
feat: Value Renderer for repeated #13604
feat: Value Renderer for repeated #13604
Conversation
4a39d19
to
4fcbfd3
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #13604 +/- ##
==========================================
+ Coverage 56.25% 56.71% +0.45%
==========================================
Files 667 647 -20
Lines 56576 55435 -1141
==========================================
- Hits 31829 31441 -388
+ Misses 22165 21423 -742
+ Partials 2582 2571 -11
|
5d7f0fa
to
7e018a6
Compare
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.
Nice! Left some comments
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.
Looking good! I left a comment about removing Kind()
from the interface.
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.
Good progress, and good to hear that you're working on the parse.
@@ -0,0 +1,157 @@ | |||
[ |
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.
Add these test cases to message.json
instead of using a separate file - allows us to reuse the same test driver code.
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'm not sure I agree with this one. I still think the reason we put repeated logic in messageValueRenderer is an implementation detail. Conceptually, I prefer them to be 2 different value renderers. I'd love to know how JS implements this.
@@ -0,0 +1,157 @@ | |||
[ |
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'm not sure I agree with this one. I still think the reason we put repeated logic in messageValueRenderer is an implementation detail. Conceptually, I prefer them to be 2 different value renderers. I'd love to know how JS implements this.
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 overall LGTM! Nice progress on this PR.
My only requested change is to think about the ParseRepeated function signature.
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.
Approving, thanks @joeabbey!
Just asked a question if we should be more rigorous in Parse, but I'm fine with the current version
func (mr *messageValueRenderer) parseRepeated(ctx context.Context, screens []Screen, l protoreflect.List, vr ValueRenderer) error { | ||
|
||
// <int> <field_kind> | ||
headerRegex := *regexp.MustCompile(`(\d+) .+`) |
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.
Should parse check that <field_kind> is correct too? We would need to pass fd protoreflect.FieldDescriptor
as an arg too.
Maybe it's fine for Parse to not be that strict.
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.
What's the criteria for <field_kind>
? We should perhaps add it into the regex. Also we need to ensure that the regex begins with an integer or permit spaces but essentially perhaps this
headerRegex := regexp.MustCompile(`^\s*(\d+) (\w+|\d+)`)
and no need to dereference the result from regexp.MustCompile.
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.
The field kind is documented in Annex 1 of ADR 50:
field_kind:
- if the type of the repeated field is a message, field_kind is the message name
- if the type of the repeated field is an enum, field_kind is the enum name
- in any other case, field_kind is the protobuf primitive type (e.g. "string" or "bytes")
@facundomedica I'm assigning you here too (if you have bandwidth), since you said you might be interested in looking into Textual. |
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.
Thank you for this change @joeabbey and great to bump into you here!
I've added some suggestions, please take a look.
func (mr *messageValueRenderer) parseRepeated(ctx context.Context, screens []Screen, l protoreflect.List, vr ValueRenderer) error { | ||
|
||
// <int> <field_kind> | ||
headerRegex := *regexp.MustCompile(`(\d+) .+`) |
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.
What's the criteria for <field_kind>
? We should perhaps add it into the regex. Also we need to ensure that the regex begins with an integer or permit spaces but essentially perhaps this
headerRegex := regexp.MustCompile(`^\s*(\d+) (\w+|\d+)`)
and no need to dereference the result from regexp.MustCompile.
5d1cd9d
to
14c5057
Compare
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.
LGTM, the test proto doesn't seem well formatted but we can solve that later
{ | ||
return NewIntValueRenderer(), nil | ||
} | ||
return NewIntValueRenderer(), nil | ||
|
||
case fd.Kind() == protoreflect.StringKind: |
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.
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.
Thanks! I'll fix it in my PR then: #13600
closes #12714
Next steps: