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

Supports inner imports within @service macro. #101

Merged
merged 1 commit into from
Dec 19, 2017
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: 13 additions & 3 deletions rpc/src/main/scala/internal/service/service.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ object serviceImpl {
def serviceExtras(name: Type.Name, alg: Defn): Term.Block = {
import utils._
val serviceAlg = ServiceAlg(alg)
Term.Block(Seq(alg) ++ Seq(mkCompanion(name, enrich(serviceAlg, Nil))))
Term.Block(Seq(alg) ++ Seq(mkCompanion(name, enrich(serviceAlg, serviceAlg.innerImports))))
}

def enrich(serviceAlg: TaglessServiceAlg, companion: Object): Object = companion match {
Expand Down Expand Up @@ -84,8 +84,18 @@ trait RPCService {
case t: Trait => (t.name, t.templ)
}

val requests: List[RPCRequest] =
buildRequests(algName, typeParam, template.stats.toList.flatten)
val allServiceStats: List[Stat] = template.stats.toList.flatten

val rpcMethods: List[Stat] = allServiceStats.filter { s =>
s match {
case q"import ..$_" => false
case _ => true
}
}

val innerImports: List[Stat] = (allServiceStats.toSet -- rpcMethods).toList

val requests: List[RPCRequest] = buildRequests(algName, typeParam, rpcMethods)

val methodDescriptors: Seq[Defn.Val] = requests.map(_.methodDescriptor)

Expand Down
9 changes: 9 additions & 0 deletions rpc/src/test/scala/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ object Utils extends CommonUtils {
@service
trait RPCService[F[_]] {

import ExternalScope._

@rpc(Protobuf) def notAllowed(b: Boolean): F[C]

@rpc(Avro) def unary(a: A): F[C]
Expand Down Expand Up @@ -58,6 +60,9 @@ object Utils extends CommonUtils {
@rpc(Avro)
@stream[BidirectionalStreaming.type]
def biStreaming(oe: Observable[E]): F[Observable[E]]

@rpc(Protobuf)
def scope(empty: Empty.type): F[External]
}

}
Expand Down Expand Up @@ -114,6 +119,10 @@ object Utils extends CommonUtils {
}

def save(e: E) = e // do something else with e?

import ExternalScope._

override def scope(empty: protocol.Empty.type): F[External] = C.capture(External(e1))
}

}
Expand Down
4 changes: 4 additions & 0 deletions rpc/src/test/scala/models.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ case class C(foo: String, a: A)
case class D(bar: Int)

case class E(a: A, foo: String)

object ExternalScope {
case class External(e: E)
}
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "0.5.1-SNAPSHOT"
version in ThisBuild := "0.5.1"