I swear I looked this up before or reported it, but can't find it, so I'll write it up. This covers two separate problems; one is causing whitespace where there shouldn't be, and the other is ignoring whitespace where it shouldn't.

For the first, if you write a paragraph in a doc block, in order to have it formatted nicely in Intellisense, you cannot use newlines. In Markdown, a single newline does not create a new paragraph - you need two for that. This is meaningful because when you're editing the code, you have to choose between readability for the author (the person writing the docblock) or the user (the person viewing the results).

For the second, if you include a code fence with examples, the leading indentation is not kept. I can't identify any easy workarounds other than putting a zero-width space in front of everything.

Example code:

<?php

/**
 * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
 * incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
 * exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
 * 
 * Example:
 * ```php
 * <?php
 * test([
 *   'foo' => 'bar'
 * ])
 * ```
 */
function test($args) {

}

and what it looks like in VSCode:

what it should look like:

and here's what you have to do to make it look that way:

(note that it's difficult to read/edit the docblock in the editor here unless you soft-wrap everything, which is not really desirable globally)

not shown in the third screenshot is the ZWSP (U+200B) before the two spaces preceding 'foo'

13 days later

Thank you for reporting this!

Yes, there are two issues,

  • [x] we intentionally add newlines between separate lines, because some users have the opposite problem :) but we should behave as you suggested! - fixed Oct 22, 2024
  • [x] it's a bug, the leading whitespace is getting trimmed off - fixed Oct 23, 2024
    Write a Reply...