Browse Source

Re-format code

George Barnett 2 years ago
parent
commit
0386af03dc

+ 8 - 5
Sources/protoc-gen-grpc-swift/Generator-Client+AsyncAwait.swift

@@ -49,7 +49,7 @@ extension Generator {
 
 
         case .clientStreaming, .bidirectionalStreaming:
         case .clientStreaming, .bidirectionalStreaming:
           arguments = [
           arguments = [
-            "callOptions: \(Types.clientCallOptions)?",
+            "callOptions: \(Types.clientCallOptions)?"
           ]
           ]
         }
         }
 
 
@@ -61,7 +61,7 @@ extension Generator {
         )
         )
       }
       }
     }
     }
-    self.println("}") // protocol
+    self.println("}")  // protocol
   }
   }
 }
 }
 
 
@@ -156,7 +156,8 @@ extension Generator {
         let streamsRequests = [.clientStreaming, .bidirectionalStreaming].contains(rpcType)
         let streamsRequests = [.clientStreaming, .bidirectionalStreaming].contains(rpcType)
 
 
         // (protocol, requires sendable)
         // (protocol, requires sendable)
-        let sequenceProtocols: [(String, Bool)?] = streamsRequests
+        let sequenceProtocols: [(String, Bool)?] =
+          streamsRequests
           ? [("Sequence", false), ("AsyncSequence", true)]
           ? [("Sequence", false), ("AsyncSequence", true)]
           : [nil]
           : [nil]
 
 
@@ -165,12 +166,14 @@ extension Generator {
           if i > 0 || j > 0 {
           if i > 0 || j > 0 {
             self.println()
             self.println()
           }
           }
-          let functionName = streamsRequests
+          let functionName =
+            streamsRequests
             ? "\(self.methodFunctionName)<RequestStream>"
             ? "\(self.methodFunctionName)<RequestStream>"
             : self.methodFunctionName
             : self.methodFunctionName
           let requestParamName = streamsRequests ? "requests" : "request"
           let requestParamName = streamsRequests ? "requests" : "request"
           let requestParamType = streamsRequests ? "RequestStream" : self.methodInputName
           let requestParamType = streamsRequests ? "RequestStream" : self.methodInputName
-          let returnType = streamsResponses
+          let returnType =
+            streamsResponses
             ? Types.responseStream(of: self.methodOutputName)
             ? Types.responseStream(of: self.methodOutputName)
             : self.methodOutputName
             : self.methodOutputName
           let maybeWhereClause = sequenceProtocol.map { protocolName, mustBeSendable -> String in
           let maybeWhereClause = sequenceProtocol.map { protocolName, mustBeSendable -> String in

+ 12 - 9
Sources/protoc-gen-grpc-swift/Generator-Client.swift

@@ -89,11 +89,14 @@ extension Generator {
       self.println("\(functionHead)func \(name)(")
       self.println("\(functionHead)func \(name)(")
       self.withIndentation {
       self.withIndentation {
         // Add a comma after each argument except the last.
         // Add a comma after each argument except the last.
-        arguments.forEach(beforeLast: {
-          self.println($0 + ",")
-        }, onLast: {
-          self.println($0)
-        })
+        arguments.forEach(
+          beforeLast: {
+            self.println($0 + ",")
+          },
+          onLast: {
+            self.println($0)
+          }
+        )
       }
       }
       self.println(")\(asyncThrows)\(`return`)\(genericWhere)", newline: !hasBody)
       self.println(")\(asyncThrows)\(`return`)\(genericWhere)", newline: !hasBody)
     }
     }
@@ -504,7 +507,7 @@ extension Generator {
     self.printFunction(
     self.printFunction(
       name: "make\(self.method.name)ResponseStream",
       name: "make\(self.method.name)ResponseStream",
       arguments: [
       arguments: [
-        "_ requestHandler: @escaping (FakeRequestPart<\(self.methodInputName)>) -> () = { _ in }",
+        "_ requestHandler: @escaping (FakeRequestPart<\(self.methodInputName)>) -> () = { _ in }"
       ],
       ],
       returnType: "\(type)<\(self.methodInputName), \(self.methodOutputName)>",
       returnType: "\(type)<\(self.methodInputName), \(self.methodOutputName)>",
       access: self.access
       access: self.access
@@ -569,7 +572,7 @@ extension Generator {
       self.printFakeResponseStreams()
       self.printFakeResponseStreams()
     }
     }
 
 
-    self.println("}") // end class
+    self.println("}")  // end class
   }
   }
 }
 }
 
 
@@ -664,9 +667,9 @@ extension MethodDescriptor {
     let sourceComments = self.protoSourceComments()
     let sourceComments = self.protoSourceComments()
 
 
     if sourceComments.isEmpty {
     if sourceComments.isEmpty {
-      return "/// \(streamingType.name) call to \(self.name)\n" // comments end with "\n" already.
+      return "/// \(streamingType.name) call to \(self.name)\n"  // comments end with "\n" already.
     } else {
     } else {
-      return sourceComments // already prefixed with "///"
+      return sourceComments  // already prefixed with "///"
     }
     }
   }
   }
 }
 }

