Skip to content

Commit 3937918

Browse files
committed
Use Fs2GrpcRenderContextAsImplicit code generator option
1 parent af59271 commit 3937918

11 files changed

+51
-39
lines changed

build.sbt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,20 @@ lazy val e2e = (projectMatrix in file("e2e"))
152152
val output = (Compile / sourceManaged).value / "fs2-grpc" / "disable-trailers"
153153
}
154154

155-
val ctxAsImplicitParam = new {
155+
val renderContextAsImplicit = new {
156156
val args = Seq(
157-
"serviceSuffix=Fs2GrpcCtxAsImplicitParam",
158-
"ctxAsImplicitParam=true"
157+
"serviceSuffix=Fs2GrpcRenderContextAsImplicit",
158+
"fs2_grpc:render_context_as_implicit"
159159
) ++ (if (tlIsScala3.value) Seq("scala3_sources") else Nil)
160160

161-
val output = (Compile / sourceManaged).value / "fs2-grpc" / "ctx-as-implicit-param"
161+
val output = (Compile / sourceManaged).value / "fs2-grpc" / "render-context-as-implicit"
162162
}
163163

164164
Seq(
165165
scalapb.gen() -> (Compile / sourceManaged).value / "scalapb",
166166
genModule(codegenFullName + "$") -> (Compile / sourceManaged).value / "fs2-grpc",
167-
(genModule(codegenFullName + "$"), disableTrailers.args) -> disableTrailers.output
167+
(genModule(codegenFullName + "$"), disableTrailers.args) -> disableTrailers.output,
168+
(genModule(codegenFullName + "$"), renderContextAsImplicit.args) -> renderContextAsImplicit.output
168169
)
169170
},
170171
buildInfoPackage := "fs2.grpc.e2e.buildinfo",

