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

codegen: move serviceCompanion to GeneratedCompanion trait. #418

Merged
merged 1 commit into from
Oct 10, 2021
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
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