phpdoc-parser icon indicating copy to clipboard operation
phpdoc-parser copied to clipboard

Support "one-line" comments (starting with //)

Open rhertogh opened this issue 1 year ago β€’ 7 comments

This PR adds support for comments inside type definitions, e.g.:

/** @return array { // Array with comments.
 *     // Comments can be placed on their own line. 
 *     foo: string, // An array key description.
 *     bar: array {, // Another array key description.
 *         'foo//bar': string, // Array key with "//" in it's name.
 *     },
 * }
 */

Fixes #184

rhertogh avatar Jul 15 '23 22:07 rhertogh

Hi, thank you, I have a few points that will makes this more complicated.

  1. The comment needs to be available for each type node in the node attributes.
  2. The comments need to be correctly preserved for the format-preserving printer, meaning it will get a bit more complicated. Fortunately it's heavily inspired by the printer from nikic/PHP-Parser so we have some starting point.

ondrejmirtes avatar Jul 16 '23 06:07 ondrejmirtes

@ondrejmirtes

  1. The comment needs to be available for each type node in the node attributes.
  2. The comments need to be correctly preserved for the format-preserving printer, meaning it will get a bit more complicated. Fortunately it's heavily inspired by the printer from nikic/PHP-Parser so we have some starting point.

Could you point me to the locations where this should be implemented, then I'll give it a shot.

rhertogh avatar Jul 16 '23 09:07 rhertogh

Comments need to be added as attributes similarly to how Attribute::START_LINE is added today. See calls to methods called enrichWithAttributes.

As for Printer, see tests in PrinterTest. Comments should be preserved correctly when printing the same PHPDoc again, and correct comment should be removed when for example removing a key from an array shape.

ondrejmirtes avatar Jul 17 '23 07:07 ondrejmirtes

@rhertogh do you have any plans to proceed with this PR? I think it's an important feature... πŸ™

shmax avatar Aug 28 '23 23:08 shmax

@ondrejmirtes

In the event that @rhertogh is MIA, any chance I can prevail upon you to implement this? If you're too busy I can take a crack at it, but I have to confess I couldn't make much sense of the printer tests...

shmax avatar Sep 01 '23 19:09 shmax

@shmax Haven't found the time to continue working on thisπŸ˜…. So if you want to take a swing at it please feel free to do so.

rhertogh avatar Sep 03 '23 10:09 rhertogh

Okay, will do. πŸ‘

shmax avatar Sep 03 '23 14:09 shmax