Over a million developers have joined DZone.

Setup Ensime with Sublime in OS X: Scala Development with Sublime

DZone 's Guide to

Setup Ensime with Sublime in OS X: Scala Development with Sublime

This post shows how to setup Ensime with Sublime Text, using Git, SBT, and HomeBrew.

· Java Zone ·
Free Resource

This post shows how to setup Ensime with Sublime Text. In particular, we use Sublime 3 to demonstrate this setup process. Therefore, to follow along, we have to make sure that we have Sublime 3 already installed.

Among others, we are going to use the following tools:

  • HomeBrew
  • Git
  • SBT
  • Setting up Ensime-Sublime

    To get started with the setup, we first clone Ensime-sublime, a Sublime plugin to interact with Ensime as follows.

    $ cd  ~/Library/Application\ Support/Sublime\ Text\ 3/Packages
    $ git clone https://github.com/ensime/ensime-sublime.git Ensime
    $ git checkout ST3

    Note that, since we are using Sublime 3, we have to checkout ST3 branch of the github repository. We refer to this directory as $ENSIME_SUBLIME:

    $ export ENSIME_SUBLIME="/Users/adilakhter/Library/Application Support/Sublime Text 3/Packages/Ensime" 

    An alternative to this approach is to clone it in any directory and afterwards, create a symbolic link as follows:

    $ ln -s ensime-sublime ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/Ensime

    Configuring ensime-sbt

    Next, we setup ensime-sbt, an SBT plugin. It can be configured at the project-level (by adding it in project\plugins.sbt) or at a global level, as outlined next.

    $ cd ~/.sbt/0.13/plugins
    $ echo "addSbtPlugin("org.ensime" % "ensime-sbt" % "0.1.7")" >> plugins.sbt

    Running Ensime Server

    To do that, we have to make sure coreutils is already installed. If not installed, we can use brew to install it:

    $ brew install coreutils

    To generate Ensime-related configuration for a SBT project, we invoke following command at that root of the project:

    $ sbt gen-ensime 

    It generates all the relevant configuration (see the generated .ensime), required to interact with the Ensime server from Sublime. Finally, We can start ensime-server as follows:

    $ $ENSIME_SUBLIME/serverStart.sh .ensime
    13:02:15.536 DEBUG None o.e.i.SearchService - committing index to disk...
    13:02:15.536 DEBUG None o.e.i.SearchService - ...done committing index
    13:02:15.539 DEBUG akka://ENSIME/user/project o.e.c.Project - indexed 0 and removed 0
    13:02:16.489 DEBUG akka://ENSIME/user/project/analyzer o.e.c.Analyzer - received handled message FullTypeCheckCompleteEvent in state loading
    13:02:16.490 DEBUG akka://ENSIME/user/project/analyzer o.e.c.Analyzer - Analyzer ready in 0.012 seconds.

    Configuring Sublime

    Last step of this setup is to configure Sublime editor for our project. To do so, first we have to modify the Ensime-related configuration that we can find by navigating at Sublime Text > Preferences > Package Settings > Ensime > Settings - User and update it as follows and restart Sublime:

    "connect_to_external_server": true,
    "external_server_port_file": "[project-root]/.ensime_cache/port"

    Note that, in the future version of Ensime-sublime plugins, external_server_port_file probably will not be required (see discussion at this pull-request). However, at the time of writing, it was indeed required.

    If we have followed so far, we are done with configuring Ensime with Sublime. Next, we start development with Sublime.

    Beginning Development with Sublime

    To start developing with Sublime, we open the root directory of the project for which we have started the server (see “Running Ensime Server” section) and invoke Ensime:Startup in Sublime’s Command Palette (i.e. cmd+shift+p).

    Afterward, we can also build the project with Ensime:Build command, which leads to running the relevant sbt command to compile the project. With respect to features, among others, ensime-sublime supports syntax completions (as shown next), go to definition and etc.

    syntax completion

    These features are also accessible from the context menu, as illustrated below.
    Image title

    That's it for today! If you have any remark or suggestion, please post. I look forward to your feedback.

    scala ,ide ,sublime ,tooling ,osx ,apple ,java

    Published at DZone with permission of

    Opinions expressed by DZone contributors are their own.

    {{ parent.title || parent.header.title}}

    {{ parent.tldr }}

    {{ parent.urlSource.name }}