-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add support for raw docstrings in ASTs #1151
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
does not seem to compile. |
212c756
to
5d4199a
Compare
Thanks @DarkDimius, it should compile - even so, this PR does not touch the typer. EDIT: but it does touch the scanner. I can see that Martin has a PR open for the successive opening of comments as well. So I'll lay low :) EDIT2: there was an off by one error inherited from previous code that showed when saving the comments, fixed it! 😅 |
7d7bfa1
to
23529fd
Compare
Look in https://github.com/lampepfl/dotty/tree/master/test/test, you might need to extend |
@smarter thanks! I'll have a look later today. |
Traits without a body caused the structure of only keeping one docstring to fail (since the parser would gobble them up before finding out that the trait had no body). So the docstrings are now saved in a queue. Maybe that's what the EDIT: fixed 👍 |
4ed74a0
to
8028ec4
Compare
Good afternoon, I now feel that this PR is nearing a state where it should be evaluated on a first review basis. When first opened, it did not meet the quality criteria and for this I apologize (@DarkDimius). The tests now show what this implementation can handle, please see: https://github.com/lampepfl/dotty/pull/1151/files#diff-a8ce7031a634f23d40bb1c04c8aeaf38R57 These are the tests performed, and should help you with an overview:
The current heuristic for associating comments is simply selecting the closest docstring (preceding the entity) from a Entering and leaving a block scope will, push respectively pop the docstring comments var. Speaking with Heather, I've been told to ping @odersky (since he is responsible for this part of the compiler). I hope I'm not stepping on any more toes. Sincerely, |
It's not it wasn't meeting quality criteria. It's that it was failing a specific test so I've tried to tell you what file to try to compile locally to reproduce the issue. I'll have a look at the PR, though getting feedback from @odersky would be great. |
@@ -317,6 +317,10 @@ object Trees { | |||
private[ast] def rawMods: Modifiers[T] = | |||
if (myMods == null) genericEmptyModifiers else myMods | |||
|
|||
private[this] var myComment: Option[String] = None |
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.
hmmm, adding new fields in trees
is likely to increase memory footprint.
As most trees do not have comments,@felixmulder, would you consider putting comments into attachments of the tree?
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.
Of course - didn't know about attachments. Will look into it 👍
@DarkDimius the two latest commits contain your suggested changes 👍 thanks for taking a look! |
e563b43
to
adf0f2e
Compare
Otherwise LGTM. Good job! |
adf0f2e
to
c0ae291
Compare
Rebased and fixupped the latest commit to include the change "back" to Let me know if this needs to be squished in order to be merged. Thanks! |
c0ae291
to
7853ce6
Compare
@felixmulder is this still a WIP branch, or is it ready for review? |
@DarkDimius - ready for review! |
cdeb00a
to
f4a543d
Compare
This commit fixes errors that would've occurred in this situation: ``` /** Docstring 1 */ <- this one would've been chosen /** Docstring 2 */ /** Docstring 3 */ class Class ``` And this situation: ``` /** Docstring 1 */ trait Trait /** Docstring 2 */ <- this one would've been chosen ```
f4a543d
to
f43f520
Compare
This commit also adds a printer for use by dottydoc.
LGTM, Thanks! |
Hello, as some of you might know (@heathermiller, @odersky) - I'm coming to EPFL in a couple of weeks to help out on dottydoc 🎉
As such, I wanted to get a head start on the implementation. I've perused the code and started an implementation for docstring parsing.
In this PR the scanner has been modified to save the docstrings according to the following heuristic:
If the comment is a docstring, save it in aclosestDocString: Option[Comment]
var, replacing the old valueclosestDocString: mutable.Queue[Comment]
valkeepComments
is set to true also save it torevComments
(not sure if this is necessary, but didn't want to ruin someone else's possibly ongoing implementation)MemberDef
tree if applicableI'm not sure if this is the optimal implementation, but it seems to eliminate the need for positional checking and instead follows "if the docstring is the closest docstring to an entity, it is the entity's docstring." The
closestDocString
var would in this approach, however, have to be emptied at the end of parsing bodies (not done yet).There are two questions I'm looking to have answered:
Sidenote: in a separate branch I've also started the implementation of a dottydoc tool which uses only the
FrontEnd
phase to get an AST. As such, finding the correct solution to adding comments to the AST will be a requirement for moving forward with said branch.