11

我有一个名为 Scala 的项目,我使用和scala-playground为 Ensime 生成了配置。sbt ensimeConfigsbt ensimeConfigProject

从项目的缓冲区运行M-x ensime时,我可以在 Emacs 状态栏中看到 Ensime 已连接:它显示Scala[scala-playground].

使用 运行项目时C-c C-b r,会在主目录中启动一个新的 sbt 实例,$HOME/project创建一个目录,而不是项目目录,但失败:

[info] Loading project definition from /home/user/project
[info] Set current project to user (in build file:/home/user/)
[info] sbt server started at 127.0.0.1:4766
sbt:user> 
sbt:user> run
[error] java.lang.RuntimeException: No main class detected.
[error]     at scala.sys.package$.error(package.scala:27)
[error]     at sbt.Defaults$.$anonfun$runTask$4(Defaults.scala:1199)
[error]     at scala.Option.getOrElse(Option.scala:121)
[error]     at sbt.Defaults$.$anonfun$runTask$3(Defaults.scala:1199)
[error]     at sbt.Defaults$.$anonfun$runTask$3$adapted(Defaults.scala:1198)
[error]     at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error]     at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:42)
[error]     at sbt.std.Transform$$anon$4.work(System.scala:64)
[error]     at sbt.Execute.$anonfun$submit$2(Execute.scala:257)
[error]     at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
[error]     at sbt.Execute.work(Execute.scala:266)
[error]     at sbt.Execute.$anonfun$submit$1(Execute.scala:257)
[error]     at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:167)
[error]     at sbt.CompletionService$$anon$2.call(CompletionService.scala:32)
[error]     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error]     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error]     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error]     at java.lang.Thread.run(Thread.java:748)
[error] (compile:run) No main class detected.
[error] Total time: 0 s, completed Aug 28, 2017 9:10:03 PM

到底是怎么回事?

4

1 回答 1

15

短篇故事

删除~/project文件夹,然后启动 emacs。

很长的故事

如果您曾经sbt在您的$HOME目录中运行,它会在那里创建基本的项目结构,主要是projecttarget目录。然后,如果您打开任何*.scala文件,emacs ( sbt-mode) 将沿着您的路径查找根项目目录。它会在您的$HOME. 您可以在文档中看到它:

Starting from the current default-directory, find a parent
directory that is an sbt root. An sbt root directory is
identified by the following rules:

   - a directory containing a 'project/build.properties' in it.

   - a directory that contains a file matching one of the patterns
    '*.sbt' or 'project/*.scala' file in it.

当前实现的一个问题是,这个过程每个缓冲区只执行一次。如果sbt:buffer-project-root变量被设置一次,它将不会被更新。

您可以通过重新启动 emacs 或通过评估(setq-local sbt:buffer-project-root nil)每个打开的缓冲区来强制一个新值,然后以通常的方式启动 sbt form emacs。

如果您从任何具有错误值的缓冲区中删除~/project并运行,它将在 home 中启动 sbt,这将再次创建。再说一遍,最简单的方法是杀死 emacs,删除目录,然后重新启动 emacs。ensime-sbtsbt:buffer-project-root~/project

于 2017-09-20T19:16:48.493 回答