-
Notifications
You must be signed in to change notification settings - Fork 24
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
Add deprecation annotations for RPCs marked "deprecated=true" #316
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,6 +119,9 @@ final class ConnectClientGenerator: Generator { | |
private func printCallbackMethodInterface(for method: MethodDescriptor) { | ||
self.printLine() | ||
self.printCommentsIfNeeded(for: method) | ||
if let availabilityAnnotation = method.callbackAvailabilityAnnotation() { | ||
self.printLine(availabilityAnnotation) | ||
} | ||
if !method.serverStreaming && !method.clientStreaming { | ||
self.printLine("@discardableResult") | ||
} | ||
|
@@ -133,7 +136,7 @@ final class ConnectClientGenerator: Generator { | |
private func printAsyncAwaitMethodInterface(for method: MethodDescriptor) { | ||
self.printLine() | ||
self.printCommentsIfNeeded(for: method) | ||
self.printLine("@available(iOS 13, *)") | ||
self.printLine(method.asyncAwaitAvailabilityAnnotation()) | ||
self.printLine( | ||
method.asyncAwaitSignature( | ||
using: self.namer, includeDefaults: false, options: self.options | ||
|
@@ -143,6 +146,9 @@ final class ConnectClientGenerator: Generator { | |
|
||
private func printCallbackMethodImplementation(for method: MethodDescriptor) { | ||
self.printLine() | ||
if let availabilityAnnotation = method.callbackAvailabilityAnnotation() { | ||
self.printLine(availabilityAnnotation) | ||
} | ||
if !method.serverStreaming && !method.clientStreaming { | ||
self.printLine("@discardableResult") | ||
} | ||
|
@@ -162,7 +168,7 @@ final class ConnectClientGenerator: Generator { | |
|
||
private func printAsyncAwaitMethodImplementation(for method: MethodDescriptor) { | ||
self.printLine() | ||
self.printLine("@available(iOS 13, *)") | ||
self.printLine(method.asyncAwaitAvailabilityAnnotation()) | ||
self.printLine( | ||
"\(self.visibility) " | ||
+ method.asyncAwaitSignature( | ||
|
@@ -201,6 +207,30 @@ private extension MethodDescriptor { | |
} | ||
} | ||
|
||
func callbackAvailabilityAnnotation() -> String? { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think all these helper functions can be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I left them without explicit access to align with the functions that were already there; however, I think we're good on not needing to specify access level since the enclosing extension There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah didn't realize these were inside a private extension 👍🏽 |
||
if self.options.deprecated { | ||
// swiftlint:disable line_length | ||
return """ | ||
@available(iOS, introduced: 12, deprecated: 12, message: "This RPC has been marked as deprecated in its `.proto` file.") | ||
@available(macOS, introduced: 10.15, deprecated: 10.15, message: "This RPC has been marked as deprecated in its `.proto` file.") | ||
@available(tvOS, introduced: 13, deprecated: 13, message: "This RPC has been marked as deprecated in its `.proto` file.") | ||
@available(watchOS, introduced: 6, deprecated: 6, message: "This RPC has been marked as deprecated in its `.proto` file.") | ||
""" | ||
// swiftlint:enable line_length | ||
} else { | ||
return nil | ||
} | ||
} | ||
|
||
func asyncAwaitAvailabilityAnnotation() -> String { | ||
if self.options.deprecated { | ||
// swiftlint:disable:next line_length | ||
return "@available(iOS, introduced: 13, deprecated: 13, message: \"This RPC has been marked as deprecated in its `.proto` file.\")" | ||
} else { | ||
return "@available(iOS 13, *)" | ||
} | ||
} | ||
|
||
func callbackReturnValue() -> String { | ||
if self.clientStreaming && self.serverStreaming { | ||
return """ | ||
|
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.
@rebello95 @jhump Let me know if this is acceptable. I use SwiftLint in my own repos as well, so I know the rules exist for a purpose; however, I may propose disabling this specific rule in this specific context to improve legibility in the editor and to more closely mimic what will actually be output at the time of generation.
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 seems fine to me, doing additional gymnastics would be a bit excessive 😉