Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

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

Closed
rhertogh wants to merge 2 commits into phpstan:1.22.x from rhertogh:support_one_line_comments

Conversation

Copy link

@rhertogh rhertogh commented Jul 15, 2023

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

primehalo and EduApps-CDG reacted with thumbs up emoji
Copy link
Member

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.

Copy link
Author

@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.

Copy link
Member

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.

Copy link
Contributor

shmax commented Aug 28, 2023

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

Copy link
Contributor

shmax commented Sep 1, 2023

@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...

Copy link
Author

rhertogh commented Sep 3, 2023

@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.

Copy link
Contributor

shmax commented Sep 3, 2023

Okay, will do. 👍

Copy link
Member

Superseded by #264

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Multiline array shapes with 'comments'

AltStyle によって変換されたページ (->オリジナル) /