-
Notifications
You must be signed in to change notification settings - Fork 17
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
Generate @Deprecated annotations #334
Conversation
Signed-off-by: Timo Stamm <[email protected]>
Signed-off-by: Timo Stamm <[email protected]>
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. Small (non-blocking) suggestion on deprecation message wording. Feel free to accept suggestions or not.
protoc-gen-connect-kotlin/src/main/kotlin/com/connectrpc/protocgen/connect/Generator.kt
Outdated
Show resolved
Hide resolved
protoc-gen-connect-kotlin/src/main/kotlin/com/connectrpc/protocgen/connect/Generator.kt
Outdated
Show resolved
Hide resolved
protoc-gen-connect-kotlin/src/main/kotlin/com/connectrpc/protocgen/connect/Generator.kt
Outdated
Show resolved
Hide resolved
Looks like you may need to add the "ignore deprecations" annotation at the top of the generated files, like the base protoc plugins do, to fix the CI build issue. |
Signed-off-by: Timo Stamm <[email protected]>
Signed-off-by: Timo Stamm <[email protected]>
@timostamm thanks for tackling this! One question: if a comment exists on the deprecation option in the proto file, or on an rpc definition, would it be feasible to surface that comment as part of the Deprecated annotation in the generated Kotlin code? Ideally, the proto spec itself would support some kind of deprecation message field to define this in a more official way, but I can very easily imagine our developers adding a comment to explain the deprecation and/or point to a replacement, non-deprecated field/rpc call. If there's a way we can include that context in Kotlin, that would be a huge win. Is that possible with what we have today? |
Signed-off-by: Timo Stamm <[email protected]>
Generating |
@erawhctim, I don't even know a language from the top of my head that supports deprecations, but doesn't support deprecation messages. Unfortunately, the option for deprecating elements in Protobuf is typed as a boolean (source), and doesn't allow users or us to provide a description. I think the most reasonable approach for now is to add a comment in the Protobuf source when you set |
Unfortunately, plugins do not have access to such comments. Plugins must inspect a file descriptor's "source code info" to find comments. While "spans" (the location of an element in the source file) are generated for nearly everything, comments are only retained for complete declarations. The field itself is a complete declaration (so it's leading and trailing comments are preserved). But comments for elements inside the field -- like individual options inside the |
This updates the plugin
protoc-gen-connect-kotlin
to generate annotations for deprecated elements. Closes #333.If an RPC is marked deprecated with the option
deprecated = true
, the corresponding member of the generated client interface and implementation is annotated with:@Deprecated("The method is deprecated in the Protobuf source file.")
Deprecating entire services is supported as well. If
deprecated = true
is set on a service, the generated client interface and implementation is annotated with:@Deprecated("The service is deprecated in the Protobuf source file.")
For good measure, deprecating Protobuf files is supported as well. Because
kotlin.Deprecated
is not applicable to files, we annotate every client interface and implementation generated from the file:@Deprecated("The Protobuf source file that defines this service is deprecated.")