Make Ensime work with newer versions of SBT

Posted in Scala

If you try to use Ensime with newer versions of SBT, you’ll find that SBT grows to fill available memory and then crashes. This is because the latest released version of Ensime assumes the project format of an old version of SBT. To fix this, just add the following to your .emacs after you require Ensime:

(defun ensime-sbt-project-dir-p (path)

  "Does a build.sbt or a project/build.properties exists in the given path."

  (or (file-exists-p (concat path "/build.sbt"))

      (file-exists-p (concat path "/project/build.properties"))))

The problem occurs because Ensime looks for your project directory by recursively going to parent directories until it sees something that looks like an SBT project. Eventually, it ends up in root, and SBT crashes while trying to recursively enumerate all the files in the current directory. Redefining this function to also look for newer project formats fixes the issue.