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

Restructure project to test SourceGen code generation #2

Merged
merged 12 commits into from
Sep 21, 2021
15 changes: 11 additions & 4 deletions FishyTransport/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ let package = Package(
"FishyActorTransportPlugin"
]
),

// would be provided by transport library
.executable(
name: "FishyActorsGenerator",
Expand Down Expand Up @@ -80,12 +80,12 @@ let package = Package(
"FishyActorsGenerator"
]
),

.executableTarget(
name: "FishyActorsGenerator",
dependencies: [
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
]
),

Expand All @@ -94,11 +94,18 @@ let package = Package(
.testTarget(
name: "FishyActorTransportTests",
dependencies: [
"FishyActorTransport"
"FishyActorTransport",
],
swiftSettings: [
.unsafeFlags(experimentalFlags)
]
),

.testTarget(
name: "FishyActorsGeneratorTests",
dependencies: [
"FishyActorsGenerator",
]
),
]
)
10 changes: 5 additions & 5 deletions FishyTransport/Sources/FishyActorsGenerator/Analysis.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class Analysis: SyntaxVisitor {
self.verbose = verbose
}

func run() {
public func run() {
let enumerator = FileManager.default.enumerator(atPath: sourceDirectory)
while let path = enumerator?.nextObject() as? String {
guard path.hasSuffix(".swift") else {
Expand Down Expand Up @@ -112,7 +112,7 @@ final class Analysis: SyntaxVisitor {

let resultTypeNaive: String
if let t = node.signature.output?.returnType {
resultTypeNaive = "\(t)"
resultTypeNaive = "\(t.withoutTrivia())"
} else {
// pretty naive representation, prefer an enum
resultTypeNaive = "Void"
Expand All @@ -121,11 +121,11 @@ final class Analysis: SyntaxVisitor {
// TODO: this is just a naive implementation, we'd carry all information here
let fun = FuncDecl(
access: .internal,
name: node.identifier.text.trimmingCharacters(in: .whitespaces),
name: node.identifier.withoutTrivia().text,
params: node.signature.gatherParams(),
throwing: isThrowing,
async: isAsync,
result: resultTypeNaive.trimmingCharacters(in: .whitespaces)
result: resultTypeNaive
)
actorDecl.funcs.append(fun)

Expand Down Expand Up @@ -205,7 +205,7 @@ extension FunctionSignatureSyntax {
// ==== ----------------------------------------------------------------------------------------------------------------
// MARK: Analysis decls

struct DistributedActorDecl {
public struct DistributedActorDecl {
let access: AccessControl
let name: String
var funcs: [FuncDecl]
Expand Down
Loading