Skip to content

Printer: keep the "*" prefix on continuation lines of multi-line text - #318

Open
janedbal wants to merge 1 commit into
phpstan:2.3.xfrom
janedbal:printer-multiline-text-indent
Open

Printer: keep the "*" prefix on continuation lines of multi-line text#318
janedbal wants to merge 1 commit into
phpstan:2.3.xfrom
janedbal:printer-multiline-text-indent

Conversation

@janedbal

@janedbal janedbal commented Sep 7, 2026

Copy link
Copy Markdown

Fixes #317

PhpDocParser::parseText() and the description parsers join continuation lines with a bare \n and drop the * prefix. Printer::print() emitted that text verbatim, so a changed or inserted multi-line PhpDocTextNode or tag description printed continuation lines without the asterisk. printNodeFormatPreserving() falls back to print() when a string sub-node changes, so printFormatPreserving() had the same problem.

Change

  • print() re-inserts a line prefix at every newline inside a PhpDocTextNode and inside a printed PhpDocTagValueNode. The default prefix is "\n * ".
  • printFormatPreserving() sets the prefix from the original tokens: detected newline plus the before-asterisk indentation, followed by * . The lexer strips exactly one space after the asterisk (TOKEN_PHPDOC_EOL), so deeper indentation is still part of the text and is kept as is.
  • Blank lines inside a text node print as * without a trailing space, same as an empty PhpDocTextNode child.

Tests

  • dataPrintFormatPreserving: change a multi-line text node with a blank line inside and a multi-line @param description; same with 5-space indentation; insert a new multi-line text node.
  • dataPrintPhpDocNode: print() of a node with a multi-line text node, an empty text node and a multi-line description.

make check passes.

Claude

Co-Authored-By: Claude Code

PhpDocParser::parseText() and the description parsers join continuation
lines with a bare newline and drop the " * " prefix. Printer::print()
emitted that text verbatim, so a changed or inserted multi-line
PhpDocTextNode or tag description printed continuation lines without
the asterisk. printNodeFormatPreserving() falls back to print() when a
string sub-node changes, so printFormatPreserving() had the same
problem.

print() now re-inserts the line prefix at every newline inside a text
node or tag value. The default prefix is "\n * ". printFormatPreserving()
uses the newline and before-asterisk indentation detected from the
original tokens. The lexer strips exactly one space after the asterisk,
so the prefix ends with a single space and any deeper indentation stays
in the text. Blank lines print as " *" without a trailing space.

Fixes phpstan#317

Co-Authored-By: Claude Code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Printer drops the * prefix on continuation lines of a changed multi-line PhpDocTextNode

1 participant