Browse Source

Use a nil Descriptor list for empty proto files (#2152)

### Motivation:

If a proto file contains no services we include a comment indicating
this is expected. At the moment this has two empty lines above it.

### Modifications:

Store `nil` instead of an empty array of `Descriptor`s into the
`FileDescription`.

### Result:

Only one empty line above the comment.
Rick Newton-Rogers 1 year ago
parent
commit
560c6c7bf5

+ 2 - 2
Sources/GRPCCodeGen/Internal/Translator/IDLToStructuredSwiftTranslator.swift

@@ -74,9 +74,9 @@ package struct IDLToStructuredSwiftTranslator: Translator {
       }
     }
 
-    let imports: [ImportDescription]
+    let imports: [ImportDescription]?
     if codeGenerationRequest.services.isEmpty {
-      imports = []
+      imports = nil
       codeBlocks.append(
         CodeBlock(comment: .inline("This file contained no services."))
       )

+ 0 - 1
Tests/GRPCCodeGenTests/Internal/Translator/IDLToStructuredSwiftTranslatorSnippetBasedTests.swift

@@ -145,7 +145,6 @@ final class IDLToStructuredSwiftTranslatorSnippetBasedTests: XCTestCase {
       """
       /// Some really exciting license header 2023.
 
-
       // This file contained no services.
       """
     try self.assertIDLToStructuredSwiftTranslation(