cel-go icon indicating copy to clipboard operation
cel-go copied to clipboard

Allow TypeProvider to iterate over message fields

Open JimLarson opened this issue 5 years ago • 2 comments

Feature request checklist

  • [X] There are no issues that match the desired change
  • [X] The change is large enough it can't be addressed with a simple Pull Request
  • [X] If this is a bug, please file a Bug Report.

Change There is currently no way in the TypeProvider interface to discover the fields available in a message.

Example

for _, field := range provider.MessageFields(msgName) {
        fieldType, found := provider.FindFieldType(msgName, field)
        ...do something with field...
}

Alternatives considered Could use proto reflection if you have an instance about, but won't work for a compiler server where foreign proto definitions are imported by FileDescriptorSet.

JimLarson avatar Jul 10 '20 23:07 JimLarson

Most of what you need will be easily accessible in the pb/type.go once #399 is checked in. The one question I have is whether you want to use the ref.FieldType or if you want the pb.FieldDescription which provides much more information.

The reason I ask is because we have a few options available to accomplish this:

  • Pass a pb.Db directly into the NewRegistry call, no interface change to speak of.
  • Make it possible to iterate over the fields in of any type and expose FindTypeFields(typeName string) on the TypeProvider

I prefer the former since it's a smaller API surface change and it shouldn't impact custom ref.TypeProvider implementations at all. Thoughts?

TristonianJones avatar Dec 09 '20 19:12 TristonianJones

Just the field name is sufficient - I think we can get what we need from the TypeProvider interface once we have the name.

JimLarson avatar Dec 09 '20 23:12 JimLarson