Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sendable conformance to generated struct #86

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Sources/StringGenerator/Extensions/InheritanceClauseSyntax.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import SwiftSyntax
import SwiftSyntaxBuilder

extension InheritanceClauseSyntax {
init(_ types: TokenSyntax.MetaType...) {
self.init(types)
}

init(_ types: [TokenSyntax.MetaType]) {
self.init {
for type in types {
InheritedTypeSyntax(type: IdentifierTypeSyntax(name: .type(type)))
}
}
}
}
1 change: 1 addition & 0 deletions Sources/StringGenerator/Extensions/TokenSyntax+Types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extension TokenSyntax {
case CVarArg
case LocalizedStringKey
case Text
case Sendable
}

static func type(_ value: MetaType) -> TokenSyntax {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct StringStringsTableArgumentEnumSnippet: Snippet {
let argument: SourceFile.StringExtension.StringsTableStruct.ArgumentEnum

var syntax: some DeclSyntaxProtocol {
EnumDeclSyntax(name: argument.type) {
EnumDeclSyntax(name: argument.type, inheritanceClause: inheritanceClause) {
MemberBlockItemListSyntax {
for enumCase in argument.cases {
Case(enumCase: enumCase)
Expand All @@ -18,6 +18,10 @@ struct StringStringsTableArgumentEnumSnippet: Snippet {
)
}
}

var inheritanceClause: InheritanceClauseSyntax? {
InheritanceClauseSyntax(.Sendable)
}
}

extension StringStringsTableArgumentEnumSnippet {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct StringStringsTableBundleDescriptionEnumSnippet: Snippet {
let bundleDescription: SourceFile.StringExtension.StringsTableStruct.BundleDescriptionEnum

var syntax: some DeclSyntaxProtocol {
EnumDeclSyntax(name: bundleDescription.type) {
EnumDeclSyntax(name: bundleDescription.type, inheritanceClause: inheritanceClause) {
MemberBlockItemListSyntax {
for enumCase in bundleDescription.cases {
Case(enumCase: enumCase)
Expand All @@ -34,6 +34,10 @@ struct StringStringsTableBundleDescriptionEnumSnippet: Snippet {
StringStringsTableBundleDescriptionCurrentComputedPropertySnippet()
}
}

var inheritanceClause: InheritanceClauseSyntax? {
InheritanceClauseSyntax(.Sendable)
}
}

extension StringStringsTableBundleDescriptionEnumSnippet {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ struct StringStringsTableStructSnippet: Snippet {

var syntax: some DeclSyntaxProtocol {
// /// headerdoc
// public struct Localizable { ... }
// public struct Localizable: Sendable { ... }
StructDeclSyntax(
leadingTrivia: leadingTrivia,
modifiers: modifiers,
name: stringsTable.type,
inheritanceClause: inheritanceClause,
memberBlock: memberBlock
)
}
Expand All @@ -20,6 +21,10 @@ struct StringStringsTableStructSnippet: Snippet {
Trivia(docComment: stringsTable.headerDocumentation)
}

var inheritanceClause: InheritanceClauseSyntax? {
InheritanceClauseSyntax(.Sendable)
}

var memberBlock: MemberBlockSyntax {
MemberBlockSyntax {
// enum BundleDescription { ... }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ extension String {
/// ```
///
/// - SeeAlso: [XCStrings Tool Documentation - Using the generated source code](https://swiftpackageindex.com/liamnichols/xcstrings-tool/0.3.0/documentation/documentation/using-the-generated-source-code)
internal struct FormatSpecifiers {
enum BundleDescription {
internal struct FormatSpecifiers: Sendable {
enum BundleDescription: Sendable {
case main
case atURL(URL)
case forClass(AnyClass)
Expand All @@ -67,7 +67,7 @@ extension String {
}
}

enum Argument {
enum Argument: Sendable {
case int(Int)
case uint(UInt)
case float(Float)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ extension String {
/// ```
///
/// - SeeAlso: [XCStrings Tool Documentation - Using the generated source code](https://swiftpackageindex.com/liamnichols/xcstrings-tool/0.3.0/documentation/documentation/using-the-generated-source-code)
internal struct Localizable {
enum BundleDescription {
internal struct Localizable: Sendable {
enum BundleDescription: Sendable {
case main
case atURL(URL)
case forClass(AnyClass)
Expand All @@ -67,7 +67,7 @@ extension String {
}
}

enum Argument {
enum Argument: Sendable {
case int(Int)
case uint(UInt)
case float(Float)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ extension String {
/// ```
///
/// - SeeAlso: [XCStrings Tool Documentation - Using the generated source code](https://swiftpackageindex.com/liamnichols/xcstrings-tool/0.3.0/documentation/documentation/using-the-generated-source-code)
internal struct Multiline {
enum BundleDescription {
internal struct Multiline: Sendable {
enum BundleDescription: Sendable {
case main
case atURL(URL)
case forClass(AnyClass)
Expand All @@ -67,7 +67,7 @@ extension String {
}
}

enum Argument {
enum Argument: Sendable {
case int(Int)
case uint(UInt)
case float(Float)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ extension String {
/// ```
///
/// - SeeAlso: [XCStrings Tool Documentation - Using the generated source code](https://swiftpackageindex.com/liamnichols/xcstrings-tool/0.3.0/documentation/documentation/using-the-generated-source-code)
internal struct Positional {
enum BundleDescription {
internal struct Positional: Sendable {
enum BundleDescription: Sendable {
case main
case atURL(URL)
case forClass(AnyClass)
Expand All @@ -67,7 +67,7 @@ extension String {
}
}

enum Argument {
enum Argument: Sendable {
case int(Int)
case uint(UInt)
case float(Float)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ extension String {
/// ```
///
/// - SeeAlso: [XCStrings Tool Documentation - Using the generated source code](https://swiftpackageindex.com/liamnichols/xcstrings-tool/0.3.0/documentation/documentation/using-the-generated-source-code)
internal struct Simple {
enum BundleDescription {
internal struct Simple: Sendable {
enum BundleDescription: Sendable {
case main
case atURL(URL)
case forClass(AnyClass)
Expand All @@ -67,7 +67,7 @@ extension String {
}
}

enum Argument {
enum Argument: Sendable {
case int(Int)
case uint(UInt)
case float(Float)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ extension String {
/// ```
///
/// - SeeAlso: [XCStrings Tool Documentation - Using the generated source code](https://swiftpackageindex.com/liamnichols/xcstrings-tool/0.3.0/documentation/documentation/using-the-generated-source-code)
internal struct Substitution {
enum BundleDescription {
internal struct Substitution: Sendable {
enum BundleDescription: Sendable {
case main
case atURL(URL)
case forClass(AnyClass)
Expand All @@ -67,7 +67,7 @@ extension String {
}
}

enum Argument {
enum Argument: Sendable {
case int(Int)
case uint(UInt)
case float(Float)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ extension String {
/// ```
///
/// - SeeAlso: [XCStrings Tool Documentation - Using the generated source code](https://swiftpackageindex.com/liamnichols/xcstrings-tool/0.3.0/documentation/documentation/using-the-generated-source-code)
internal struct Variations {
enum BundleDescription {
internal struct Variations: Sendable {
enum BundleDescription: Sendable {
case main
case atURL(URL)
case forClass(AnyClass)
Expand All @@ -67,7 +67,7 @@ extension String {
}
}

enum Argument {
enum Argument: Sendable {
case int(Int)
case uint(UInt)
case float(Float)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ extension String {
/// ```
///
/// - SeeAlso: [XCStrings Tool Documentation - Using the generated source code](https://swiftpackageindex.com/liamnichols/xcstrings-tool/0.3.0/documentation/documentation/using-the-generated-source-code)
package struct Localizable {
enum BundleDescription {
package struct Localizable: Sendable {
enum BundleDescription: Sendable {
case main
case atURL(URL)
case forClass(AnyClass)
Expand All @@ -67,7 +67,7 @@ extension String {
}
}

enum Argument {
enum Argument: Sendable {
case int(Int)
case uint(UInt)
case float(Float)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ extension String {
/// ```
///
/// - SeeAlso: [XCStrings Tool Documentation - Using the generated source code](https://swiftpackageindex.com/liamnichols/xcstrings-tool/0.3.0/documentation/documentation/using-the-generated-source-code)
public struct Localizable {
enum BundleDescription {
public struct Localizable: Sendable {
enum BundleDescription: Sendable {
case main
case atURL(URL)
case forClass(AnyClass)
Expand All @@ -67,7 +67,7 @@ extension String {
}
}

enum Argument {
enum Argument: Sendable {
case int(Int)
case uint(UInt)
case float(Float)
Expand Down
Loading