bmewburn / vscode-intelephense

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

Closure doesn't use description from @param PHPDoc #685

Open KapitanOczywisty opened 5 years ago

KapitanOczywisty commented 5 years ago

Extension does not use description from @param with closures.

Call typehinting:

Closure doesn't have description

image image

Hover label

Doesn't have type (fixed 1.3) nor description

image image

Closure var hover

Here we have complete set of phpdoc

image

Inside Closure

Inside closure type is correctly recognized but not description

image image

Version: vsc 1.38.1 / ext 1.2.3

Code:

/**
 * Function
 * @param  int    $a       Param a
 * @param  string $b       Param b
 * @param  bool   $c       Param c
 * @return string Return
 */
function func($a, $b, $c) {
    $a;
    return '';
};

func();

/**
 * Closure
 * @param  int    $a       Param a
 * @param  string $b       Param b
 * @param  bool   $c       Param c
 * @return string Return
 */
$func = function ($a, $b, $c) {
    $a;
    return '';
};

$func();
bmewburn commented 5 years ago

This is somewhat related to #439 . Do any other IDE's or static analysis libs support function style doc block on closures?

I'd rather see something like this:

/** @var \Closure<int, string, bool, string> $func description */
$func = function ($a, $b, $c) {
    $a;
    return '';
};
KapitanOczywisty commented 5 years ago

I have no IDE to test. Still extension recognized int in one place, but not description.

Suggested syntax is great but for telling how callback should look like, and there is no place to tell what each param means.

This is useful case for proposed syntax:

/**
 * @param callable(int, string):string $callback Yup, I'm still for this syntax
 */
function iWillCallYouBack($callback) { /*...*/ }

iWillCallYouBack(function($myInt, $myString){// Extension can warn here: function should return string
$myInt; // on hover we have int type
})

\Closure<int, string, bool, string> syntax is ok-ish, but does not deal with other callbacks and return type isn't obvious.

Edit:

Of course, this doesn't exclude use with @var. Every addition would be great, because now there is nothing to deal with closures and callbacks.

Edit 2:

Psalm should support docblock on closures :link:Supported docblock annotations (screenshot formatted for readability) image