6

Is it possible to use Ensime and SBT to go to the definition of Scala library classes?

I know it is possible to see the definition of elements (using M-. or Control+Left-Click) and from there it's possible to see the doc page. Is there any way to tie this functionality into src as well?

UPDATE:

my project config (.ensime file):

(
  :root-dir "/Users/eugene/tmp/scrap"
  :sources (
    "/Users/eugene/tmp/scrap"
  )
  :reference-source-roots (
    "/usr/local/Cellar/scala/2.9.2/libexec/src"
  )
 :compile-deps (
    ""
  )
  :target "/Users/eugene/tmp/scrap"
)

/usr/local/Cellar/scala/2.9.2/libexec/src contains:

scala-compiler-src.jar scala-library-src.jar  scala-swing-src.jar
scala-dbc-src.jar      scala-partest-src.jar  scalap-src.jar

build.sbt:

name := "scrap"

version := "0.1-SNAPSHOT"

scalaVersion := "2.9.2"
Eugene Cheipesh
  • 373
  • 1
  • 9

1 Answers1

2

Download the sources of scala-library and then set :reference-source-roots in your project config file.

Eugene Burmako
  • 13,028
  • 1
  • 46
  • 59
  • Doesn't seem to have the desired effect, updating post with info – Eugene Cheipesh Nov 01 '12 at 06:59
  • Hmm... I remember this working in our Sublime plugin. Looks like we have to summon Aemon. – Eugene Burmako Nov 01 '12 at 09:24
  • 1
    Ah right! This thingie won't work as is. You need to extract the sources to a directory and then point `reference-source-roots` to that directory. – Eugene Burmako Nov 01 '12 at 09:27
  • Works, kind of. Having expanded the jar for scala library and looking at this code: val x = 1 :: 2 :: Nil val y = x.map (x => x*x) Inspecting on .map brings me to correct def in TraversableLike.scala While sinepcting on Nil (or List) just throws me to doc viewer for scala.collection.immutable$ – Eugene Cheipesh Nov 01 '12 at 16:58
  • This might be some kind of ensime bug. When fully qualifying Nil as "scala.collection.immutable.Nil" ensime is able to find the correct definition. It looks like it expects an "immutable" companion object above? Not sure why. – Eugene Cheipesh Nov 01 '12 at 17:18
  • Also when adding "import scala.collection.immutable._" to the file Nil is properly resolved to "scala.collection.immutable.Nil$" instead of "scala.collection.immutable$" – Eugene Cheipesh Nov 01 '12 at 17:23
  • Probably that's a bug in Ensime. Let's wait for Aemon to chime in. – Eugene Burmako Nov 01 '12 at 18:25
  • Has anyone any struck any solution for this? Manually extracting the source-jars of all my managed deps feels unfeasable. Hm, maybe script it... – Viktor Hedefalk Feb 26 '13 at 17:41