Developing Scala in Atom With Ensime
Check out how to get going with Scala in Atom using Ensime, from installing Ensime to project prep and import.
Join the DZone community and get the full member experience.Join For Free
when i began java software development way back in the time of java 1.3 i remember using jdeveloper for a time, before switching to the early versions of eclipse. i stayed with eclipse for a very long time (about 8 years) before switching to intellij about 4 years ago. i've always been a big fan of intellij, not just for programming java, but i also kept using it when i started with scala a couple of years ago. last months, though, i started noticing that i actually only use a small amount of all the intellij functionality and was slowly getting a bit annoyed with the way intellij slowed down to a crawl for certain scala projects. combined with the fact that intellij tripped over some shapeless, spray, scalaz stuff, made me start looking for an alternative leightweight scala editor.
since i already am using atom for taking notes (nvatom in combination with a synced dropbox folder works great!), and i tried ensime a couple of months ago, i thought i'd gave that combination another try. in this article, you can read the steps i've taken, the plugins i've installed to get to a fairly good working ensime/atom combination.
getting and installing ensime
i've waited with this article until scala 2.11.8 came out since it solves a number of issues with imports and implicits when using ensime. so for the best experience of using ensime, upgrade your projects to scala 2.11.8. so with that out of the way lets get started with installing ensime.
to install ensime, just follow the instructions on the site ( http://ensime.github.io/editors/atom/installation/ ), and you'll get an atom which you can use to run ensime.
preparing and importing a project
once installed, make sure you point to your local sbt installation, and you're more or less ready to start using ensime. the last thing we need to do is install an sbt plugin which is needed to generate some information ensime needs. follow the installation instructions from here ( http://ensime.github.io/build_tools/sbt/ ) and once done open a console and navigate to the project you want to import. if you haven't already done so, update the scala version to 2.11.8. in that directory call `sbt gen-ensime`.
➜ graphql-sangria sbt gen-ensime [info] set current project to graphql-sangria (in build file:/users/jos/dev/git/graphql-sangria/) [info] ensime update. please vote for https://github.com/sbt/sbt/issues/2266 [info] ensime updateclassifiers. please vote for https://github.com/sbt/sbt/issues/1930 [warn] multiple dependencies with the same organization/name but different versions. to avoid conflict, pick one version: [info] resolving org.scala-lang#scalap;2.11.7 ... [info] ensime processing graphql-sangria (graphql-sangria) ➜ graphql-sangria ls -lat total 32 -rw-r--r-- 1 jos staff 9327 mar 19 09:54 .ensime drwxr-xr-x 57 jos staff 1938 feb 22 09:28 .. drwxr-xr-x 6 jos staff 204 jan 20 07:15 .ensime_cache drwxr-xr-x 9 jos staff 306 jan 19 20:22 . drwxr-xr-x 12 jos staff 408 jan 5 14:17 .idea -rw-r--r-- 1 jos staff 410 jan 2 14:45 build.sbt drwxr-xr-x 4 jos staff 136 jan 2 13:24 src drwxr-xr-x 6 jos staff 204 jan 2 13:24 target drwxr-xr-x 6 jos staff 204 jan 2 13:23 project ➜ graphql-sangria
note that i use the following sbt wrapper ( https://github.com/paulp/sbt-extras ), which drastically reduces the output of sbt only to the necessary, and provides a lot of additional features that make working with sbt a little easier. so when you run this, you might see some more information. the import thing to notice here is that we've got a `.ensime` and a `.ensime_cache` directory now, which contains ensime specific files.
in atom open up a new window, add that folder and you can use ctrl-cmd-p `ensime: start` to start ensime.
the first time will take some time while dependencies are being downloaded, but eventually, ensime will finish downloading and start the server. at this point, you can use ensime to check your scala code (either while your typing or whenever you save). at the bottom, it will show you the issues with the current file or with the complete project. for instance in the sample project, i've got a number of unused imports:
it also provides import suggestions:
and shows specific errors.
so for a lot of projects, you can already use atom for your scala development. there are, however, also a couple of issues with ensime.
what doesn't work that great yet
i'm an avid intellij user, and one of the features i noticed i used a lot when i started using atom, was the auto-import function of intellij. ensime/atom provides something similar, but it is by far not as useful as the intellij one. with atom/ensime you can import a suggestion, but (at the moment) it just selects one, instead of allowing you to chose. more often than not the wrong one gets imported.
even though the import feature is an annoying one, it's just a matter of time before it is added, since ensime does provide multiple hints, it's just that the atom/ensime plugin doesn't support it yet.
there are a number of other features, where intellij provides more helpful information, but nothing that really stands in the way of working, you'll just be browsing the source/documentation a little more, which is easy to do (`ensime: go to doc`):
or just `ctrl-click` to go to the declaration.
some stuff that was blocking
while ensime/atom is quickly getting better, at the moment, for some projects, there could be some really blocking issues. if you use a project that uses macros or some compiler plugins, you might get false errors. i was going to show a project where false errors where reported, but with the latest version the errors apparently don't occur anymore in my spray/shapeless project. so i took one of my other projects (which uses a lot of scalaz stuff), where intellij has issues with as a test to see how ensime/atom handles that. while it takes some time for ensime to compile everything and get to a stable state, it handles everything correctly!
regardless of this recent surprising success, there is still a big change, you'll run into false errors. this is an issue where the ensime team is aware of (see issue: https://github.com/ensime/ensime-server/issues/673 ), and which apparently is very difficult to solve. people however are working on this by providing a plugin which returns the correct signatures for generated code, to make the editors happy. more information on this can be found here: https://github.com/fommil/imaginary-friend
additional plugins which make working with ensime easier
with the ensime plugin you can probably already get a lot of work done using the standard functionality in atom. however, i've installed the two suggested plugins from the ensime/atom site and they really make working with multiple projects and navigating through your code a lot easier. so if you intend to start using atom and ensime more. these two are very useful to install:
- project manager: allows you to manage multiple projects
- last cursor position: navigate back to where you where
lastly, i suggest you install the term3 package, with this package you can open a terminal window directly in your atom, which is nice when you've got some quick sbt commands to execute, or do some git actions (which is pretty much the way i also work in intellij)
development of the ensime server goes quickly, as i've just noticed myself. a month ago there were a whole lot of issues with spray/shapeless which seems to have been solved now (whether this is through ensime improvements or scala 2.11.8 i don't know). the atom plugin has some rough edges, but is already really useful. one of the biggest advantages is how lightweight atom is in comparison with intellij. so i'll start working with atom more and more, but will probably come back to intellij for certain type of projects.
Published at DZone with permission of Jos Dirksen. See the original article here.
Opinions expressed by DZone contributors are their own.