bmewburn / vscode-intelephense

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

PHPDoc @var tag not working on promoted properties #2909

Open adam-openplay opened 2 weeks ago

adam-openplay commented 2 weeks ago

Describe the bug

The @var PHPDoc tag doesn't work (i.e. it doesn't appear to be parsed/understood by intelephense) on promoted properties.

To Reproduce

This doesn't work:

class Foo
{
    public function __construct(
        /** @var Bar[] */
        public array $things,
    ) {
    }
}

This does, but isn't as clear when the constructor has a bunch of arguments:

class Foo
{
    /**
     * @param Bar[] $things
     */
    public function __construct(
        public array $things,
    ) {
    }
}

This also works, but then you lose out on the succinctness of promoted properties:

class Foo
{
    /** @var Bar[] */
    public array $things;

    public function __construct(
        array $things,
    ) {
        $this->things = $things;
    }
}

Expected behavior

The @var tag on the promoted property in the first snippet above should work in the same way as the other two, telling intelephense the type of items in the array and opening up code completion and all that jazz.

Platform and version

Ubuntu 22.04.4 LTS Intelephense 1.10.4

AnrDaemon commented 1 week ago

No, it should not. Readthedocs?

jameslkingsley commented 1 week ago

Yes, it should.

adam-openplay commented 1 week ago

No, it should not. Readthedocs?

Which docs? There's nothing I can see in either the intelephense docs or the PHPDoc docs to suggest that this shouldn't be possible.

Also, PHPStorm supports it. And yes, I know this isn't PHPStorm, but that is a very popular IDE which means a lot of my colleagues use it so there are instances of this @var usage in our codebase that I can't take advantage of.

Maybe this should be filed under feature requests rather than bugs, but I don't think it's an unreasonable request 😄

AnrDaemon commented 1 week ago

On a second thought, it's a tricky case. @var annotates assignment, but in essence, the syntax you use IS THE assignment.

bmewburn commented 1 week ago

Will look at implementing this. There's a bit of effort involved though as the parser only provides syntax nodes for statement level phpdoc. For now the workaround, as noted, is to use @param on the ctor doc block.