Using Ensime + SBT to browse scala library
Asked Answered
N

1

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"
Noonberg answered 1/11, 2012 at 4:27 Comment(0)
L
2

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

Lyndel answered 1/11, 2012 at 6:29 Comment(8)
Doesn't seem to have the desired effect, updating post with infoNoonberg
Hmm... I remember this working in our Sublime plugin. Looks like we have to summon Aemon.Lyndel
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.Lyndel
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$Noonberg
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.Noonberg
Also when adding "import scala.collection.immutable._" to the file Nil is properly resolved to "scala.collection.immutable.Nil$" instead of "scala.collection.immutable$"Noonberg
Probably that's a bug in Ensime. Let's wait for Aemon to chime in.Lyndel
Has anyone any struck any solution for this? Manually extracting the source-jars of all my managed deps feels unfeasable. Hm, maybe script it...Lahey

© 2022 - 2024 — McMap. All rights reserved.