Open Aivean opened 6 years ago
Should now "just" be a matter of implementing this method well.
Although last time I checked, it seemed to be no easy task to get the javadoc of symbols this way... Maybe scalameta and / or LSP stuff could help here, cc @olafurpg.
@alexarchambault we have the pieces to implement this but there's no ready solution for it yet. I'll be working on it in the coming weeks and can publish a module with an API to go from a symbol to its docstring, which works for both Scala and Java. Do you have access to the Scala compiler symbol and do you have access to the sources.jar of the classpath?
We're using Ammonite, so we have an instance of an ammonite.interp.Interpreter
, which itself has a CompilerLifecycleManager
, which can give us the current compiler instance.
Note that we receive requests as plain text, with an index at which the user would like more details.
Ammonite adds source JARs along standard JARs in the classpath (for now).
One particularity of Ammonite is that some sources and their classes don't originate from JARs, but only live in memory. (These correspond to the code the user entered. Although there may be similar stuff in sbt projects or other that LSP should handle...)
The way I imagine the API will look like is roughly like this
trait Docstrings {
def addSourceJar(jar: Path): Unit
def addVirtualFile(filename: String, code: String): Unit
def docstring(symbol: String): Option[String]
}
I would ideally like the implementation of addSourceJar
to not rely on persistent caching but I'm not sure yet if that will be too slow.
In addition, you will need a way to produce the correct symbol string format according to the spec here
We already have an implementation in Scalameta that does this for scala-compiler nsc.Global.Symbol
.
In the meantime, you can prototype this functionality by showing the signature of the compiler symbol with symbol.info.toString
.
How is tooltip string rendered? We might be able to provide html markup with hyperlinks but I haven't looked into it in depth.
Per the Jupyter spec, tooltips can be text, HTML (even with images and JS), markdown, ...
https://github.com/almond-sh/almond/pull/235 should provide symbol.info.toString
.
Python kernel shows docstring tooltip on shift-tab, which is very useful for finding information on function and parameters:
It is possible to support something like this for scala kernel?
If somebody can point me in the right direction, I can try to implement it myself.
Thanks.