Skip to content

Commit

Permalink
Merge pull request #418 from typelevel/wip-move-code-gen-to-companion…
Browse files Browse the repository at this point in the history
…-trait

codegen: move `serviceCompanion` to `GeneratedCompanion` trait.
  • Loading branch information
ahjohannessen authored Oct 10, 2021
2 parents 906a3ab + 29ac22b commit 6b87b7a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
5 changes: 0 additions & 5 deletions codegen/src/main/scala/Fs2GrpcServicePrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,13 @@ class Fs2GrpcServicePrinter(service: ServiceDescriptor, serviceSuffix: String, d

private[this] def serviceObject: PrinterEndo =
_.add(s"object $serviceNameFs2 extends $Companion[$serviceNameFs2] {").indent.newline
.call(serviceCompanion)
.newline
.call(serviceClient)
.newline
.call(serviceBinding)
.outdent
.newline
.add("}")

private[this] def serviceCompanion: PrinterEndo =
_.add(s"implicit def serviceCompanion: $Companion[$serviceNameFs2] = this")

private[this] def serviceClient: PrinterEndo = {
_.add(
s"def client[F[_]: $Async, $Ctx](dispatcher: $Dispatcher[F], channel: $Channel, mkMetadata: $Ctx => $Metadata, clientOptions: $ClientOptions): $serviceNameFs2[F, $Ctx] = new $serviceNameFs2[F, $Ctx] {"
Expand Down
2 changes: 0 additions & 2 deletions e2e/src/test/resources/TestServiceFs2Grpc.scala.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ trait TestServiceFs2Grpc[F[_], A] {

object TestServiceFs2Grpc extends _root_.fs2.grpc.GeneratedCompanion[TestServiceFs2Grpc] {

implicit def serviceCompanion: _root_.fs2.grpc.GeneratedCompanion[TestServiceFs2Grpc] = this

def client[F[_]: _root_.cats.effect.Async, A](dispatcher: _root_.cats.effect.std.Dispatcher[F], channel: _root_.io.grpc.Channel, mkMetadata: A => _root_.io.grpc.Metadata, clientOptions: _root_.fs2.grpc.client.ClientOptions): TestServiceFs2Grpc[F, A] = new TestServiceFs2Grpc[F, A] {
def noStreaming(request: hello.world.TestMessage, ctx: A): F[hello.world.TestMessage] = {
_root_.fs2.grpc.client.Fs2ClientCall[F](channel, hello.world.TestServiceGrpc.METHOD_NO_STREAMING, dispatcher, clientOptions).flatMap(_.unaryToUnaryCall(request, mkMetadata(ctx)))
Expand Down
5 changes: 5 additions & 0 deletions e2e/src/test/scala/fs2/grpc/e2e/CodegenSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ package e2e
import java.io.File
import scala.io.Source
import buildinfo.BuildInfo.sourceManaged
import hello.world._

class Fs2CodeGeneratorSpec extends munit.FunSuite {

Expand All @@ -41,4 +42,8 @@ class Fs2CodeGeneratorSpec extends munit.FunSuite {

}

test("implicit of companion resolves") {
implicitly[GeneratedCompanion[TestServiceFs2Grpc]]
}

}
2 changes: 2 additions & 0 deletions runtime/src/main/scala/GeneratedCompanion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import fs2.grpc.server.ServerOptions

trait GeneratedCompanion[Service[*[_], _]] {

implicit final def serviceCompanion: GeneratedCompanion[Service] = this

///=== Client ==========================================================================================================

def client[F[_]: Async, A](
Expand Down

0 comments on commit 6b87b7a

Please sign in to comment.