bmewburn / vscode-intelephense

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

Does Intelephense support multiple @return types? #1800

Closed BernhardBaumrock closed 3 years ago

BernhardBaumrock commented 3 years ago

In advance: Thx for your help and the awesome extension!!

I'm using the ProcessWire CMS in my everyday work. ProcessWire has a base class Wire that almost every other class extends. The Wire base class has a wire() method that can return several objects:

Here is the definition: https://github.com/processwire/processwire/blob/d8945198f4a6a60dab23bd0462e8a6285369dcb9/wire/core/Wire.php#L1710

@return ProcessWire|Wire|Session|Page|Pages|Modules|User|Users|Roles|Permissions|Templates|Fields|Fieldtypes|Sanitizer|Config|Notices|WireDatabasePDO|WireHooks|WireDateTime|WireFileTools|WireMailTools|WireInput|string|mixed

The Problem

$this->wire()->... does not suggest anything useful:

image

This is how it should look like:

image

Calling $this->wire (using the wire property instead of the wire method) works because of a different phpdoc: https://github.com/processwire/processwire/blob/d8945198f4a6a60dab23bd0462e8a6285369dcb9/wire/core/Wire.php#L61

But I'd really like my Intelephense to understand wire() calls, because that's the way it is used everywhere in the core of ProcessWire.

PHPStorm does understand what's going on because of this meta file: https://github.com/processwire/processwire/blob/master/wire/core/.phpstorm.meta.php

Any ideas what would be the best direction to tackle this problem? I wonder if Intelephense should return all possible methods that are part of all possible return types of the method? Or maybe just return the first one listed as default?

Thx again!

bmewburn commented 3 years ago

If you rewrite the meta file in the newer phpstorm format it will be understood.

tianyiw2013 commented 3 years ago

Duplicate of #1711

bmewburn commented 3 years ago

Closing this one as it can be solved with phpstorm meta. Looking at changing the minimal type reduction that's probably happening here in #1711