Skip to content

Commit

Permalink
Supports inner imports within @service macro. (#101)
Browse files Browse the repository at this point in the history
* Releases a new patch version -> 0.5.1
  • Loading branch information
juanpedromoreno authored Dec 19, 2017
1 parent 1ba7879 commit 616651a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
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"

0 comments on commit 616651a

Please sign in to comment.