bmewburn / vscode-intelephense

PHP intellisense for Visual Studio Code
https://intelephense.com
Other
1.62k stars 94 forks source link

PHPDoc parameter alignment #1541

Open levacic opened 3 years ago

levacic commented 3 years ago

Feature description or problem with existing feature

By default, an example generated docblock is formatted something like this:

/**
 * @param Foo $fooooo This is a foo param.
 * @param FooBarBaz $fbb This is a foo bar baz param.
 * @param FooBar $fooooobar This is a foo bar param.
 */

Describe the solution you'd like

I would like automatically generated @param annotations to have the types, variable names, and descriptions aligned, based on the longest of each group. So the example above should be formatted like this:

/**
 * @param Foo       $fooooo    This is a foo param.
 * @param FooBarBaz $fbb       This is a foo bar baz param.
 * @param FooBar    $fooooobar This is a foo bar param.
 */

Additional context

This is enforced by the Symfony.Commenting.FunctionComment sniff, which is part of my team's coding standards.

KapitanOczywisty commented 3 years ago

For exactly that reason, I'm still using php-fmt (slightly modified for php7+).

levacic commented 3 years ago

Thanks for the tip, I'm actually already doing the same thing, but using PHP Sniffer as a formatter, which is convenient because it relies on the sniffs in my PHPCS configuration (a lot of which are also implemented so as to be able to fix the issues they detect) - thus making everything consistent.

However, it would be more convenient if the docblock was already aligned correctly as soon as it is generated, which seems like a pretty easy feature to implement (basically pad all items in each group with spaces on the right-hand side up to the length of the longest item in that group).

P.S. This would be particularly helpful if #1101 was implemented, and worked correctly with this feature (although the combo of these features does seem like slightly more work).

KapitanOczywisty commented 3 years ago

There are some considerations like very long lines and line breaks, also probably someone might be not happy with such feature (messing with version control). As option for sure, anyway I wouldn't hope for that in the near future, since author is inactive lately.

1101 You can already format selection, so this would only had to trigger formatting on phpdoc block.