首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Intellij中找不到Scala2.13和Mill项目中的宏生成源

在Intellij中找不到Scala2.13和Mill项目中的宏生成源
EN

Stack Overflow用户
提问于 2019-10-29 19:31:00
回答 2查看 593关注 0票数 0

我在Scala2.13/ Mill项目中使用齐奥宏

这里的例子是:

代码语言:javascript
运行
复制
@accessible
@mockable
trait AccountObserver {
  val accountObserver: AccountObserver.Service[Any]
}

object AccountObserver {
  trait Service[R] {
    def processEvent(event: String): ZIO[R, Nothing, Unit]
  }

  // autogenerated `object Service { ... }`
  // autogenerated `object > extends Service[AccountObserver] { ... }`
  // autogenerated `implicit val mockable: Mockable[AccountObserver] = ...`
}

我可以运行测试,它可以找到自动生成的代码。

问题是,在Intellij中,对自动生成的代码的引用做而不是编译。

我是否必须配置某些东西,或者缺少什么?

EN

Stack Overflow用户

发布于 2019-10-29 22:07:27

下面的项目编译

build.sc

代码语言:javascript
运行
复制
import mill._, scalalib._

object root extends ScalaModule {
  def scalaVersion = "2.13.1"
  val zioMacrosV = "0.4.0"
  def ivyDeps = Agg(
    ivy"dev.zio::zio-macros-core:${zioMacrosV}",
    ivy"dev.zio::zio-macros-access:${zioMacrosV}",
    ivy"dev.zio::zio-macros-mock:${zioMacrosV}"
  )
  def scalacOptions = Seq(
    "-Ymacro-annotations",
    "-Ymacro-debug-lite"
  )
}

root/src/App.scala

代码语言:javascript
运行
复制
import zio.ZIO
import zio.macros.access.accessible
import zio.macros.mock.mockable

@accessible
@mockable
trait AccountObserver {
  val accountObserver: AccountObserver.Service[Any]
}

object AccountObserver {
  trait Service[R] {
    def processEvent(event: String): ZIO[R, Nothing, Unit]
  }
}

命令mill root.compile编译项目

代码语言:javascript
运行
复制
//{
//  abstract trait AccountObserver extends scala.AnyRef {
//    val accountObserver: AccountObserver.Service[Any]
//  };
//  object AccountObserver extends scala.AnyRef {
//    def <init>() = {
//      super.<init>();
//      ()
//    };
//    abstract trait Service[R] extends scala.AnyRef {
//      def processEvent(event: String): ZIO[R, Nothing, Unit]
//    };
//    object Service extends scala.AnyRef {
//      def <init>() = {
//        super.<init>();
//        ()
//      };
//      case object processEvent extends _root_.zio.test.mock.Method[String, Unit] with scala.Product with scala.Serializable {
//        def <init>() = {
//          super.<init>();
//          ()
//        }
//      }
//    };
//    implicit val mockable: _root_.zio.test.mock.Mockable[AccountObserver] = ((mock: _root_.zio.test.mock.Mock) => {
//      final class $anon extends AccountObserver {
//        def <init>() = {
//          super.<init>();
//          ()
//        };
//        val accountObserver = {
//          final class $anon extends Service[Any] {
//            def <init>() = {
//              super.<init>();
//              ()
//            };
//            def processEvent(event: String): _root_.zio.IO[Nothing, Unit] = mock(Service.processEvent, event)
//          };
//          new $anon()
//        }
//      };
//      new $anon()
//    });
//    object $greater extends Service[AccountObserver] {
//      def <init>() = {
//        super.<init>();
//        ()
//      };
//      def processEvent(event: String): _root_.zio.IO[Nothing, Unit] = _root_.zio.ZIO.accessM(<empty> match {
//        case (env @ (_: AccountObserver)) => env.accountObserver.processEvent(event)
//      })
//    }
//  };
//  ()
//}

创建IntelliJ文件

代码语言:javascript
运行
复制
mill mill.scalalib.GenIdea/idea

然后在IntelliJ中打开项目(不要导入 it)。

现在,Ctrl+Shift+F9编译项目(类似于上面)。

例如,可以使用对对象AccountObserver.Service的引用(这是编译的)。当然,IntelliJ将Service高亮为红色,但这并不重要。

票数 1
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58614222

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档