Procházet zdrojové kódy

Refactor some of the client code generation (#856)

Motivation:

In the future it might be useful to generate some of the client code in
multiple places.

Modifications:

- Split up the client code gen to print such that there are separate
  methods to print RPC methods
- The style of the generated code changed slightly too, to match the
  rest of the style
- Regenerate code

Result:

- We can avoid repeating ourselve in the future
- No functional change
George Barnett před 5 roky
rodič
revize
2e35e1d155

+ 36 - 17
Sources/Examples/Echo/Model/echo.grpc.swift

@@ -55,10 +55,15 @@ public final class Echo_EchoClient: GRPCClient, Echo_EchoClientProtocol {
   ///   - request: Request to send to Get.
   ///   - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
   /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
-  public func get(_ request: Echo_EchoRequest, callOptions: CallOptions? = nil) -> UnaryCall<Echo_EchoRequest, Echo_EchoResponse> {
-    return self.makeUnaryCall(path: "/echo.Echo/Get",
-                              request: request,
-                              callOptions: callOptions ?? self.defaultCallOptions)
+  public func get(
+    _ request: Echo_EchoRequest,
+    callOptions: CallOptions? = nil
+  ) -> UnaryCall<Echo_EchoRequest, Echo_EchoResponse> {
+    return self.makeUnaryCall(
+      path: "/echo.Echo/Get",
+      request: request,
+      callOptions: callOptions ?? self.defaultCallOptions
+    )
   }
 
   /// Splits a request into words and returns each word in a stream of messages.
@@ -68,11 +73,17 @@ public final class Echo_EchoClient: GRPCClient, Echo_EchoClientProtocol {
   ///   - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
   ///   - handler: A closure called when each response is received from the server.
   /// - Returns: A `ServerStreamingCall` with futures for the metadata and status.
-  public func expand(_ request: Echo_EchoRequest, callOptions: CallOptions? = nil, handler: @escaping (Echo_EchoResponse) -> Void) -> ServerStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
-    return self.makeServerStreamingCall(path: "/echo.Echo/Expand",
-                                        request: request,
-                                        callOptions: callOptions ?? self.defaultCallOptions,
-                                        handler: handler)
+  public func expand(
+    _ request: Echo_EchoRequest,
+    callOptions: CallOptions? = nil,
+    handler: @escaping (Echo_EchoResponse) -> Void
+  ) -> ServerStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
+    return self.makeServerStreamingCall(
+      path: "/echo.Echo/Expand",
+      request: request,
+      callOptions: callOptions ?? self.defaultCallOptions,
+      handler: handler
+    )
   }
 
   /// Collects a stream of messages and returns them concatenated when the caller closes.
@@ -83,9 +94,13 @@ public final class Echo_EchoClient: GRPCClient, Echo_EchoClientProtocol {
   /// - Parameters:
   ///   - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
   /// - Returns: A `ClientStreamingCall` with futures for the metadata, status and response.
-  public func collect(callOptions: CallOptions? = nil) -> ClientStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
-    return self.makeClientStreamingCall(path: "/echo.Echo/Collect",
-                                        callOptions: callOptions ?? self.defaultCallOptions)
+  public func collect(
+    callOptions: CallOptions? = nil
+  ) -> ClientStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
+    return self.makeClientStreamingCall(
+      path: "/echo.Echo/Collect",
+      callOptions: callOptions ?? self.defaultCallOptions
+    )
   }
 
   /// Streams back messages as they are received in an input stream.
@@ -97,12 +112,16 @@ public final class Echo_EchoClient: GRPCClient, Echo_EchoClientProtocol {
   ///   - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
   ///   - handler: A closure called when each response is received from the server.
   /// - Returns: A `ClientStreamingCall` with futures for the metadata and status.
-  public func update(callOptions: CallOptions? = nil, handler: @escaping (Echo_EchoResponse) -> Void) -> BidirectionalStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
-    return self.makeBidirectionalStreamingCall(path: "/echo.Echo/Update",
-                                               callOptions: callOptions ?? self.defaultCallOptions,
-                                               handler: handler)
+  public func update(
+    callOptions: CallOptions? = nil,
+    handler: @escaping (Echo_EchoResponse) -> Void
+  ) -> BidirectionalStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
+    return self.makeBidirectionalStreamingCall(
+      path: "/echo.Echo/Update",
+      callOptions: callOptions ?? self.defaultCallOptions,
+      handler: handler
+    )
   }
-
 }
 
 /// To build a server, implement a class that conforms to this protocol.

+ 9 - 5
Sources/Examples/HelloWorld/Model/helloworld.grpc.swift

@@ -52,12 +52,16 @@ public final class Helloworld_GreeterClient: GRPCClient, Helloworld_GreeterClien
   ///   - request: Request to send to SayHello.
   ///   - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
   /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
-  public func sayHello(_ request: Helloworld_HelloRequest, callOptions: CallOptions? = nil) -> UnaryCall<Helloworld_HelloRequest, Helloworld_HelloReply> {
-    return self.makeUnaryCall(path: "/helloworld.Greeter/SayHello",
-                              request: request,
-                              callOptions: callOptions ?? self.defaultCallOptions)
+  public func sayHello(
+    _ request: Helloworld_HelloRequest,
+    callOptions: CallOptions? = nil
+  ) -> UnaryCall<Helloworld_HelloRequest, Helloworld_HelloReply> {
+    return self.makeUnaryCall(
+      path: "/helloworld.Greeter/SayHello",
+      request: request,
+      callOptions: callOptions ?? self.defaultCallOptions
+    )
   }
-
 }
 
 /// To build a server, implement a class that conforms to this protocol.

+ 1 - 0
Sources/Examples/HelloWorld/Model/helloworld.pb.swift

@@ -1,4 +1,5 @@
 // DO NOT EDIT.
+// swift-format-ignore-file
 //
 // Generated by the Swift generator plugin for the protocol buffer compiler.
 // Source: helloworld.proto

+ 36 - 17
Sources/Examples/RouteGuide/Model/route_guide.grpc.swift

@@ -60,10 +60,15 @@ public final class Routeguide_RouteGuideClient: GRPCClient, Routeguide_RouteGuid
   ///   - request: Request to send to GetFeature.
   ///   - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
   /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
-  public func getFeature(_ request: Routeguide_Point, callOptions: CallOptions? = nil) -> UnaryCall<Routeguide_Point, Routeguide_Feature> {
-    return self.makeUnaryCall(path: "/routeguide.RouteGuide/GetFeature",
-                              request: request,
-                              callOptions: callOptions ?? self.defaultCallOptions)
+  public func getFeature(
+    _ request: Routeguide_Point,
+    callOptions: CallOptions? = nil
+  ) -> UnaryCall<Routeguide_Point, Routeguide_Feature> {
+    return self.makeUnaryCall(
+      path: "/routeguide.RouteGuide/GetFeature",
+      request: request,
+      callOptions: callOptions ?? self.defaultCallOptions
+    )
   }
 
   /// A server-to-client streaming RPC.
@@ -78,11 +83,17 @@ public final class Routeguide_RouteGuideClient: GRPCClient, Routeguide_RouteGuid
   ///   - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
   ///   - handler: A closure called when each response is received from the server.
   /// - Returns: A `ServerStreamingCall` with futures for the metadata and status.
-  public func listFeatures(_ request: Routeguide_Rectangle, callOptions: CallOptions? = nil, handler: @escaping (Routeguide_Feature) -> Void) -> ServerStreamingCall<Routeguide_Rectangle, Routeguide_Feature> {
-    return self.makeServerStreamingCall(path: "/routeguide.RouteGuide/ListFeatures",
-                                        request: request,
-                                        callOptions: callOptions ?? self.defaultCallOptions,
-                                        handler: handler)
+  public func listFeatures(
+    _ request: Routeguide_Rectangle,
+    callOptions: CallOptions? = nil,
+    handler: @escaping (Routeguide_Feature) -> Void
+  ) -> ServerStreamingCall<Routeguide_Rectangle, Routeguide_Feature> {
+    return self.makeServerStreamingCall(
+      path: "/routeguide.RouteGuide/ListFeatures",
+      request: request,
+      callOptions: callOptions ?? self.defaultCallOptions,
+      handler: handler
+    )
   }
 
   /// A client-to-server streaming RPC.
@@ -96,9 +107,13 @@ public final class Routeguide_RouteGuideClient: GRPCClient, Routeguide_RouteGuid
   /// - Parameters:
   ///   - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
   /// - Returns: A `ClientStreamingCall` with futures for the metadata, status and response.
-  public func recordRoute(callOptions: CallOptions? = nil) -> ClientStreamingCall<Routeguide_Point, Routeguide_RouteSummary> {
-    return self.makeClientStreamingCall(path: "/routeguide.RouteGuide/RecordRoute",
-                                        callOptions: callOptions ?? self.defaultCallOptions)
+  public func recordRoute(
+    callOptions: CallOptions? = nil
+  ) -> ClientStreamingCall<Routeguide_Point, Routeguide_RouteSummary> {
+    return self.makeClientStreamingCall(
+      path: "/routeguide.RouteGuide/RecordRoute",
+      callOptions: callOptions ?? self.defaultCallOptions
+    )
   }
 
   /// A Bidirectional streaming RPC.
@@ -113,12 +128,16 @@ public final class Routeguide_RouteGuideClient: GRPCClient, Routeguide_RouteGuid
   ///   - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
   ///   - handler: A closure called when each response is received from the server.
   /// - Returns: A `ClientStreamingCall` with futures for the metadata and status.
-  public func routeChat(callOptions: CallOptions? = nil, handler: @escaping (Routeguide_RouteNote) -> Void) -> BidirectionalStreamingCall<Routeguide_RouteNote, Routeguide_RouteNote> {
-    return self.makeBidirectionalStreamingCall(path: "/routeguide.RouteGuide/RouteChat",
-                                               callOptions: callOptions ?? self.defaultCallOptions,
-                                               handler: handler)
+  public func routeChat(
+    callOptions: CallOptions? = nil,
+    handler: @escaping (Routeguide_RouteNote) -> Void
+  ) -> BidirectionalStreamingCall<Routeguide_RouteNote, Routeguide_RouteNote> {
+    return self.makeBidirectionalStreamingCall(
+      path: "/routeguide.RouteGuide/RouteChat",
+      callOptions: callOptions ?? self.defaultCallOptions,
+      handler: handler
+    )
   }
-
 }
 
 /// To build a server, implement a class that conforms to this protocol.

+ 125 - 63
Sources/protoc-gen-grpc-swift/Generator-Client.swift

@@ -66,80 +66,136 @@ extension Generator {
     println("self.defaultCallOptions = defaultCallOptions")
     outdent()
     println("}")
-    println()
 
-    for method in service.methods {
+    self.printMethods()
+
+    outdent()
+    println("}")
+  }
+
+  private func printMethods(callFactory: String = "self") {
+    for method in self.service.methods {
+      self.println()
+
       self.method = method
-      let streamType = streamingType(self.method)
-      switch streamType {
+      switch self.streamType {
       case .unary:
-        println(self.method.documentation(streamingType: streamType), newline: false)
-        println("///")
-        printParameters()
-        printRequestParameter()
-        printCallOptionsParameter()
-        println("/// - Returns: A `UnaryCall` with futures for the metadata, status and response.")
-        println("\(access) func \(methodFunctionName)(_ request: \(methodInputName), callOptions: CallOptions? = nil) -> UnaryCall<\(methodInputName), \(methodOutputName)> {")
-        indent()
-        println("return self.makeUnaryCall(path: \"/\(servicePath)/\(method.name)\",")
-        println("                          request: request,")
-        println("                          callOptions: callOptions ?? self.defaultCallOptions)")
-        outdent()
-        println("}")
+        self.printUnaryCall(callFactory: callFactory)
 
       case .serverStreaming:
-        println(self.method.documentation(streamingType: streamType), newline: false)
-        println("///")
-        printParameters()
-        printRequestParameter()
-        printCallOptionsParameter()
-        printHandlerParameter()
-        println("/// - Returns: A `ServerStreamingCall` with futures for the metadata and status.")
-        println("\(access) func \(methodFunctionName)(_ request: \(methodInputName), callOptions: CallOptions? = nil, handler: @escaping (\(methodOutputName)) -> Void) -> ServerStreamingCall<\(methodInputName), \(methodOutputName)> {")
-        indent()
-        println("return self.makeServerStreamingCall(path: \"/\(servicePath)/\(method.name)\",")
-        println("                                    request: request,")
-        println("                                    callOptions: callOptions ?? self.defaultCallOptions,")
-        println("                                    handler: handler)")
-        outdent()
-        println("}")
+        self.printServerStreamingCall(callFactory: callFactory)
 
       case .clientStreaming:
-        println(self.method.documentation(streamingType: streamType), newline: false)
-        println("///")
-        printClientStreamingDetails()
-        println("///")
-        printParameters()
-        printCallOptionsParameter()
-        println("/// - Returns: A `ClientStreamingCall` with futures for the metadata, status and response.")
-        println("\(access) func \(methodFunctionName)(callOptions: CallOptions? = nil) -> ClientStreamingCall<\(methodInputName), \(methodOutputName)> {")
-        indent()
-        println("return self.makeClientStreamingCall(path: \"/\(servicePath)/\(method.name)\",")
-        println("                                    callOptions: callOptions ?? self.defaultCallOptions)")
-        outdent()
-        println("}")
+        self.printClientStreamingCall(callFactory: callFactory)
 
       case .bidirectionalStreaming:
-        println(self.method.documentation(streamingType: streamType), newline: false)
-        println("///")
-        printClientStreamingDetails()
-        println("///")
-        printParameters()
-        printCallOptionsParameter()
-        printHandlerParameter()
-        println("/// - Returns: A `ClientStreamingCall` with futures for the metadata and status.")
-        println("\(access) func \(methodFunctionName)(callOptions: CallOptions? = nil, handler: @escaping (\(methodOutputName)) -> Void) -> BidirectionalStreamingCall<\(methodInputName), \(methodOutputName)> {")
-        indent()
-        println("return self.makeBidirectionalStreamingCall(path: \"/\(servicePath)/\(method.name)\",")
-        println("                                           callOptions: callOptions ?? self.defaultCallOptions,")
-        println("                                           handler: handler)")
-        outdent()
-        println("}")
+        self.printBidirectionalStreamingCall(callFactory: callFactory)
       }
-      println()
     }
-    outdent()
-    println("}")
+  }
+
+  private func printUnaryCall(callFactory: String) {
+    self.println(self.method.documentation(streamingType: self.streamType), newline: false)
+    self.println("///")
+    self.printParameters()
+    self.printRequestParameter()
+    self.printCallOptionsParameter()
+    self.println("/// - Returns: A `UnaryCall` with futures for the metadata, status and response.")
+    self.println("\(self.access) func \(self.methodFunctionName)(")
+    self.withIndentation {
+      self.println("_ request: \(self.methodInputName),")
+      self.println("callOptions: CallOptions? = nil")
+    }
+    self.println(") -> UnaryCall<\(self.methodInputName), \(self.methodOutputName)> {")
+    self.withIndentation {
+      self.println("return \(callFactory).makeUnaryCall(")
+      self.withIndentation {
+        self.println("path: \(self.methodPath),")
+        self.println("request: request,")
+        self.println("callOptions: callOptions ?? self.defaultCallOptions")
+      }
+      self.println(")")
+    }
+    self.println("}")
+  }
+
+  private func printServerStreamingCall(callFactory: String) {
+    self.println(self.method.documentation(streamingType: self.streamType), newline: false)
+    self.println("///")
+    self.printParameters()
+    self.printRequestParameter()
+    self.printCallOptionsParameter()
+    self.printHandlerParameter()
+    self.println("/// - Returns: A `ServerStreamingCall` with futures for the metadata and status.")
+    self.println("\(self.access) func \(self.methodFunctionName)(")
+    self.withIndentation {
+      self.println("_ request: \(self.methodInputName),")
+      self.println("callOptions: CallOptions? = nil,")
+      self.println("handler: @escaping (\(methodOutputName)) -> Void")
+    }
+    self.println(") -> ServerStreamingCall<\(methodInputName), \(methodOutputName)> {")
+    self.withIndentation {
+      self.println("return \(callFactory).makeServerStreamingCall(") // path: \"/\(servicePath)/\(method.name)\",")
+      self.withIndentation {
+        self.println("path: \(self.methodPath),")
+        self.println("request: request,")
+        self.println("callOptions: callOptions ?? self.defaultCallOptions,")
+        self.println("handler: handler")
+      }
+      self.println(")")
+    }
+    self.println("}")
+  }
+
+  private func printClientStreamingCall(callFactory: String) {
+    self.println(self.method.documentation(streamingType: self.streamType), newline: false)
+    self.println("///")
+    self.printClientStreamingDetails()
+    self.println("///")
+    self.printParameters()
+    self.printCallOptionsParameter()
+    self.println("/// - Returns: A `ClientStreamingCall` with futures for the metadata, status and response.")
+    self.println("\(self.access) func \(self.methodFunctionName)(")
+    self.withIndentation {
+      self.println("callOptions: CallOptions? = nil")
+    }
+    self.println(") -> ClientStreamingCall<\(self.methodInputName), \(self.methodOutputName)> {")
+    self.withIndentation {
+      self.println("return \(callFactory).makeClientStreamingCall(")
+      self.withIndentation {
+        self.println("path: \(self.methodPath),")
+        self.println("callOptions: callOptions ?? self.defaultCallOptions")
+      }
+      self.println(")")
+    }
+    self.println("}")
+  }
+
+  private func printBidirectionalStreamingCall(callFactory: String) {
+    self.println(self.method.documentation(streamingType: self.streamType), newline: false)
+    self.println("///")
+    self.printClientStreamingDetails()
+    self.println("///")
+    self.printParameters()
+    self.printCallOptionsParameter()
+    self.printHandlerParameter()
+    self.println("/// - Returns: A `ClientStreamingCall` with futures for the metadata and status.")
+    self.println("\(self.access) func \(self.methodFunctionName)(")
+    self.withIndentation {
+      self.println("callOptions: CallOptions? = nil,")
+      self.println("handler: @escaping (\(self.methodOutputName)) -> Void")
+    }
+    self.println(") -> BidirectionalStreamingCall<\(self.methodInputName), \(self.methodOutputName)> {")
+    self.withIndentation {
+      self.println("return \(callFactory).makeBidirectionalStreamingCall(")
+      self.withIndentation {
+        self.println("path: \(self.methodPath),")
+        self.println("callOptions: callOptions ?? self.defaultCallOptions,")
+        self.println("handler: handler")
+      }
+      self.println(")")
+    }
+    self.println("}")
   }
 
   private func printClientStreamingDetails() {
@@ -164,6 +220,12 @@ extension Generator {
   }
 }
 
+fileprivate extension Generator {
+  var streamType: StreamingType {
+    return streamingType(self.method)
+  }
+}
+
 fileprivate extension StreamingType {
   var name: String {
     switch self {

+ 6 - 0
Sources/protoc-gen-grpc-swift/Generator.swift

@@ -54,6 +54,12 @@ class Generator {
     printer.outdent()
   }
 
+  internal func withIndentation(body: () -> ()) {
+    self.indent()
+    body()
+    self.outdent()
+  }
+
   private func printMain() {
     printer.print("""
       //

+ 36 - 17
dev/codegen-tests/01-echo/golden/echo.grpc.swift

@@ -55,10 +55,15 @@ internal final class Echo_EchoClient: GRPCClient, Echo_EchoClientProtocol {
   ///   - request: Request to send to Get.
   ///   - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
   /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
-  internal func get(_ request: Echo_EchoRequest, callOptions: CallOptions? = nil) -> UnaryCall<Echo_EchoRequest, Echo_EchoResponse> {
-    return self.makeUnaryCall(path: "/echo.Echo/Get",
-                              request: request,
-                              callOptions: callOptions ?? self.defaultCallOptions)
+  internal func get(
+    _ request: Echo_EchoRequest,
+    callOptions: CallOptions? = nil
+  ) -> UnaryCall<Echo_EchoRequest, Echo_EchoResponse> {
+    return self.makeUnaryCall(
+      path: "/echo.Echo/Get",
+      request: request,
+      callOptions: callOptions ?? self.defaultCallOptions
+    )
   }
 
   /// Splits a request into words and returns each word in a stream of messages.
@@ -68,11 +73,17 @@ internal final class Echo_EchoClient: GRPCClient, Echo_EchoClientProtocol {
   ///   - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
   ///   - handler: A closure called when each response is received from the server.
   /// - Returns: A `ServerStreamingCall` with futures for the metadata and status.
-  internal func expand(_ request: Echo_EchoRequest, callOptions: CallOptions? = nil, handler: @escaping (Echo_EchoResponse) -> Void) -> ServerStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
-    return self.makeServerStreamingCall(path: "/echo.Echo/Expand",
-                                        request: request,
-                                        callOptions: callOptions ?? self.defaultCallOptions,
-                                        handler: handler)
+  internal func expand(
+    _ request: Echo_EchoRequest,
+    callOptions: CallOptions? = nil,
+    handler: @escaping (Echo_EchoResponse) -> Void
+  ) -> ServerStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
+    return self.makeServerStreamingCall(
+      path: "/echo.Echo/Expand",
+      request: request,
+      callOptions: callOptions ?? self.defaultCallOptions,
+      handler: handler
+    )
   }
 
   /// Collects a stream of messages and returns them concatenated when the caller closes.
@@ -83,9 +94,13 @@ internal final class Echo_EchoClient: GRPCClient, Echo_EchoClientProtocol {
   /// - Parameters:
   ///   - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
   /// - Returns: A `ClientStreamingCall` with futures for the metadata, status and response.
-  internal func collect(callOptions: CallOptions? = nil) -> ClientStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
-    return self.makeClientStreamingCall(path: "/echo.Echo/Collect",
-                                        callOptions: callOptions ?? self.defaultCallOptions)
+  internal func collect(
+    callOptions: CallOptions? = nil
+  ) -> ClientStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
+    return self.makeClientStreamingCall(
+      path: "/echo.Echo/Collect",
+      callOptions: callOptions ?? self.defaultCallOptions
+    )
   }
 
   /// Streams back messages as they are received in an input stream.
@@ -97,12 +112,16 @@ internal final class Echo_EchoClient: GRPCClient, Echo_EchoClientProtocol {
   ///   - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
   ///   - handler: A closure called when each response is received from the server.
   /// - Returns: A `ClientStreamingCall` with futures for the metadata and status.
-  internal func update(callOptions: CallOptions? = nil, handler: @escaping (Echo_EchoResponse) -> Void) -> BidirectionalStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
-    return self.makeBidirectionalStreamingCall(path: "/echo.Echo/Update",
-                                               callOptions: callOptions ?? self.defaultCallOptions,
-                                               handler: handler)
+  internal func update(
+    callOptions: CallOptions? = nil,
+    handler: @escaping (Echo_EchoResponse) -> Void
+  ) -> BidirectionalStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
+    return self.makeBidirectionalStreamingCall(
+      path: "/echo.Echo/Update",
+      callOptions: callOptions ?? self.defaultCallOptions,
+      handler: handler
+    )
   }
-
 }
 
 /// To build a server, implement a class that conforms to this protocol.

+ 9 - 5
dev/codegen-tests/02-multifile/golden/a.grpc.swift

@@ -52,12 +52,16 @@ internal final class A_ServiceAClient: GRPCClient, A_ServiceAClientProtocol {
   ///   - request: Request to send to CallServiceA.
   ///   - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
   /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
-  internal func callServiceA(_ request: A_MessageA, callOptions: CallOptions? = nil) -> UnaryCall<A_MessageA, SwiftProtobuf.Google_Protobuf_Empty> {
-    return self.makeUnaryCall(path: "/a.ServiceA/CallServiceA",
-                              request: request,
-                              callOptions: callOptions ?? self.defaultCallOptions)
+  internal func callServiceA(
+    _ request: A_MessageA,
+    callOptions: CallOptions? = nil
+  ) -> UnaryCall<A_MessageA, SwiftProtobuf.Google_Protobuf_Empty> {
+    return self.makeUnaryCall(
+      path: "/a.ServiceA/CallServiceA",
+      request: request,
+      callOptions: callOptions ?? self.defaultCallOptions
+    )
   }
-
 }
 
 /// To build a server, implement a class that conforms to this protocol.

+ 9 - 5
dev/codegen-tests/02-multifile/golden/b.grpc.swift

@@ -52,12 +52,16 @@ internal final class B_ServiceBClient: GRPCClient, B_ServiceBClientProtocol {
   ///   - request: Request to send to CallServiceB.
   ///   - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
   /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
-  internal func callServiceB(_ request: B_MessageB, callOptions: CallOptions? = nil) -> UnaryCall<B_MessageB, SwiftProtobuf.Google_Protobuf_Empty> {
-    return self.makeUnaryCall(path: "/b.ServiceB/CallServiceB",
-                              request: request,
-                              callOptions: callOptions ?? self.defaultCallOptions)
+  internal func callServiceB(
+    _ request: B_MessageB,
+    callOptions: CallOptions? = nil
+  ) -> UnaryCall<B_MessageB, SwiftProtobuf.Google_Protobuf_Empty> {
+    return self.makeUnaryCall(
+      path: "/b.ServiceB/CallServiceB",
+      request: request,
+      callOptions: callOptions ?? self.defaultCallOptions
+    )
   }
-
 }
 
 /// To build a server, implement a class that conforms to this protocol.

+ 9 - 5
dev/codegen-tests/03-multifile-with-module-map/golden/a.grpc.swift

@@ -53,12 +53,16 @@ internal final class A_ServiceAClient: GRPCClient, A_ServiceAClientProtocol {
   ///   - request: Request to send to CallServiceA.
   ///   - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
   /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
-  internal func callServiceA(_ request: A_MessageA, callOptions: CallOptions? = nil) -> UnaryCall<A_MessageA, SwiftProtobuf.Google_Protobuf_Empty> {
-    return self.makeUnaryCall(path: "/a.ServiceA/CallServiceA",
-                              request: request,
-                              callOptions: callOptions ?? self.defaultCallOptions)
+  internal func callServiceA(
+    _ request: A_MessageA,
+    callOptions: CallOptions? = nil
+  ) -> UnaryCall<A_MessageA, SwiftProtobuf.Google_Protobuf_Empty> {
+    return self.makeUnaryCall(
+      path: "/a.ServiceA/CallServiceA",
+      request: request,
+      callOptions: callOptions ?? self.defaultCallOptions
+    )
   }
-
 }
 
 /// To build a server, implement a class that conforms to this protocol.

+ 9 - 5
dev/codegen-tests/03-multifile-with-module-map/golden/b.grpc.swift

@@ -52,12 +52,16 @@ internal final class B_ServiceBClient: GRPCClient, B_ServiceBClientProtocol {
   ///   - request: Request to send to CallServiceB.
   ///   - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
   /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
-  internal func callServiceB(_ request: B_MessageB, callOptions: CallOptions? = nil) -> UnaryCall<B_MessageB, SwiftProtobuf.Google_Protobuf_Empty> {
-    return self.makeUnaryCall(path: "/b.ServiceB/CallServiceB",
-                              request: request,
-                              callOptions: callOptions ?? self.defaultCallOptions)
+  internal func callServiceB(
+    _ request: B_MessageB,
+    callOptions: CallOptions? = nil
+  ) -> UnaryCall<B_MessageB, SwiftProtobuf.Google_Protobuf_Empty> {
+    return self.makeUnaryCall(
+      path: "/b.ServiceB/CallServiceB",
+      request: request,
+      callOptions: callOptions ?? self.defaultCallOptions
+    )
   }
-
 }
 
 /// To build a server, implement a class that conforms to this protocol.

+ 9 - 5
dev/codegen-tests/05-service-only/golden/test.grpc.swift

@@ -52,12 +52,16 @@ internal final class Codegentest_FooClient: GRPCClient, Codegentest_FooClientPro
   ///   - request: Request to send to Bar.
   ///   - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
   /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
-  internal func bar(_ request: SwiftProtobuf.Google_Protobuf_Empty, callOptions: CallOptions? = nil) -> UnaryCall<SwiftProtobuf.Google_Protobuf_Empty, SwiftProtobuf.Google_Protobuf_Empty> {
-    return self.makeUnaryCall(path: "/codegentest.Foo/Bar",
-                              request: request,
-                              callOptions: callOptions ?? self.defaultCallOptions)
+  internal func bar(
+    _ request: SwiftProtobuf.Google_Protobuf_Empty,
+    callOptions: CallOptions? = nil
+  ) -> UnaryCall<SwiftProtobuf.Google_Protobuf_Empty, SwiftProtobuf.Google_Protobuf_Empty> {
+    return self.makeUnaryCall(
+      path: "/codegentest.Foo/Bar",
+      request: request,
+      callOptions: callOptions ?? self.defaultCallOptions
+    )
   }
-
 }
 
 /// To build a server, implement a class that conforms to this protocol.