How do I access scala documentation from the repl?

早过忘川 提交于 2019-11-29 22:13:31

Scaladocs are generated as HTML, so you don't want them appearing in the REPL window. You might want to load docs in a browser from the REPL, however. You can do that by creating your own method like so (this one takes an instance; you could have it take an instance of Class[A] instead, if you prefer):

def viewdoc[A](a: A) {
  val name = a.asInstanceOf[AnyRef].getClass.getName
  val url = "http://www.scala-lang.org/api/current/index.html#"+name
  val pb = new ProcessBuilder("firefox",url)
  val p = pb.start
  p.waitFor
}

If you want to get extra-clever, you could parse the name to point the web browser at Javadocs for java classes and Scaladocs for Scala classes and wherever you have your documentation for your classes. You also probably want to use a local source, file:///my/path/to/docs/index.html# instead of the API from the web. But I used this so you can try out

scala> viewdoc(Some(1))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!