This is a little “proof of concept” (POC) or MVP candidate to see if having commands like these to view Scaladoc and Scala source code in the REPL would be good:
Command | Description |
---|---|
doc("List") |
show the List class Scaladoc |
doc("List", "withFilter") |
grep for withFilter in the methods of the List Scaladoc |
src("Vector") |
show the source code for the Vector class |
browser("LazyList") |
open the LazyList class Scaladoc in the default browser |
editor("Vector") |
open the Vector class in your default ".txt" editor |
Note that the open
command currently only works on MacOS systems, because it requires a little bit of AppleScript code to open the default browser on a Mac system.
This little project was inspired by a Gitter discussion that started here and ended here.
Most of this code is written in a “worst practices” style because I just want to see if a tool like this is worth developing, so I’ve taken a lot of shortcuts, and often don’t handle possible errors.
The following commands should work on Mac and Unix/Linux systems.
Once you create a JAR file with sbt assembly
, follow these steps:
- Create a /Users/al/tmp directory (change this to match a directory on your system)
- Copy the JAR file to that directory (the JAR is currently named ScalaReplDocCommands-assembly-0.2.jar)
- Create a file named repl-commands in that directory
- Put this content in that file:
import com.alvinalexander.repl_docs.ReplDocCommands._
- Create an alias to start the REPL:
alias repl="scala -cp ScalaReplDocCommands-assembly-0.2.jar -i _/Users/al/tmp/repl-commands_"
- Then start the REPL with that alias:
$ repl
Inside the REPL, use the help
, doc
, src
, open
, and editor
commands shown above.
As mentioned, I created this as a POC/MVP candidate to see if this is a good idea. The easiest way for me to do this was to get the docs off the internet, from URLs like this one:
Everything after that is screen-scraping with Jsoup. A much better (i.e., real) implementation would probably read from the source code JAR files. But, this was much easier for me to do quickly.
Some useful Jsoup URLs: