-
In emacs >= 29.1, they natively provide eglot, a client for language server protocol (lsp). If you have lower version of emacs, you need to install eglot. So it will use metals as Scala LSP.
-
Install metals for emacs as followed.
coursier bootstrap \
--java-opt -XX:+UseG1GC \
--java-opt -XX:+UseStringDeduplication \
--java-opt -Xss4m \
--java-opt -Xms100m \
--java-opt -Dmetals.client=emacs \
org.scalameta:metals_2.13:1.3.5 -o metals -f
I learn this from the metals’ website here. It says that
The
-Dmetals.client=emacs
flag is important since it configures Metals for usage with Emacs.
But they did not add it into their formula, to my surprise. So I add it here.
-
Once you have installed metals, put it anywhere that PATH could find it.
-
Here is my Scala configuration. I also have some key bindings for eglot, which include the common commands I use often. When you open your Scala file, it should be under Scala-mode. And you can then
M-x eglot
to start metals automatically. -
If you want to use Ammonite as REPL, I have a script:
import os._
import ammonite.*
object AmmMain {
def main(args: Array[String]): Unit = {
ammonite.Main().run()
}
}
Then you can use SBT to run the main function AmmMain to enter Ammonite REPL.
Note that the latest Ammonite supports Scala 3.5.1, here is how I add it in my build.sbt
libbraryDependencies += "com.lihaoyi" % "ammonite" % "3.0.0" cross CrossVersion.full
Hope you can use metals successfully in your Emacs. Previously, before metals, I used ENSIME a lot. and it just worked and was really great! I am a big fan of ENSIME. But once it was archived, I tried to use it but failed lots of times. So now I use metals, which is also an amazing tool.