+ 1 - 1
Sources/protoc-gen-grpc-swift/Generator-Server+AsyncAwait.swift

@@ -176,7 +176,7 @@ extension Generator {
           self.println("return nil")
           self.println("return nil")
         }
         }
 
 
-        self.println("}") // switch
+        self.println("}")  // switch
       }
       }
     }
     }
   }
   }

+ 13 - 11
Sources/protoc-gen-grpc-swift/Generator.swift

@@ -20,8 +20,8 @@ class Generator {
   private var printer: CodePrinter
   private var printer: CodePrinter
 
 
   internal var file: FileDescriptor
   internal var file: FileDescriptor
-  internal var service: ServiceDescriptor! // context during generation
-  internal var method: MethodDescriptor! // context during generation
+  internal var service: ServiceDescriptor!  // context during generation
+  internal var method: MethodDescriptor!  // context during generation
 
 
   internal let protobufNamer: SwiftProtobufNamer
   internal let protobufNamer: SwiftProtobufNamer
 
 
@@ -108,15 +108,17 @@ class Generator {
   }
   }
 
 
   private func printMain() {
   private func printMain() {
-    self.printer.print("""
-    //
-    // DO NOT EDIT.
-    // swift-format-ignore-file
-    //
-    // Generated by the protocol buffer compiler.
-    // Source: \(self.file.name)
-    //\n
-    """)
+    self.printer.print(
+      """
+      //
+      // DO NOT EDIT.
+      // swift-format-ignore-file
+      //
+      // Generated by the protocol buffer compiler.
+      // Source: \(self.file.name)
+      //\n
+      """
+    )
 
 
     let moduleNames = [
     let moduleNames = [
       self.options.gRPCModuleName,
       self.options.gRPCModuleName,

+ 2 - 5
Sources/protoc-gen-grpc-swift/main.swift

@@ -141,7 +141,7 @@ func main(args: [String]) throws {
   // Only generate output for services.
   // Only generate output for services.
   for name in request.fileToGenerate {
   for name in request.fileToGenerate {
     if let fileDescriptor = descriptorSet.fileDescriptor(named: name) {
     if let fileDescriptor = descriptorSet.fileDescriptor(named: name) {
-      if (options.generateReflectionData) {
+      if options.generateReflectionData {
         var binaryFile = Google_Protobuf_Compiler_CodeGeneratorResponse.File()
         var binaryFile = Google_Protobuf_Compiler_CodeGeneratorResponse.File()
         let binaryFileName = uniqueOutputFileName(
         let binaryFileName = uniqueOutputFileName(
           component: "grpc.reflection",
           component: "grpc.reflection",
@@ -156,10 +156,7 @@ func main(args: [String]) throws {
         binaryFile.content = serializedFileDescriptorProto
         binaryFile.content = serializedFileDescriptorProto
         response.file.append(binaryFile)
         response.file.append(binaryFile)
       }
       }
-      if (
-        !fileDescriptor.services
-          .isEmpty && (options.generateClient || options.generateServer)
-      ) {
+      if !fileDescriptor.services.isEmpty && (options.generateClient || options.generateServer) {
         var grpcFile = Google_Protobuf_Compiler_CodeGeneratorResponse.File()
         var grpcFile = Google_Protobuf_Compiler_CodeGeneratorResponse.File()
         let grpcFileName = uniqueOutputFileName(
         let grpcFileName = uniqueOutputFileName(
           component: "grpc",
           component: "grpc",