-
Notifications
You must be signed in to change notification settings - Fork 69
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
V2: Support option retention #827
Conversation
// Our goal is to provide options with source retention to plugin authors. | ||
// CodeGeneratorRequest.proto_file elides options with source retention for | ||
// files to generate. For these files, we take the file from source_file_descriptors, | ||
// which does include options with source retention. | ||
const allProtoWithSourceOptions = request.protoFile.map((protoFile) => { | ||
const sourceFile = request.sourceFileDescriptors.find( | ||
(s) => s.name == protoFile.name, | ||
); | ||
return sourceFile ?? protoFile; | ||
}); |
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 is backwards compatible. Old compilers will not populate source_file_descriptors
, and we keep using proto_file
.
function getFileDescCall(f: GeneratedFile, file: DescFile, schema: Schema) { | ||
const sourceFile = file.proto; | ||
const runtimeFile = schema.proto.protoFile.find(f => f.name == sourceFile.name); | ||
const info = embedFileDesc(runtimeFile ?? sourceFile); |
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 removes source retention options from embedded file descriptors generated by protoc-gen-es. We simply do the reverse of packages/protoplugin/src/ecmascript/schema.ts:223.
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.
Might be worth a comment in here about why we want the version in schema.proto.protoFile
instead of the provided file.proto
, because it would already have omitted source-only options.
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 call, added in 2ca5ebd
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
function getFileDescCall(f: GeneratedFile, file: DescFile, schema: Schema) { | ||
const sourceFile = file.proto; | ||
const runtimeFile = schema.proto.protoFile.find(f => f.name == sourceFile.name); | ||
const info = embedFileDesc(runtimeFile ?? sourceFile); |
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.
Might be worth a comment in here about why we want the version in schema.proto.protoFile
instead of the provided file.proto
, because it would already have omitted source-only options.
This PR adds support for option retention: Options can specify whether they should be included in generated code (making them accessible at runtime), or be only available for plugins, while generating code.
With this change, options that specify
retention = RETENTION_SOURCE
are available in plugins written on top of @bufbuild/protoplugin. But they will not be included in the code generated by protoc-gen-es.