-
Notifications
You must be signed in to change notification settings - Fork 35
Show documentation on hover #1025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Essentially this works now, except that the Anyway, here's a demo: hover.mp4Btw, why can't I hover on |
It seems like this needs rebasing on #930, @marvinborner. 👀 |
Yes, otherwise it's a bit hard to review :) Please ping me once it's rebased! |
7fe591d
to
a304fb2
Compare
@jiribenes @timsueberkrueb rebased! |
Another mysterious CI error in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Can you add a test case to LSPTests.scala
?
documentation.flatten | ||
.map('\n' +: _) | ||
.getOrElse("") | ||
.replace("\\n", "\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is .flatten.map f the same as .flatMap f?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems we have:
type Doc = Option[String] |
But then, why do we pass an Option[Doc]
(see other comment)?
Also, maybe instead of .map(...).getOrElse(...)
, a match
would be clearer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late response.
Why is this needed?
We only want to add a newline delimiter if the symbol actually has a doc comment, therefore we map on it and then .getOrElse. We need to unescape the newlines in order to show them in VS code as literal newlines (we build the string with escaped newlines in RecursiveDescent
)
Is
.flatten.map f
the same as.flatMap f
No, as it turns out. Also, I have changed the types from Option[Doc]
to Doc
, so this is not required anymore (see other comment)
Also, maybe instead of .map(...).getOrElse(...), a match would be clearer?
It's of course a stylistic choice, but I think it is clear enough as is.
case Some(p: Product) => | ||
p.productElementNames.zip(p.productIterator) | ||
.collectFirst { | ||
case ("doc", Some(s: String)) => Some(s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if there's a way to get rid of the magic string literal here somehow 🤔?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, I am not aware of it. I also do not really have a problem with this implementation, I think it is precisely the solution which our way of annotating Doc
s requires us to use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could the Tree
s that (potentially) have doc comments inherit from some Documented
trait like:
trait Documented {
def doc: Doc
}
// ...
enum Def extends Definition with Documented {...}
// ...
case class Constructor(..., doc: Doc, ...) extends ... with Documented
?
Then this could be a
case Some(d: Documented) => d.doc
Then we will probably get better compiler support.
Or am I misunderstanding something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with it if you add a test case so we notice if it breaks!
The test case did indeed reveal a problem in the parsing of doc comments, where the initial doc comment was always ignored because of empty/implicit Other than that, this should be mergeable now. |
Closes #1006, blocked by #930.