2015-12-02 14:23:39 +00:00
#+TITLE : Scala layer
2015-06-10 16:44:30 +00:00
2019-05-07 08:53:56 +00:00
#+TAGS : general|layer|multi-paradigm|programming
2019-05-05 17:26:40 +00:00
[scala] remove long-deprecated Ensime integration
According to its website, the Ensime project has been shut down since 2019. We
have been supporting both Ensime and Metals for [a year and a
half](https://github.com/syl20bnr/spacemacs/pull/12234#issuecomment-524916394).
Ensime's GitHub repositories, including its Emacs integration, are archived.
Meanwhile, Metals has been developed actively, regularly releasing new versions.
It has stabilized significantly, and supports an increasingly full set of
features. Scala 3 is just around the corner, and the community is poised to make
the transition smoothly and relatively quickly. Metals supports it already,
whereas of course Ensime does not and never will. In fact, Scala 2 has had
several import minor versions released since Ensime died. Now that it's 2021,
it's time to cut the baggage we are carrying around for Ensime.
2021-01-11 16:14:01 +00:00
[[file:img/scala.png ]] with [[file:img/scalameta.png ]]
2015-06-10 16:44:30 +00:00
2019-05-07 20:05:06 +00:00
* Table of Contents :TOC_5_gh:noexport:
2017-05-22 14:16:12 +00:00
- [[#description ][Description ]]
2018-01-28 19:58:25 +00:00
- [[#features ][Features: ]]
2017-05-22 14:16:12 +00:00
- [[#layer-installation ][Layer Installation ]]
2019-04-26 10:34:11 +00:00
- [[#backends ][Backends ]]
2020-03-12 22:14:11 +00:00
- [[#metals ][Metals ]]
2017-05-22 14:16:12 +00:00
- [[#scalastyle ][Scalastyle ]]
- [[#use-java-doc-style ][Use Java doc-style ]]
2020-04-03 16:00:45 +00:00
- [[#enable-debug-adapter-protocol-dap ][Enable Debug Adapter Protocol (DAP) ]]
2017-05-22 14:16:12 +00:00
- [[#automatically-insert-asterisk-in-multiline-comments ][Automatically insert asterisk in multiline comments ]]
2020-04-03 16:00:45 +00:00
- [[#enable-gtags-as-a-fallback-navigation-utility ][Enable GTags as a fallback navigation utility ]]
2017-05-22 14:16:12 +00:00
- [[#key-bindings ][Key bindings ]]
[scala] remove long-deprecated Ensime integration
According to its website, the Ensime project has been shut down since 2019. We
have been supporting both Ensime and Metals for [a year and a
half](https://github.com/syl20bnr/spacemacs/pull/12234#issuecomment-524916394).
Ensime's GitHub repositories, including its Emacs integration, are archived.
Meanwhile, Metals has been developed actively, regularly releasing new versions.
It has stabilized significantly, and supports an increasingly full set of
features. Scala 3 is just around the corner, and the community is poised to make
the transition smoothly and relatively quickly. Metals supports it already,
whereas of course Ensime does not and never will. In fact, Scala 2 has had
several import minor versions released since Ensime died. Now that it's 2021,
it's time to cut the baggage we are carrying around for Ensime.
2021-01-11 16:14:01 +00:00
- [[#sbt ][sbt ]]
2015-06-10 16:44:30 +00:00
* Description
2018-01-28 19:58:25 +00:00
This layer adds support for the Scala language to Spacemacs.
** Features:
- Syntax highlighting
[scala] remove long-deprecated Ensime integration
According to its website, the Ensime project has been shut down since 2019. We
have been supporting both Ensime and Metals for [a year and a
half](https://github.com/syl20bnr/spacemacs/pull/12234#issuecomment-524916394).
Ensime's GitHub repositories, including its Emacs integration, are archived.
Meanwhile, Metals has been developed actively, regularly releasing new versions.
It has stabilized significantly, and supports an increasingly full set of
features. Scala 3 is just around the corner, and the community is poised to make
the transition smoothly and relatively quickly. Metals supports it already,
whereas of course Ensime does not and never will. In fact, Scala 2 has had
several import minor versions released since Ensime died. Now that it's 2021,
it's time to cut the baggage we are carrying around for Ensime.
2021-01-11 16:14:01 +00:00
- Support for language backend using LSP and [[https://scalameta.org/metals/ ][Metals ]]
- Debugging support via =dap=
2018-01-28 19:58:25 +00:00
- Auto-completion
2020-04-03 16:00:45 +00:00
- Treeview support for viewing project structure and triggering compilation
2018-01-28 19:58:25 +00:00
- Syntax-checking
- Refactoring
- Incremental compilation
- Style linting
2020-04-03 16:00:45 +00:00
- Optional GGTags search
2015-06-10 16:44:30 +00:00
* Layer Installation
2016-01-06 05:21:55 +00:00
To use this configuration layer, add it to your =~/.spacemacs= . You will need to
add =scala= to the existing =dotspacemacs-configuration-layers= list in this
file.
2021-03-20 21:02:09 +00:00
+ To turn on the Metals tree view side bar, set =scala-auto-treeview= to =t= .
2021-01-11 18:05:05 +00:00
+ To display SBT in a small buffer at the bottom of the frame, set the
=scala-sbt-window-position= layer variable to =bottom= .
2019-04-26 10:34:11 +00:00
* Backends
[scala] remove long-deprecated Ensime integration
According to its website, the Ensime project has been shut down since 2019. We
have been supporting both Ensime and Metals for [a year and a
half](https://github.com/syl20bnr/spacemacs/pull/12234#issuecomment-524916394).
Ensime's GitHub repositories, including its Emacs integration, are archived.
Meanwhile, Metals has been developed actively, regularly releasing new versions.
It has stabilized significantly, and supports an increasingly full set of
features. Scala 3 is just around the corner, and the community is poised to make
the transition smoothly and relatively quickly. Metals supports it already,
whereas of course Ensime does not and never will. In fact, Scala 2 has had
several import minor versions released since Ensime died. Now that it's 2021,
it's time to cut the baggage we are carrying around for Ensime.
2021-01-11 16:14:01 +00:00
The only currently supported language backend is =scala-metals= . Support for
Ensime has been dropped as that project has been dead for some time.
2020-03-12 22:14:11 +00:00
** Metals
[scala] remove long-deprecated Ensime integration
According to its website, the Ensime project has been shut down since 2019. We
have been supporting both Ensime and Metals for [a year and a
half](https://github.com/syl20bnr/spacemacs/pull/12234#issuecomment-524916394).
Ensime's GitHub repositories, including its Emacs integration, are archived.
Meanwhile, Metals has been developed actively, regularly releasing new versions.
It has stabilized significantly, and supports an increasingly full set of
features. Scala 3 is just around the corner, and the community is poised to make
the transition smoothly and relatively quickly. Metals supports it already,
whereas of course Ensime does not and never will. In fact, Scala 2 has had
several import minor versions released since Ensime died. Now that it's 2021,
it's time to cut the baggage we are carrying around for Ensime.
2021-01-11 16:14:01 +00:00
Currently, you must manually install the Metals server. It is possible to do so
2020-03-12 22:14:11 +00:00
via coursier; the latest version can be built using the following commands,
[scala] remove long-deprecated Ensime integration
According to its website, the Ensime project has been shut down since 2019. We
have been supporting both Ensime and Metals for [a year and a
half](https://github.com/syl20bnr/spacemacs/pull/12234#issuecomment-524916394).
Ensime's GitHub repositories, including its Emacs integration, are archived.
Meanwhile, Metals has been developed actively, regularly releasing new versions.
It has stabilized significantly, and supports an increasingly full set of
features. Scala 3 is just around the corner, and the community is poised to make
the transition smoothly and relatively quickly. Metals supports it already,
whereas of course Ensime does not and never will. In fact, Scala 2 has had
several import minor versions released since Ensime died. Now that it's 2021,
it's time to cut the baggage we are carrying around for Ensime.
2021-01-11 16:14:01 +00:00
where =0.9.8= can be replaced with the current version of [[https://scalameta.org/metals/docs/editors/emacs.html ][Metals ]]:
2020-03-12 22:14:11 +00:00
#+BEGIN_SRC bash
./coursier bootstrap \
--java-opt -Xss4m \
--java-opt -Xms100m \
--java-opt -Dmetals.client=emacs \
[scala] remove long-deprecated Ensime integration
According to its website, the Ensime project has been shut down since 2019. We
have been supporting both Ensime and Metals for [a year and a
half](https://github.com/syl20bnr/spacemacs/pull/12234#issuecomment-524916394).
Ensime's GitHub repositories, including its Emacs integration, are archived.
Meanwhile, Metals has been developed actively, regularly releasing new versions.
It has stabilized significantly, and supports an increasingly full set of
features. Scala 3 is just around the corner, and the community is poised to make
the transition smoothly and relatively quickly. Metals supports it already,
whereas of course Ensime does not and never will. In fact, Scala 2 has had
several import minor versions released since Ensime died. Now that it's 2021,
it's time to cut the baggage we are carrying around for Ensime.
2021-01-11 16:14:01 +00:00
org.scalameta:metals_2.12:0.9.8 \
2020-03-12 22:14:11 +00:00
-r bintray:scalacenter/releases \
-r sonatype:snapshots \
-o /usr/local/bin/metals-emacs -f
2019-04-26 10:34:11 +00:00
#+END_SRC
2021-03-20 21:02:09 +00:00
Notice that the layer by default overwrites Metals-scala tree view to nil.
2021-03-10 23:34:21 +00:00
This to avoid issues with buffers when rendering VSCode like view, issue described [[https://github.com/syl20bnr/spacemacs/pull/14470 ][Here ]].
2020-03-12 22:14:11 +00:00
You will then have the common LSP key bindings; see
[[https://github.com/syl20bnr/spacemacs/tree/develop/layers/%2Btools/lsp#key-bindings ][LSP#key-bindings ]] for more details.
2015-06-10 16:44:30 +00:00
* Scalastyle
2016-07-16 05:30:56 +00:00
[[http://www.scalastyle.org/ ][Scalastyle ]] provides style-checking and linting. The Emacs functionality is
2015-06-10 16:44:30 +00:00
provided by Flycheck.
2016-10-02 19:23:40 +00:00
To use scalastyle, it must be present as an executable in your =PATH= .
2019-10-13 05:27:17 +00:00
- macOS users: =brew install scalastyle=
2018-09-19 03:54:47 +00:00
- Linux, please see [[http://www.scalastyle.org/command-line.html ]]
2016-10-02 19:23:40 +00:00
To test if =scalastyle= executable is in your path, run =scalastyle= in a new
terminal, it should output something like:
2018-07-10 10:57:25 +00:00
2016-10-02 19:23:40 +00:00
#+BEGIN_SRC bash
2018-09-19 03:54:47 +00:00
$ scalastyle
scalastyle 0.8.0
Usage: scalastyle [options] <source directory >
...
2016-10-02 19:23:40 +00:00
#+END_SRC
Finally, enable the =syntax-checking= layer and set the =flycheck-scalastylerc=
variable to a valid location.
2018-07-10 10:57:25 +00:00
2016-07-25 05:11:17 +00:00
#+BEGIN_SRC emacs-lisp
2016-10-02 19:23:40 +00:00
(setq-default flycheck-scalastylerc "/usr/local/etc/scalastyle_config.xml")
2016-07-16 05:30:56 +00:00
#+END_SRC
2015-12-02 05:22:18 +00:00
2016-07-25 05:11:17 +00:00
See the [[http://www.flycheck.org/en/latest/languages.html?highlight=scala#syntax-checker-scala-scalastyle ][flycheck documentation ]] and [[http://www.scalastyle.org/configuration.html ][scalastyle configuration ]] for up-to-date
configuration instructions.
2016-04-13 03:31:38 +00:00
2016-05-06 11:35:10 +00:00
** Use Java doc-style
2016-08-21 07:55:25 +00:00
To enable =java-doc-style= , set the variable =scala-indent:use-javadoc-style= to
=t=
2016-04-12 07:50:02 +00:00
#+BEGIN_SRC emacs-lisp
(setq-default dotspacemacs-configuration-layers '(
2016-05-06 11:35:10 +00:00
(scala :variables scala-indent:use-javadoc-style t)))
2016-04-12 07:50:02 +00:00
#+END_SRC
2020-04-03 16:00:45 +00:00
* Enable Debug Adapter Protocol (DAP)
The metals backend enables integration with the DAP layer for debugging support.
2015-12-30 15:54:28 +00:00
* Automatically insert asterisk in multiline comments
2016-08-21 07:55:25 +00:00
To insert a leading asterisk in multiline comments automatically, set the
variable =scala-auto-insert-asterisk-in-comments= to =t= .
2015-12-30 15:54:28 +00:00
#+BEGIN_SRC emacs-lisp
(setq-default dotspacemacs-configuration-layers '(
(scala :variables scala-auto-insert-asterisk-in-comments t)))
#+END_SRC
2020-04-03 16:00:45 +00:00
* Enable GTags as a fallback navigation utility
[scala] remove long-deprecated Ensime integration
According to its website, the Ensime project has been shut down since 2019. We
have been supporting both Ensime and Metals for [a year and a
half](https://github.com/syl20bnr/spacemacs/pull/12234#issuecomment-524916394).
Ensime's GitHub repositories, including its Emacs integration, are archived.
Meanwhile, Metals has been developed actively, regularly releasing new versions.
It has stabilized significantly, and supports an increasingly full set of
features. Scala 3 is just around the corner, and the community is poised to make
the transition smoothly and relatively quickly. Metals supports it already,
whereas of course Ensime does not and never will. In fact, Scala 2 has had
several import minor versions released since Ensime died. Now that it's 2021,
it's time to cut the baggage we are carrying around for Ensime.
2021-01-11 16:14:01 +00:00
To enable gtags when in =scala-mode= set the variable =scala-enable-gtags= to =t= .
2020-04-03 16:00:45 +00:00
#+BEGIN_SRC emacs-lisp
(setq-default dotspacemacs-configuration-layers '(
(scala :variables scala-enable-gtags t)))
#+END_SRC
2015-06-10 16:44:30 +00:00
* Key bindings
2021-01-25 02:14:21 +00:00
Additional major mode key bindings are populated by LSP and DAP.
2019-04-18 09:32:18 +00:00
[scala] remove long-deprecated Ensime integration
According to its website, the Ensime project has been shut down since 2019. We
have been supporting both Ensime and Metals for [a year and a
half](https://github.com/syl20bnr/spacemacs/pull/12234#issuecomment-524916394).
Ensime's GitHub repositories, including its Emacs integration, are archived.
Meanwhile, Metals has been developed actively, regularly releasing new versions.
It has stabilized significantly, and supports an increasingly full set of
features. Scala 3 is just around the corner, and the community is poised to make
the transition smoothly and relatively quickly. Metals supports it already,
whereas of course Ensime does not and never will. In fact, Scala 2 has had
several import minor versions released since Ensime died. Now that it's 2021,
it's time to cut the baggage we are carrying around for Ensime.
2021-01-11 16:14:01 +00:00
** sbt
2019-04-18 09:32:18 +00:00
2021-01-25 02:14:21 +00:00
| Key binding | Description |
|-------------+---------------------|
| ~SPC m b .~ | sbt transient state |
| ~SPC m b b~ | sbt command |