Skip to content

Commit c2712f0

Browse files
committed
Make empty generated source files descriptive
Motivation: Sometimes protobuf definition files contain no gRPC services and result in an empty file. This is intentional but could be confusing. Modifications: Empty files now contain a comment indicating they are intentional. ``` // This file contained no services. ``` Result: More descriptive empty source files.
1 parent 0696e0a commit c2712f0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Sources/GRPCCodeGen/SourceGenerator.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,21 @@ public struct SourceGenerator: Sendable {
8787
let translator = IDLToStructuredSwiftTranslator()
8888
let textRenderer = TextBasedRenderer(indentation: self.config.indentation)
8989

90-
let structuredSwiftRepresentation = try translator.translate(
90+
var structuredSwiftRepresentation = try translator.translate(
9191
codeGenerationRequest: request,
9292
accessLevel: self.config.accessLevel,
9393
accessLevelOnImports: self.config.accessLevelOnImports,
9494
client: self.config.client,
9595
server: self.config.server
9696
)
97+
98+
if structuredSwiftRepresentation.file.contents.codeBlocks.isEmpty {
99+
structuredSwiftRepresentation.file.contents.imports = []
100+
structuredSwiftRepresentation.file.contents.codeBlocks.append(
101+
CodeBlock(comment: .inline("This file contained no services."))
102+
)
103+
}
104+
97105
let sourceFile = try textRenderer.render(structured: structuredSwiftRepresentation)
98106

99107
return sourceFile

0 commit comments

Comments
 (0)