From 3fba43817ba6cf6aa78c68ff41b535e26db4c272 Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Tue, 30 Jul 2024 18:28:41 -0700 Subject: [PATCH 1/5] WIP - update to support editions updates Update Generator.swift Signed-off-by: Michael Rebello --- Package.swift | 1 + .../ConnectMockGenerator.swift | 25 ++-- Plugins/ConnectMocksPlugin/main.swift | 19 --- .../ConnectPluginUtilities/Generator.swift | 121 ++++++++++++++---- .../GeneratorOptions.swift | 59 +++------ .../MainGeneratorFunction.swift | 74 ----------- .../ConnectClientGenerator.swift | 23 ++-- Plugins/ConnectSwiftPlugin/main.swift | 19 --- 8 files changed, 136 insertions(+), 205 deletions(-) delete mode 100644 Plugins/ConnectMocksPlugin/main.swift delete mode 100644 Plugins/ConnectPluginUtilities/MainGeneratorFunction.swift delete mode 100644 Plugins/ConnectSwiftPlugin/main.swift diff --git a/Package.swift b/Package.swift index 42b80184..6bbb4550 100644 --- a/Package.swift +++ b/Package.swift @@ -121,6 +121,7 @@ let package = Package( name: "ConnectMocksPlugin", dependencies: [ "ConnectPluginUtilities", + .product(name: "SwiftProtobuf", package: "swift-protobuf"), .product(name: "SwiftProtobufPluginLibrary", package: "swift-protobuf"), ], path: "Plugins/ConnectMocksPlugin" diff --git a/Plugins/ConnectMocksPlugin/ConnectMockGenerator.swift b/Plugins/ConnectMocksPlugin/ConnectMockGenerator.swift index 7a6371fb..d9246784 100644 --- a/Plugins/ConnectMocksPlugin/ConnectMockGenerator.swift +++ b/Plugins/ConnectMocksPlugin/ConnectMockGenerator.swift @@ -16,13 +16,20 @@ import ConnectPluginUtilities import Foundation import SwiftProtobufPluginLibrary -/// Responsible for generating services and RPCs that are compatible with the Connect library. +/// Responsible for generating mocks that are compatible with generated Connect services. +@main final class ConnectMockGenerator: Generator { - private let propertyVisibility: String - private let typeVisibility: String + private var propertyVisibility = "" + private var typeVisibility = "" - required init(_ descriptor: FileDescriptor, options: GeneratorOptions) { - switch options.visibility { + override var outputFileExtension: String { + return ".mock.swift" + } + + override func printContent(for descriptor: FileDescriptor) { + super.printContent(for: descriptor) + + switch self.options.visibility { case .internal: self.propertyVisibility = "internal" self.typeVisibility = "internal" @@ -30,12 +37,6 @@ final class ConnectMockGenerator: Generator { self.propertyVisibility = "public" self.typeVisibility = "open" } - super.init(descriptor, options: options) - self.printContent() - } - - private func printContent() { - self.printFilePreamble() if self.options.generateCallbackMethods { self.printModuleImports(adding: ["Combine", "ConnectMocks"]) @@ -43,7 +44,7 @@ final class ConnectMockGenerator: Generator { self.printModuleImports(adding: ["ConnectMocks"]) } - for service in self.descriptor.services { + for service in self.services { self.printLine() self.printMockService(service) } diff --git a/Plugins/ConnectMocksPlugin/main.swift b/Plugins/ConnectMocksPlugin/main.swift deleted file mode 100644 index d45bfe7a..00000000 --- a/Plugins/ConnectMocksPlugin/main.swift +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2022-2024 The Connect Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import ConnectPluginUtilities - -MainGeneratorFunction( - generatorType: ConnectMockGenerator.self, outputFileExtension: ".mock.swift" -).generateFromStandardInToStandardOut() diff --git a/Plugins/ConnectPluginUtilities/Generator.swift b/Plugins/ConnectPluginUtilities/Generator.swift index 86847874..d35fda40 100644 --- a/Plugins/ConnectPluginUtilities/Generator.swift +++ b/Plugins/ConnectPluginUtilities/Generator.swift @@ -12,27 +12,49 @@ // See the License for the specific language governing permissions and // limitations under the License. +import SwiftProtobuf import SwiftProtobufPluginLibrary -/// Base generator class that can be used to output a file from a Protobuf file descriptor. +private struct GeneratorError: Swift.Error { + let message: String +} + +/// Base generator class that can be used to output files from Protobuf file descriptors. +/// +/// Subclasses must be annotated with `@main` to be properly invoked at runtime. open class Generator { - private var printer = CodePrinter(indent: " ".unicodeScalars) + private var printer = SwiftProtobufPluginLibrary.CodePrinter() - public let descriptor: FileDescriptor - public let namer: SwiftProtobufNamer - public let options: GeneratorOptions + /// Used for producing type names when generating code. + public private(set) var namer = SwiftProtobufPluginLibrary.SwiftProtobufNamer() + /// List of Swift module dependencies required by the current Protobuf file. + public private(set) var neededModules = [String]() + /// Options to use when generating code. + public private(set) var options = GeneratorOptions.empty() + /// List of services specified in the current file. + public private(set) var services = [SwiftProtobufPluginLibrary.ServiceDescriptor]() - public var output: String { - return self.printer.content + // MARK: - Overridable + + /// File extension to use for generated file names. + open var outputFileExtension: String { + return ".connect.swift" } - public required init(_ descriptor: FileDescriptor, options: GeneratorOptions) { - self.descriptor = descriptor - self.options = options - self.namer = SwiftProtobufNamer( - currentFile: descriptor, - protoFileToModuleMappings: options.protoToModuleMappings - ) + /// Initializer required by `SwiftProtobufPluginLibrary.CodeGenerator`. + public required init() {} + + /// Should be overridden by subclasses to write output for a given file descriptor. + /// Subclasses should call `super` before producing their own outputs. + /// May be called multiple times (once per file descriptor) over the lifetime of this class. + /// + /// - parameter descriptor: The file descriptor for which to generate code. + open func printContent(for descriptor: SwiftProtobufPluginLibrary.FileDescriptor) { + self.printLine("// Code generated by protoc-gen-connect-swift. DO NOT EDIT.") + self.printLine("//") + self.printLine("// Source: \(descriptor.name)") + self.printLine("//") + self.printLine() } // MARK: - Output helpers @@ -58,30 +80,75 @@ open class Generator { self.printer.print("\n") } - public func printCommentsIfNeeded(for entity: ProvidesSourceCodeLocation) { + public func printCommentsIfNeeded( + for entity: SwiftProtobufPluginLibrary.ProvidesSourceCodeLocation + ) { let comments = entity.protoSourceComments().trimmingCharacters(in: .whitespacesAndNewlines) if !comments.isEmpty { self.printLine(comments) } } - public func printFilePreamble() { - self.printLine("// Code generated by protoc-gen-connect-swift. DO NOT EDIT.") - self.printLine("//") - self.printLine("// Source: \(self.descriptor.name)") - self.printLine("//") - self.printLine() - } - public func printModuleImports(adding additional: [String] = []) { let defaults = ["Connect", "Foundation", self.options.swiftProtobufModuleName] let extraOptionImports = self.options.extraModuleImports - let mappings = self.options.protoToModuleMappings - .neededModules(forFile: self.descriptor) ?? [] - let allImports = (defaults + mappings + extraOptionImports + additional).sorted() - + let allImports = (defaults + self.neededModules + extraOptionImports + additional).sorted() for module in allImports { self.printLine("import \(module)") } } } + +extension Generator: SwiftProtobufPluginLibrary.CodeGenerator { + private func resetAndPrintFile( + for descriptor: SwiftProtobufPluginLibrary.FileDescriptor, with options: GeneratorOptions + ) -> String { + self.namer = SwiftProtobufPluginLibrary.SwiftProtobufNamer( + currentFile: descriptor, + protoFileToModuleMappings: self.options.protoToModuleMappings + ) + self.neededModules = self.options.protoToModuleMappings + .neededModules(forFile: descriptor) ?? [] + self.options = options + self.services = descriptor.services + self.printer = SwiftProtobufPluginLibrary.CodePrinter(indent: " ".unicodeScalars) + self.printContent(for: descriptor) + return self.printer.content + } + + public func generate( + files: [SwiftProtobufPluginLibrary.FileDescriptor], + parameter: any SwiftProtobufPluginLibrary.CodeGeneratorParameter, + protoCompilerContext _: any SwiftProtobufPluginLibrary.ProtoCompilerContext, + generatorOutputs: any SwiftProtobufPluginLibrary.GeneratorOutputs + ) throws { + let options = try GeneratorOptions(commandLineParameters: parameter) + guard options.generateAsyncMethods || options.generateCallbackMethods else { + throw GeneratorError( + message: "Either async methods or callback methods must be enabled" + ) + } + + for descriptor in files where !descriptor.services.isEmpty { + try generatorOutputs.add( + fileName: FilePathComponents(path: descriptor.name).outputFilePath( + withExtension: self.outputFileExtension, using: options.fileNaming + ), + contents: self.resetAndPrintFile(for: descriptor, with: options) + ) + } + } + + public var supportedEditionRange: ClosedRange { + return SwiftProtobufPluginLibrary.DescriptorSet.bundledEditionsSupport + } + + public var supportedFeatures: [ + SwiftProtobufPluginLibrary.Google_Protobuf_Compiler_CodeGeneratorResponse.Feature + ] { + return [ + .proto3Optional, + .supportsEditions, + ] + } +} diff --git a/Plugins/ConnectPluginUtilities/GeneratorOptions.swift b/Plugins/ConnectPluginUtilities/GeneratorOptions.swift index 82d30147..33fc97c6 100644 --- a/Plugins/ConnectPluginUtilities/GeneratorOptions.swift +++ b/Plugins/ConnectPluginUtilities/GeneratorOptions.swift @@ -42,33 +42,6 @@ private enum CommandLineParameter: String { } } } - - static func parse(commandLineParameters: String) throws -> [(key: Self, value: String)] { - return try commandLineParameters - .components(separatedBy: ",") - .compactMap { parameter in - if parameter.isEmpty { - return nil - } - - guard let index = parameter.firstIndex(of: "=") else { - throw Error.unknownParameter(string: parameter) - } - - let rawKey = parameter[.. Self { + return .init() + } +} + +extension GeneratorOptions { /// Initializes a set of generator options from the raw string representation of command line /// parameters (e.g., "Visibility=Internal,KeepMethodCasing=true"). /// - /// Handles trimming whitespace, and some parameters may be specified multiple times. - /// - /// - parameter commandLineParameters: The raw CLI parameters. - public init(commandLineParameters: String) throws { - let parsedParameters = try CommandLineParameter.parse( - commandLineParameters: commandLineParameters - ) - for (key, rawValue) in parsedParameters { - switch key { + /// - parameter commandLineParameters: The CLI parameters. + public init(commandLineParameters: SwiftProtobufPluginLibrary.CodeGeneratorParameter) throws { + for (key, rawValue) in commandLineParameters.parsedPairs { + guard let parsedKey = CommandLineParameter(rawValue: key) else { + throw CommandLineParameter.Error.unknownParameter(string: key) + } + + switch parsedKey { case .extraModuleImports: self.extraModuleImports.append(rawValue) continue @@ -145,9 +123,7 @@ public struct GeneratorOptions { self.protoToModuleMappings = try ProtoFileToModuleMappings(path: rawValue) continue } catch let error { - throw CommandLineParameter.Error.deserializationError( - key: key.rawValue, error: error - ) + throw CommandLineParameter.Error.deserializationError(key: key, error: error) } case .swiftProtobufModuleName: @@ -161,10 +137,7 @@ public struct GeneratorOptions { } } - throw CommandLineParameter.Error.invalidParameterValue( - key: key.rawValue, - value: rawValue - ) + throw CommandLineParameter.Error.invalidParameterValue(key: key, value: rawValue) } } } diff --git a/Plugins/ConnectPluginUtilities/MainGeneratorFunction.swift b/Plugins/ConnectPluginUtilities/MainGeneratorFunction.swift deleted file mode 100644 index 03380bbb..00000000 --- a/Plugins/ConnectPluginUtilities/MainGeneratorFunction.swift +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2022-2024 The Connect Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import Foundation -import SwiftProtobufPluginLibrary - -private struct GeneratorError: Swift.Error { - let message: String -} - -/// Provides the implementation of a `main()` function for generating outputs at runtime -/// using standard in/out and a specific generator type. -public final class MainGeneratorFunction { - private let generatorType: Generator.Type - private let outputFileExtension: String - - public init(generatorType: Generator.Type, outputFileExtension: String) { - self.generatorType = generatorType - self.outputFileExtension = outputFileExtension - } - - public func generateFromStandardInToStandardOut() { - do { - var response = Google_Protobuf_Compiler_CodeGeneratorResponse( - files: [], - supportedFeatures: [.proto3Optional] - ) - let request = try Google_Protobuf_Compiler_CodeGeneratorRequest( - serializedData: FileHandle.standardInput.readDataToEndOfFile() - ) - let descriptors = DescriptorSet(protos: request.protoFile) - let options = try GeneratorOptions(commandLineParameters: request.parameter) - - guard options.generateAsyncMethods || options.generateCallbackMethods else { - throw GeneratorError( - message: "Either async methods or callback methods must be enabled" - ) - } - - for name in request.fileToGenerate { - guard let descriptor = descriptors.fileDescriptor(named: name) else { - continue - } - - if descriptor.services.isEmpty { - continue - } - - response.file.append(.with { outputFile in - outputFile.name = FilePathComponents(path: descriptor.name).outputFilePath( - withExtension: self.outputFileExtension, using: options.fileNaming - ) - outputFile.content = self.generatorType.init( - descriptor, options: options - ).output - }) - } - FileHandle.standardOutput.write(try response.serializedData()) - } catch let error { - FileHandle.standardError.write(("\(error)" + "\n").data(using: .utf8)!) - } - } -} diff --git a/Plugins/ConnectSwiftPlugin/ConnectClientGenerator.swift b/Plugins/ConnectSwiftPlugin/ConnectClientGenerator.swift index a809b068..dc39363f 100644 --- a/Plugins/ConnectSwiftPlugin/ConnectClientGenerator.swift +++ b/Plugins/ConnectSwiftPlugin/ConnectClientGenerator.swift @@ -17,26 +17,27 @@ import Foundation import SwiftProtobufPluginLibrary /// Responsible for generating services and RPCs that are compatible with the Connect library. +@main final class ConnectClientGenerator: Generator { - private let visibility: String + private var visibility = "" - required init(_ descriptor: FileDescriptor, options: GeneratorOptions) { - switch options.visibility { + override var outputFileExtension: String { + ".connect.swift" + } + + override func printContent(for descriptor: FileDescriptor) { + super.printContent(for: descriptor) + + switch self.options.visibility { case .internal: self.visibility = "internal" case .public: self.visibility = "public" } - super.init(descriptor, options: options) - self.printContent() - } - - private func printContent() { - self.printFilePreamble() self.printModuleImports() - for service in self.descriptor.services { + for service in self.services { self.printLine() self.printService(service) } @@ -190,7 +191,7 @@ private extension MethodDescriptor { } func idempotencyLevel() -> String { - switch self.proto.options.idempotencyLevel { + switch self.options.idempotencyLevel { case .idempotencyUnknown: return "unknown" case .noSideEffects: diff --git a/Plugins/ConnectSwiftPlugin/main.swift b/Plugins/ConnectSwiftPlugin/main.swift deleted file mode 100644 index 523f52a6..00000000 --- a/Plugins/ConnectSwiftPlugin/main.swift +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2022-2024 The Connect Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import ConnectPluginUtilities - -MainGeneratorFunction( - generatorType: ConnectClientGenerator.self, outputFileExtension: ".connect.swift" -).generateFromStandardInToStandardOut() From a6b114dabb8cc4fbadb02fda6254ac98def70706 Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Tue, 30 Jul 2024 21:43:14 -0700 Subject: [PATCH 2/5] updates Signed-off-by: Michael Rebello --- Package.swift | 2 +- Plugins/ConnectPluginUtilities/Generator.swift | 17 ++++++++--------- .../GeneratorOptions.swift | 6 +++--- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Package.swift b/Package.swift index 6bbb4550..5405d1ec 100644 --- a/Package.swift +++ b/Package.swift @@ -121,7 +121,6 @@ let package = Package( name: "ConnectMocksPlugin", dependencies: [ "ConnectPluginUtilities", - .product(name: "SwiftProtobuf", package: "swift-protobuf"), .product(name: "SwiftProtobufPluginLibrary", package: "swift-protobuf"), ], path: "Plugins/ConnectMocksPlugin" @@ -146,6 +145,7 @@ let package = Package( .target( name: "ConnectPluginUtilities", dependencies: [ + .product(name: "SwiftProtobuf", package: "swift-protobuf"), .product(name: "SwiftProtobufPluginLibrary", package: "swift-protobuf"), ], path: "Plugins/ConnectPluginUtilities" diff --git a/Plugins/ConnectPluginUtilities/Generator.swift b/Plugins/ConnectPluginUtilities/Generator.swift index d35fda40..542062a3 100644 --- a/Plugins/ConnectPluginUtilities/Generator.swift +++ b/Plugins/ConnectPluginUtilities/Generator.swift @@ -19,16 +19,15 @@ private struct GeneratorError: Swift.Error { let message: String } -/// Base generator class that can be used to output files from Protobuf file descriptors. +/// Base generator class that can be used to generate Swift files from Protobuf file descriptors. /// /// Subclasses must be annotated with `@main` to be properly invoked at runtime. open class Generator { + private var neededModules = [String]() private var printer = SwiftProtobufPluginLibrary.CodePrinter() /// Used for producing type names when generating code. public private(set) var namer = SwiftProtobufPluginLibrary.SwiftProtobufNamer() - /// List of Swift module dependencies required by the current Protobuf file. - public private(set) var neededModules = [String]() /// Options to use when generating code. public private(set) var options = GeneratorOptions.empty() /// List of services specified in the current file. @@ -101,7 +100,7 @@ open class Generator { extension Generator: SwiftProtobufPluginLibrary.CodeGenerator { private func resetAndPrintFile( - for descriptor: SwiftProtobufPluginLibrary.FileDescriptor, with options: GeneratorOptions + for descriptor: SwiftProtobufPluginLibrary.FileDescriptor ) -> String { self.namer = SwiftProtobufPluginLibrary.SwiftProtobufNamer( currentFile: descriptor, @@ -109,7 +108,6 @@ extension Generator: SwiftProtobufPluginLibrary.CodeGenerator { ) self.neededModules = self.options.protoToModuleMappings .neededModules(forFile: descriptor) ?? [] - self.options = options self.services = descriptor.services self.printer = SwiftProtobufPluginLibrary.CodePrinter(indent: " ".unicodeScalars) self.printContent(for: descriptor) @@ -122,8 +120,8 @@ extension Generator: SwiftProtobufPluginLibrary.CodeGenerator { protoCompilerContext _: any SwiftProtobufPluginLibrary.ProtoCompilerContext, generatorOutputs: any SwiftProtobufPluginLibrary.GeneratorOutputs ) throws { - let options = try GeneratorOptions(commandLineParameters: parameter) - guard options.generateAsyncMethods || options.generateCallbackMethods else { + self.options = try GeneratorOptions(commandLineParameters: parameter) + guard self.options.generateAsyncMethods || self.options.generateCallbackMethods else { throw GeneratorError( message: "Either async methods or callback methods must be enabled" ) @@ -132,9 +130,10 @@ extension Generator: SwiftProtobufPluginLibrary.CodeGenerator { for descriptor in files where !descriptor.services.isEmpty { try generatorOutputs.add( fileName: FilePathComponents(path: descriptor.name).outputFilePath( - withExtension: self.outputFileExtension, using: options.fileNaming + withExtension: self.outputFileExtension, + using: self.options.fileNaming ), - contents: self.resetAndPrintFile(for: descriptor, with: options) + contents: self.resetAndPrintFile(for: descriptor) ) } } diff --git a/Plugins/ConnectPluginUtilities/GeneratorOptions.swift b/Plugins/ConnectPluginUtilities/GeneratorOptions.swift index 33fc97c6..8d039e9c 100644 --- a/Plugins/ConnectPluginUtilities/GeneratorOptions.swift +++ b/Plugins/ConnectPluginUtilities/GeneratorOptions.swift @@ -73,17 +73,17 @@ public struct GeneratorOptions { } extension GeneratorOptions { - /// Initializes a set of generator options from the raw string representation of command line + /// Initializes a set of generator options from command line /// parameters (e.g., "Visibility=Internal,KeepMethodCasing=true"). /// /// - parameter commandLineParameters: The CLI parameters. public init(commandLineParameters: SwiftProtobufPluginLibrary.CodeGeneratorParameter) throws { for (key, rawValue) in commandLineParameters.parsedPairs { - guard let parsedKey = CommandLineParameter(rawValue: key) else { + guard let parsedParameter = CommandLineParameter(rawValue: key) else { throw CommandLineParameter.Error.unknownParameter(string: key) } - switch parsedKey { + switch parsedParameter { case .extraModuleImports: self.extraModuleImports.append(rawValue) continue From 309f017c9ba59940c933327a2f59a67ea62d2124 Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Wed, 31 Jul 2024 08:53:05 -0700 Subject: [PATCH 3/5] pr comments Signed-off-by: Michael Rebello --- .../ConnectPluginUtilities/Generator.swift | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/Plugins/ConnectPluginUtilities/Generator.swift b/Plugins/ConnectPluginUtilities/Generator.swift index 542062a3..5c5201fa 100644 --- a/Plugins/ConnectPluginUtilities/Generator.swift +++ b/Plugins/ConnectPluginUtilities/Generator.swift @@ -20,24 +20,18 @@ private struct GeneratorError: Swift.Error { } /// Base generator class that can be used to generate Swift files from Protobuf file descriptors. -/// +/// Not intended to be instantiated directly. /// Subclasses must be annotated with `@main` to be properly invoked at runtime. open class Generator { private var neededModules = [String]() private var printer = SwiftProtobufPluginLibrary.CodePrinter() - /// Used for producing type names when generating code. - public private(set) var namer = SwiftProtobufPluginLibrary.SwiftProtobufNamer() - /// Options to use when generating code. - public private(set) var options = GeneratorOptions.empty() - /// List of services specified in the current file. - public private(set) var services = [SwiftProtobufPluginLibrary.ServiceDescriptor]() - // MARK: - Overridable - /// File extension to use for generated file names. + /// File extension to use for generated file names (e.g., ".connect.swift"). + /// Must be overridden by subclasses. open var outputFileExtension: String { - return ".connect.swift" + fatalError("\(#function) must be overridden by subclasses") } /// Initializer required by `SwiftProtobufPluginLibrary.CodeGenerator`. @@ -58,6 +52,13 @@ open class Generator { // MARK: - Output helpers + /// Used for producing type names when generating code. + public private(set) var namer = SwiftProtobufPluginLibrary.SwiftProtobufNamer() + /// Options to use when generating code. + public private(set) var options = GeneratorOptions.empty() + /// List of services specified in the current file. + public private(set) var services = [SwiftProtobufPluginLibrary.ServiceDescriptor]() + public func indent() { self.printer.indent() } @@ -139,7 +140,13 @@ extension Generator: SwiftProtobufPluginLibrary.CodeGenerator { } public var supportedEditionRange: ClosedRange { - return SwiftProtobufPluginLibrary.DescriptorSet.bundledEditionsSupport + let minEdition = max( + DescriptorSet.bundledEditionsSupport.lowerBound, Google_Protobuf_Edition.legacy + ) + let maxEdition = min( + DescriptorSet.bundledEditionsSupport.upperBound, Google_Protobuf_Edition.edition2024 + ) + return minEdition...maxEdition } public var supportedFeatures: [ From 5921afaa6f634f9e68cc9375a2ad3ab1f78127b5 Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Wed, 31 Jul 2024 08:57:41 -0700 Subject: [PATCH 4/5] update visibility Signed-off-by: Michael Rebello --- Plugins/ConnectPluginUtilities/GeneratorOptions.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/ConnectPluginUtilities/GeneratorOptions.swift b/Plugins/ConnectPluginUtilities/GeneratorOptions.swift index 8d039e9c..cd46c55c 100644 --- a/Plugins/ConnectPluginUtilities/GeneratorOptions.swift +++ b/Plugins/ConnectPluginUtilities/GeneratorOptions.swift @@ -67,7 +67,7 @@ public struct GeneratorOptions { case `public` = "Public" } - public static func empty() -> Self { + static func empty() -> Self { return .init() } } From 26aff6daf59b7460ff13e324b9e30677e3235eb3 Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Wed, 31 Jul 2024 09:11:28 -0700 Subject: [PATCH 5/5] use edition 2023 Signed-off-by: Michael Rebello --- Plugins/ConnectPluginUtilities/Generator.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/ConnectPluginUtilities/Generator.swift b/Plugins/ConnectPluginUtilities/Generator.swift index 5c5201fa..7a6b2573 100644 --- a/Plugins/ConnectPluginUtilities/Generator.swift +++ b/Plugins/ConnectPluginUtilities/Generator.swift @@ -144,7 +144,7 @@ extension Generator: SwiftProtobufPluginLibrary.CodeGenerator { DescriptorSet.bundledEditionsSupport.lowerBound, Google_Protobuf_Edition.legacy ) let maxEdition = min( - DescriptorSet.bundledEditionsSupport.upperBound, Google_Protobuf_Edition.edition2024 + DescriptorSet.bundledEditionsSupport.upperBound, Google_Protobuf_Edition.edition2023 ) return minEdition...maxEdition }