codegen/src/main/scala/fs2/grpc/codegen/Fs2AbstractServicePrinter.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ abstract class Fs2AbstractServicePrinter extends Fs2ServicePrinter {
3232
val service: ServiceDescriptor
3333
val serviceSuffix: String
3434
val di: DescriptorImplicits
35-
protected[this] val ctxAsImplicitParam: Boolean = false
35+
protected[this] val renderContextAsImplicit: Boolean = false
3636
protected[this] val scala3Sources: Boolean = false
3737

3838
import di._
@@ -58,7 +58,7 @@ abstract class Fs2AbstractServicePrinter extends Fs2ServicePrinter {
5858
}
5959

6060
protected[this] def renderCtxParameter(): String = {
61-
if (ctxAsImplicitParam) {
61+
if (renderContextAsImplicit) {
6262
if (scala3Sources) {
6363
s")(using ctx: $Ctx"
6464
} else {
@@ -93,7 +93,7 @@ abstract class Fs2AbstractServicePrinter extends Fs2ServicePrinter {
9393
val handler = s"$Fs2ServerCallHandler[G](dispatcher, serverOptions).${handleMethod(method)}[$inType, $outType]"
9494

9595
val serviceCall = s"serviceImpl.${method.name}"
96-
val invoke = if (ctxAsImplicitParam) {
96+
val invoke = if (renderContextAsImplicit) {
9797
if (scala3Sources) {
9898
s"$serviceCall(r)(using m)"
9999
} else {

codegen/src/main/scala/fs2/grpc/codegen/Fs2CodeGenerator.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ object Fs2Params {
6565
copy(disableTrailers = value)
6666

6767
def withRenderContextAsImplicit(value: Boolean): Fs2Params =
68-
copy(ctxAsImplicitParam = value)
68+
copy(renderContextAsImplicit = value)
6969

7070
def withScala3Sources(value: Boolean): Fs2Params =
7171
copy(scala3Sources = value)

codegen/src/main/scala/fs2/grpc/codegen/Fs2GrpcExhaustiveTrailersServicePrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import scalapb.compiler.{DescriptorImplicits, StreamType}
2727
class Fs2GrpcExhaustiveTrailersServicePrinter(
2828
val service: ServiceDescriptor,
2929
val serviceSuffix: String,
30-
override val ctxAsImplicitParam: Boolean,
30+
override val renderContextAsImplicit: Boolean,
3131
override val scala3Sources: Boolean,
3232
val di: DescriptorImplicits
3333
) extends Fs2AbstractServicePrinter {

codegen/src/main/scala/fs2/grpc/codegen/Fs2GrpcServicePrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import scalapb.compiler.{DescriptorImplicits, StreamType}
2727
class Fs2GrpcServicePrinter(
2828
val service: ServiceDescriptor,
2929
val serviceSuffix: String,
30-
override val ctxAsImplicitParam: Boolean,
30+
override val renderContextAsImplicit: Boolean,
3131
override val scala3Sources: Boolean,
3232
val di: DescriptorImplicits
3333
) extends Fs2AbstractServicePrinter {

e2e/src/test/resources/TestServiceFs2GrpcCtxAsImplicitParam.scala.txt renamed to e2e/src/test/resources/TestServiceFs2GrpcRenderContextAsImplicit.scala.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import _root_.cats.syntax.all._
55
/** TestService: Example gRPC service used in e2e tests
66
* It demonstrates all four RPC shapes.
77
*/
8-
trait TestServiceFs2GrpcCtxAsImplicitParam[F[_], A] {
8+
trait TestServiceFs2GrpcRenderContextAsImplicit[F[_], A] {
99
/** Unary RPC: no streaming in either direction
1010
*/
1111
def noStreaming(request: hello.world.TestMessage)(implicit ctx: A): F[hello.world.TestMessage]
@@ -20,7 +20,7 @@ trait TestServiceFs2GrpcCtxAsImplicitParam[F[_], A] {
2020
def bothStreaming(request: _root_.fs2.Stream[F, hello.world.TestMessage])(implicit ctx: A): _root_.fs2.Stream[F, hello.world.TestMessage]
2121
}
2222

23-
object TestServiceFs2GrpcCtxAsImplicitParam extends _root_.fs2.grpc.GeneratedCompanion[TestServiceFs2GrpcCtxAsImplicitParam] {
23+
object TestServiceFs2GrpcRenderContextAsImplicit extends _root_.fs2.grpc.GeneratedCompanion[TestServiceFs2GrpcRenderContextAsImplicit] {
2424

2525
def serviceDescriptor: _root_.io.grpc.ServiceDescriptor = hello.world.TestServiceGrpc.SERVICE
2626

@@ -29,7 +29,7 @@ object TestServiceFs2GrpcCtxAsImplicitParam extends _root_.fs2.grpc.GeneratedCom
2929
channel: _root_.io.grpc.Channel,
3030
clientAspect: _root_.fs2.grpc.client.ClientAspect[F, G, A],
3131
clientOptions: _root_.fs2.grpc.client.ClientOptions
32-
): TestServiceFs2GrpcCtxAsImplicitParam[F, A] = new TestServiceFs2GrpcCtxAsImplicitParam[F, A] {
32+
): TestServiceFs2GrpcRenderContextAsImplicit[F, A] = new TestServiceFs2GrpcRenderContextAsImplicit[F, A] {
3333
def noStreaming(request: hello.world.TestMessage)(implicit ctx: A): F[hello.world.TestMessage] =
3434
clientAspect.visitUnaryToUnaryCall[hello.world.TestMessage, hello.world.TestMessage](
3535
_root_.fs2.grpc.client.ClientCallContext(ctx, hello.world.TestServiceGrpc.METHOD_NO_STREAMING),
@@ -58,7 +58,7 @@ object TestServiceFs2GrpcCtxAsImplicitParam extends _root_.fs2.grpc.GeneratedCom
5858

5959
protected def serviceBindingFull[F[_], G[_]: _root_.cats.effect.Async, A](
6060
dispatcher: _root_.cats.effect.std.Dispatcher[G],
61-
serviceImpl: TestServiceFs2GrpcCtxAsImplicitParam[F, A],
61+
serviceImpl: TestServiceFs2GrpcRenderContextAsImplicit[F, A],
6262
serviceAspect: _root_.fs2.grpc.server.ServiceAspect[F, G, A],
6363
serverOptions: _root_.fs2.grpc.server.ServerOptions
6464
) = {

e2e/src/test/resources/TestServiceFs2GrpcCtxAsImplicitParamScala3.scala.txt renamed to e2e/src/test/resources/TestServiceFs2GrpcRenderContextAsImplicitScala3.scala.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import _root_.cats.syntax.all.*
55
/** TestService: Example gRPC service used in e2e tests
66
* It demonstrates all four RPC shapes.
77
*/
8-
trait TestServiceFs2GrpcCtxAsImplicitParam[F[_], A] {
8+
trait TestServiceFs2GrpcRenderContextAsImplicit[F[_], A] {
99
/** Unary RPC: no streaming in either direction
1010
*/
1111
def noStreaming(request: hello.world.TestMessage)(using ctx: A): F[hello.world.TestMessage]
@@ -20,7 +20,7 @@ trait TestServiceFs2GrpcCtxAsImplicitParam[F[_], A] {
2020
def bothStreaming(request: _root_.fs2.Stream[F, hello.world.TestMessage])(using ctx: A): _root_.fs2.Stream[F, hello.world.TestMessage]
2121
}
2222

23-
object TestServiceFs2GrpcCtxAsImplicitParam extends _root_.fs2.grpc.GeneratedCompanion[TestServiceFs2GrpcCtxAsImplicitParam] {
23+
object TestServiceFs2GrpcRenderContextAsImplicit extends _root_.fs2.grpc.GeneratedCompanion[TestServiceFs2GrpcRenderContextAsImplicit] {
2424

2525
def serviceDescriptor: _root_.io.grpc.ServiceDescriptor = hello.world.TestServiceGrpc.SERVICE
2626

@@ -29,7 +29,7 @@ object TestServiceFs2GrpcCtxAsImplicitParam extends _root_.fs2.grpc.GeneratedCom
2929
channel: _root_.io.grpc.Channel,
3030
clientAspect: _root_.fs2.grpc.client.ClientAspect[F, G, A],
3131
clientOptions: _root_.fs2.grpc.client.ClientOptions
32-
): TestServiceFs2GrpcCtxAsImplicitParam[F, A] = new TestServiceFs2GrpcCtxAsImplicitParam[F, A] {
32+
): TestServiceFs2GrpcRenderContextAsImplicit[F, A] = new TestServiceFs2GrpcRenderContextAsImplicit[F, A] {
3333
def noStreaming(request: hello.world.TestMessage)(using ctx: A): F[hello.world.TestMessage] =
3434
clientAspect.visitUnaryToUnaryCall[hello.world.TestMessage, hello.world.TestMessage](
3535
_root_.fs2.grpc.client.ClientCallContext(ctx, hello.world.TestServiceGrpc.METHOD_NO_STREAMING),
@@ -58,7 +58,7 @@ object TestServiceFs2GrpcCtxAsImplicitParam extends _root_.fs2.grpc.GeneratedCom
5858

5959
protected def serviceBindingFull[F[_], G[_]: _root_.cats.effect.Async, A](
6060
dispatcher: _root_.cats.effect.std.Dispatcher[G],
61-
serviceImpl: TestServiceFs2GrpcCtxAsImplicitParam[F, A],
61+
serviceImpl: TestServiceFs2GrpcRenderContextAsImplicit[F, A],
6262
serviceAspect: _root_.fs2.grpc.server.ServiceAspect[F, G, A],
6363
serverOptions: _root_.fs2.grpc.server.ServerOptions
6464
) = {

e2e/src/test/resources/TestServiceFs2GrpcCtxAsImplicitParamTrailers.scala.txt renamed to e2e/src/test/resources/TestServiceFs2GrpcRenderContextAsImplicitTrailers.scala.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import _root_.cats.syntax.all._
55
/** TestService: Example gRPC service used in e2e tests
66
* It demonstrates all four RPC shapes.
77
*/
8-
trait TestServiceFs2GrpcCtxAsImplicitParamTrailers[F[_], A] {
8+
trait TestServiceFs2GrpcRenderContextAsImplicitTrailers[F[_], A] {
99
/** Unary RPC: no streaming in either direction
1010
*/
1111
def noStreaming(request: hello.world.TestMessage)(implicit ctx: A): F[(hello.world.TestMessage, _root_.io.grpc.Metadata)]
@@ -20,7 +20,7 @@ trait TestServiceFs2GrpcCtxAsImplicitParamTrailers[F[_], A] {
2020
def bothStreaming(request: _root_.fs2.Stream[F, hello.world.TestMessage])(implicit ctx: A): _root_.fs2.Stream[F, hello.world.TestMessage]
2121
}
2222

23-
object TestServiceFs2GrpcCtxAsImplicitParamTrailers extends _root_.fs2.grpc.GeneratedCompanion[TestServiceFs2GrpcCtxAsImplicitParamTrailers] {
23+
object TestServiceFs2GrpcRenderContextAsImplicitTrailers extends _root_.fs2.grpc.GeneratedCompanion[TestServiceFs2GrpcRenderContextAsImplicitTrailers] {
2424

2525
def serviceDescriptor: _root_.io.grpc.ServiceDescriptor = hello.world.TestServiceGrpc.SERVICE
2626

@@ -29,7 +29,7 @@ object TestServiceFs2GrpcCtxAsImplicitParamTrailers extends _root_.fs2.grpc.Gene
2929
channel: _root_.io.grpc.Channel,
3030
clientAspect: _root_.fs2.grpc.client.ClientAspect[F, G, A],
3131
clientOptions: _root_.fs2.grpc.client.ClientOptions
32-
): TestServiceFs2GrpcCtxAsImplicitParamTrailers[F, A] = new TestServiceFs2GrpcCtxAsImplicitParamTrailers[F, A] {
32+
): TestServiceFs2GrpcRenderContextAsImplicitTrailers[F, A] = new TestServiceFs2GrpcRenderContextAsImplicitTrailers[F, A] {
3333
def noStreaming(request: hello.world.TestMessage)(implicit ctx: A): F[(hello.world.TestMessage, _root_.io.grpc.Metadata)] =
3434
clientAspect.visitUnaryToUnaryCallTrailers[hello.world.TestMessage, hello.world.TestMessage](
3535
_root_.fs2.grpc.client.ClientCallContext(ctx, hello.world.TestServiceGrpc.METHOD_NO_STREAMING),
@@ -58,7 +58,7 @@ object TestServiceFs2GrpcCtxAsImplicitParamTrailers extends _root_.fs2.grpc.Gene
5858

5959
protected def serviceBindingFull[F[_], G[_]: _root_.cats.effect.Async, A](
6060
dispatcher: _root_.cats.effect.std.Dispatcher[G],
61-
serviceImpl: TestServiceFs2GrpcCtxAsImplicitParamTrailers[F, A],
61+
serviceImpl: TestServiceFs2GrpcRenderContextAsImplicitTrailers[F, A],
6262
serviceAspect: _root_.fs2.grpc.server.ServiceAspect[F, G, A],
6363
serverOptions: _root_.fs2.grpc.server.ServerOptions
6464
) = {

e2e/src/test/resources/TestServiceFs2GrpcCtxAsImplicitParamTrailersScala3.scala.txt renamed to e2e/src/test/resources/TestServiceFs2GrpcRenderContextAsImplicitTrailersScala3.scala.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import _root_.cats.syntax.all.*
55
/** TestService: Example gRPC service used in e2e tests
66
* It demonstrates all four RPC shapes.
77
*/
8-
trait TestServiceFs2GrpcCtxAsImplicitParamTrailers[F[_], A] {
8+
trait TestServiceFs2GrpcRenderContextAsImplicitTrailers[F[_], A] {
99
/** Unary RPC: no streaming in either direction
1010
*/
1111
def noStreaming(request: hello.world.TestMessage)(using ctx: A): F[(hello.world.TestMessage, _root_.io.grpc.Metadata)]
@@ -20,7 +20,7 @@ trait TestServiceFs2GrpcCtxAsImplicitParamTrailers[F[_], A] {
2020
def bothStreaming(request: _root_.fs2.Stream[F, hello.world.TestMessage])(using ctx: A): _root_.fs2.Stream[F, hello.world.TestMessage]
2121
}
2222

23-
object TestServiceFs2GrpcCtxAsImplicitParamTrailers extends _root_.fs2.grpc.GeneratedCompanion[TestServiceFs2GrpcCtxAsImplicitParamTrailers] {
23+
object TestServiceFs2GrpcRenderContextAsImplicitTrailers extends _root_.fs2.grpc.GeneratedCompanion[TestServiceFs2GrpcRenderContextAsImplicitTrailers] {
2424

2525
def serviceDescriptor: _root_.io.grpc.ServiceDescriptor = hello.world.TestServiceGrpc.SERVICE
2626

@@ -29,7 +29,7 @@ object TestServiceFs2GrpcCtxAsImplicitParamTrailers extends _root_.fs2.grpc.Gene
2929
channel: _root_.io.grpc.Channel,
3030
clientAspect: _root_.fs2.grpc.client.ClientAspect[F, G, A],
3131
clientOptions: _root_.fs2.grpc.client.ClientOptions
32-
): TestServiceFs2GrpcCtxAsImplicitParamTrailers[F, A] = new TestServiceFs2GrpcCtxAsImplicitParamTrailers[F, A] {
32+
): TestServiceFs2GrpcRenderContextAsImplicitTrailers[F, A] = new TestServiceFs2GrpcRenderContextAsImplicitTrailers[F, A] {
3333
def noStreaming(request: hello.world.TestMessage)(using ctx: A): F[(hello.world.TestMessage, _root_.io.grpc.Metadata)] =
3434
clientAspect.visitUnaryToUnaryCallTrailers[hello.world.TestMessage, hello.world.TestMessage](
3535
_root_.fs2.grpc.client.ClientCallContext(ctx, hello.world.TestServiceGrpc.METHOD_NO_STREAMING),
@@ -58,7 +58,7 @@ object TestServiceFs2GrpcCtxAsImplicitParamTrailers extends _root_.fs2.grpc.Gene
5858

5959
protected def serviceBindingFull[F[_], G[_]: _root_.cats.effect.Async, A](
6060
dispatcher: _root_.cats.effect.std.Dispatcher[G],
61-
serviceImpl: TestServiceFs2GrpcCtxAsImplicitParamTrailers[F, A],
61+
serviceImpl: TestServiceFs2GrpcRenderContextAsImplicitTrailers[F, A],
6262
serviceAspect: _root_.fs2.grpc.server.ServiceAspect[F, G, A],
6363
serverOptions: _root_.fs2.grpc.server.ServerOptions
6464
) = {

e2e/src/test/scala/fs2/grpc/e2e/Fs2CodeGeneratorCtxAsImplicitParamSpec.scala renamed to e2e/src/test/scala/fs2/grpc/e2e/Fs2CodeGeneratorRenderContextAsImplicitSpec.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ import hello.world._
2929

3030
import scala.io.Source
3131

32-
class Fs2CodeGeneratorCtxAsImplicitParamSpec extends munit.FunSuite {
32+
class Fs2CodeGeneratorRenderContextAsImplicitSpec extends munit.FunSuite {
3333

34-
val sourcesGenerated = new File(sourceManaged.getAbsolutePath, "ctx-as-implicit-param/hello/world")
34+
val sourcesGenerated = new File(sourceManaged.getAbsolutePath, "render-context-as-implicit/hello/world")
3535
val suffix = if (scalaVersion.startsWith("3")) "Scala3" else ""
3636

3737
test("code generator outputs correct service file") {
38-
val fileName = "TestServiceFs2GrpcCtxAsImplicitParam"
38+
val fileName = "TestServiceFs2GrpcRenderContextAsImplicit"
3939
val testFileName = s"$fileName.scala"
4040
val referenceName = s"$fileName$suffix.scala"
4141
val reference = Source.fromResource(s"$referenceName.txt").getLines().mkString("\n")
@@ -45,7 +45,7 @@ class Fs2CodeGeneratorCtxAsImplicitParamSpec extends munit.FunSuite {
4545
}
4646

4747
test("code generator outputs correct service file for trailers") {
48-
val fileName = s"TestServiceFs2GrpcCtxAsImplicitParamTrailers"
48+
val fileName = s"TestServiceFs2GrpcRenderContextAsImplicitTrailers"
4949
val testFileName = s"$fileName.scala"
5050
val referenceName = s"$fileName$suffix.scala"
5151
val reference = Source.fromResource(s"$referenceName.txt").getLines().mkString("\n")
@@ -55,11 +55,11 @@ class Fs2CodeGeneratorCtxAsImplicitParamSpec extends munit.FunSuite {
5555
}
5656

5757
test("implicit of companion resolves") {
58-
implicitly[GeneratedCompanion[TestServiceFs2GrpcCtxAsImplicitParam]]
58+
implicitly[GeneratedCompanion[TestServiceFs2GrpcRenderContextAsImplicit]]
5959
}
6060

6161
test("implicit of companion resolves trailers") {
62-
implicitly[GeneratedCompanion[TestServiceFs2GrpcCtxAsImplicitParamTrailers]]
62+
implicitly[GeneratedCompanion[TestServiceFs2GrpcRenderContextAsImplicitTrailers]]
6363
}
6464

6565
}

0 commit comments

Comments
 (0)