Haehnchen / idea-php-symfony2-plugin

IntelliJ IDEA / PhpStorm Symfony Plugin
https://plugins.jetbrains.com/plugin/7219
MIT License
910 stars 137 forks source link

[Doctrine] Autocomplete fails for Document classes #789

Open vkost opened 8 years ago

vkost commented 8 years ago

Hi, thank you for this brilliant plugin - but can you please help me to get it to work the way it used to :) I'm working with doctrine_mongodb bundle, and I keep my documents in AppBundle/Document folder. Autocomplete used to work great before last PHPstorm update, now it does not recognise the class from getRepository() command. For example, $patient = $mongo->getRepository('AppBundle:Patient')->find($id); used to make PHPstorm aware that $patient variable holds an instance of Patient class, so autocomplete worked flawlessly. Now it fails. It also fails to see the Repository class for the same document.

At first I thought it's about cache so I issued Invalidate Caches command, but to no avail. I'm using PhpStorm 2016.2.1 Build #PS-162.1889.1, Plugin version is 0.12.125

I thought I should try the previous plugin version but I don't know how to obtain it.

I'm not sure if I'm making myself clear enough, please let me know if you need any more info on this. Thanks again for the effort you make to keep this plugin working.

Cheers, Vic

vkost commented 8 years ago

Hi, I've just noticed that there's an official name for the failing functionality in plugin description

Thanks for looking into this, let me know if I can help with anything. Vic

fyrye commented 8 years ago

Where $em = $this->get('doctrine.orm.entity_manager');

The resulting inspection (ctrl+hover over $em) shows as: doctrine entity manager or object

Using /** @var \Doctrine\ORM\EntityManager $em */ resolves the issue for me, but should not be needed. or /** @var \Doctrine\ODM\MongoDB\DocumentManager $mongo */ should work for the Mongo ODM (please verify).

Attempted invalidate caches and restart of PHPStorm and cleaning the Symfony Framework plugin index with no change.

vkost commented 8 years ago

I can confirm that adding /* @var \Doctrine\ODM\MongoDB\DocumentManager $mongo / resolves the problem. What's also interesting is that it seems that it's enough to set it in one class method and entire class (controller) starts to behave fine. It's true I always use $mongo as a var name for DocumentManager but it's always local so I'd expect it to be resolved on a method level, this is why I find this strange.

Thank you all Vic

vkost commented 8 years ago

I've just made few more tests, I think additional info can't hurt In this line $mongo = $this->get('doctrine_mongodb')->getManager(); If I CMD+Hover over $mongo, it resolves to Doctrine\Common\Persistence\ObjectManager, and the rest of the expected methods fail. If I add /* @var \Doctrine\ODM\MongoDB\DocumentManager $mongo / and thus tell the system to treat $mongo as DocumentManager, everything works as expected. Not sure what is causing this, I think that some declarations in Doctrine or MongoDB-ODM may be causing the odd behaviour. I don't have any custom declarations of these services, I use the default with Gedmo mappings - that's all.

Cheers

fyrye commented 7 years ago

Related to #619