Bug 9472 – Include comments in ddoc'd unittest blocks

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-02-07T15:28:00Z
Last change time
2013-02-12T17:36:53Z
Assigned to
nobody
Creator
hsteoh

Comments

Comment #0 by hsteoh — 2013-02-07T15:28:47Z
Code: --- /// A magic function that can do anything void dotDotDotMagic() { doAnything(); } /// Example unittest { // Call the very powerful function that can do anything! dotDotDotMagic(); } --- The comment inside the unittest should be included in the generated DDoc for dotDotDotMagic(). Alternatively, if we want to be able to put comments inside the unittest block that doesn't get seen by the user, we can require the inner comments to be doc comments as well (i.e., with /// instead of just //).
Comment #1 by andrej.mitrovich — 2013-02-07T16:26:38Z
I think the issue is that the lexer simply skips over regular non-ddoc comments. I also don't think that statements can have ddoc comments, but only declarations can. I'm going to need help from Kenji on this one.
Comment #2 by hsteoh — 2013-02-07T16:31:01Z
I'm OK with requiring that comments to be included in the doc must be ddoc comments, if that makes it easier to implement.
Comment #3 by issues.dlang — 2013-02-07T21:44:09Z
> I'm OK with requiring that comments to be included in the doc must be ddoc > comments, if that makes it easier to implement. If we _have_ to do that, then we have to do that, but that's not particularly user-friendly. And you _definitely_ wouldn't want them to show up as ddoc comments (rather than regular comments) in the example because of the confusion that it would cause. I really think that we should try to get it working with regular comments.
Comment #4 by hsteoh — 2013-02-07T22:15:45Z
Supporting regular comments may require non-trivial modifications to the lexer, though. Lexers by default just skip over comments entirely. But then again, if we're going to need to retain indentation (because right now that doesn't work either), then we're going to have to modify the lexer anyway, so we might as well throw in comments as well. But I doubt it's going to be pretty, in terms of changes to the lexer code. And there may be lexer performance considerations as well, depending on what needs to be done.
Comment #5 by hsteoh — 2013-02-07T22:18:18Z
Makes me wonder if this feature should be done the *other* way round: that is, unittest injection from ddoc code snippets. It may be easier going in that direction than the current direction of code -> ddocs, because then you don't have to fight with the lexer to _not_ eat spaces and ignore comments, as it's designed to do.
Comment #6 by andrej.mitrovich — 2013-02-08T04:41:23Z
Actually I came up with an idea this morning, I should be able to implement it today. This will also resolve the other issue about indentation.
Comment #7 by andrej.mitrovich — 2013-02-08T06:42:54Z
Caused by same issue as in 9475. *** This issue has been marked as a duplicate of issue 9475 ***
Comment #8 by andrej.mitrovich — 2013-02-12T17:36:53Z
(In reply to comment #4) > Supporting regular comments may require non-trivial modifications to the lexer, > though. Lexers by default just skip over comments entirely. It was actually trivial to fix Issue9472 and Issue9475, see https://github.com/D-Programming-Language/dmd/pull/1641 All that was required was to fetch the end pointer where the unittest body closes, and then we can extract the string. Still waiting for the pull to be reviewed and pulled (I'm hoping it makes it into 2.062 or we'll have a half-baked documented unittest feature in release).