Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PhpStorm 10: Unused symfony2 annotations imports #44

Closed
scaytrase opened this issue Nov 2, 2015 · 44 comments
Closed

PhpStorm 10: Unused symfony2 annotations imports #44

scaytrase opened this issue Nov 2, 2015 · 44 comments

Comments

@scaytrase
Copy link

Annotation imports became mark unused right after aftercompletion succeedes.

image

PhpStorm 10.0
Build #PS-143.381, built on October 31, 2015
JRE: 1.8.0_51-b16 x86
JVM: Java HotSpot(TM) Server VM by Oracle Corporation

Plugin version: 2.6.1

@scaytrase
Copy link
Author

PhpStorm 9.0.2 with the same plugin version render imports OK

image

PhpStorm 9.0.2
Build #PS-141.2462, built on August 18, 2015
JRE: 1.8.0_51-b16 x86
JVM: Java HotSpot(TM) Server VM by Oracle Corporation

@lsv
Copy link

lsv commented Nov 3, 2015

Can confirm, just changed to PhpStorm 10 now.

If you remove the import line, then the annotation actually says it cant find the class

screenshot from 2015-11-03 01 41 11

@Haehnchen
Copy link
Owner

I did a clean installation, its working fine.

@lsv that correct class is not imported so not known ;)
@scaytrase try a cache invalidation and rebuild it for new PhpStorm10 environment: File > Invalidate Cache

@scaytrase
Copy link
Author

Invalidate Cache and Restart, than reindexing did nothing. Any other ideas?

Reinstall plugin and reindex didn't help

@scaytrase
Copy link
Author

Hell, I've even dropped .WebIde100 folder and reconfigured plugins. Same story. I've left only two custom plugins enabled - Symfony2 and PHP Annotations, rebuilt cache and restarted. Nothing changed.

@lsv
Copy link

lsv commented Nov 4, 2015

@Haehnchen ofcourse, it was just to show that the @route actually looked for a class.

In symfony fullstack there are two different classes that gives you the route annotation.

Symfony\Component\Routing\Annotation\Route and Sensio\Bundle\FrameworkExtraBundle\Configuration\Route if you choose the frameworkextra route annotation then it says the class is never used.

But if you use the component annotation then it works as before.

But it is not just the route annotation, the Method annotation which only is in the frameworkextra does not work at all.

(By "work" I mean it shows up as "class import never used", just in the first screenshot from OP)

@scaytrase
Copy link
Author

Yeah @lsv , Interesting note - component annotation marked as used correctly. At the same time FrameworkBundle one - not

image

@lsv
Copy link

lsv commented Nov 4, 2015

The only difference I can see on the two classes are

The component route has the Target annotation, and the framework does not.

But again, both worked perfect in PHPStorm 9 (and still does) but not in 10 (so what have changed I dont know)

@linaori
Copy link

linaori commented Nov 11, 2015

It seems like the following annotations are not detected when used:

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

The following work fine:

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Routing\Annotation\Route;

This is quite an issue for me as it would mean I remove used use statements.

@lsv
Copy link

lsv commented Nov 11, 2015

+1

@hoshsadiq
Copy link

Any update on this?

@Haehnchen
Copy link
Owner

yes. targets are missing in all classes https://github.com/sensiolabs/SensioFrameworkExtraBundle/tree/master/Configuration. but that should not break, will check that changes between PhpStorm 9 > 10 psi-struct/lexer

@desarrolla2
Copy link

+1

@Haehnchen
Copy link
Owner

can someone provide some project background. symfony version, ... ?. that ever i am trying all works as expected. :)

  • try drop cache folder?
  • multiple class names for eg Route?

@scaytrase
Copy link
Author

@Haehnchen currently I cannot reproduce this issue neither with PS10.0.3 nor with PS11 EAP (plugins are latest). Maybe something go fixed silently last two months.

If some other confirm - then, issue should be gone.

@linaori
Copy link

linaori commented Jan 31, 2016

I think it has indeed been fixed in a patch in-between. I can verify tomorrow but I cannot remember running into this issue the past weeks.

@linaori
Copy link

linaori commented Feb 1, 2016

Update, I'm running 10.0.3 (jan 8) with annotations 2.6.2, and it's working here.

@fracasula
Copy link

Same here with Ubuntu and PHPStorm 10.0.3. With me what's not working are other classes though so I don't think it's this plugin the culprit. PHPStorm says the ParamFetcher class that I'm using with type hinting is never used, plus a trait I wrote myself.

import_never_used

@hoshsadiq
Copy link

@fracasula I think your issue is different. This plugin is to do with annotations, yours is a PhpStorm built in feature. You should raise this as an issue on YouTrack on Intellij's website.

@fracasula
Copy link

@hoshsadiq That's why I wrote "so I don't think it's this plugin the culprit" in my previous comment. I was trying to point out that maybe this whole thing could probably be just about PHPStorm and not the plugin at all. Just saying though, so if you guys are sure about this then it makes sense you keep posting here.

@hackzilla
Copy link

For future reference, this has been fixed by installing the PHP Annotations plugin.

https://youtrack.jetbrains.com/issue/WI-30512

@Haehnchen
Copy link
Owner

so closed

@plfort
Copy link

plfort commented Jun 3, 2016

I still have this issue with PHP Annotation 3.0.1 and PHPStorm 2016.1.2 (145.1616).
Cleaning index or reinstalling the plugin did not help.
Am i missing something ?

@denisvmedia
Copy link

@Haehnchen
I have this problem too, but in PhpStorm 10.0.4 and the plugin version 2.6.2. Tried clearing cache - no results. Tried re-installing it - no results. Shoudn't we re-open this issue?

@Haehnchen
Copy link
Owner

not supporting version < 2016.x because of different api levels. versions +2016.1 need also some updates because of #55

@vpArth
Copy link

vpArth commented Dec 8, 2016

PhpStorm 2016.3.1
Build #PS-163.9735.1, built on December 6, 2016

Same issue:

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

Both are never used

@vpArth
Copy link

vpArth commented Dec 8, 2016

Workaround is aliasing:

use Sensio\Bundle\FrameworkExtraBundle\Configuration as C;

/**
 * @C\Route(...)
 * @C\Method()
 */

@shyinyong
Copy link

You can install PHP Annotations plugin!

image

@lashae
Copy link

lashae commented Dec 16, 2016

It is already installed on the latest build of Phpstorm.

screen shot 2016-12-16 at 09 12 52

screen shot 2016-12-16 at 09 13 29

screen shot 2016-12-16 at 09 16 15

@linaori
Copy link

linaori commented Dec 16, 2016

It's fixed again in the latest EAP of phpstorm

@weph
Copy link

weph commented Dec 20, 2016

Will this fix also be released for 2016.3.1?

@dramentol
Copy link

dramentol commented Dec 21, 2016

I have the same problem.

PhpStorm 2016.3.1
Build #PS-163.9735.1, built on December 6, 2016

PHP Annotations 4.2

Edit:
as @iltar pointed, it's fixed in the latest EAP

@igops
Copy link

igops commented Dec 21, 2016

The last build of PhpStorm has a fix for the issue!

PhpStorm 2016.3.2
Build #PS-163.10504.2, built on December 20, 2016

PHP Annotations 4.2

Voilà:

phpstorm_use_annotation_fixed

@lifo101
Copy link

lifo101 commented Jan 3, 2017

I just upgraded to 2016.3.2 and now these annotations are broken. I've tried invalidating/restarting/re-indexing/reinstalling the PHP annotations plugins, etc. And nothing seems to work. :(

IntelliJ IDEA 2016.3.2
Build #IU-163.10154.41, built on December 21, 2016
Licensed to ...
You have perpetual fallback license for this version
Subscription is active until November 29, 2017
JRE: 1.8.0_112-release-408-b6 x86
JVM: OpenJDK Server VM by JetBrains s.r.o

image

@igops
Copy link

igops commented Jan 3, 2017

@lifo101 which version of PHP Annotations?

@lifo101
Copy link

lifo101 commented Jan 3, 2017 via email

@dfreudenberger
Copy link

same here, running php annotations v4.2 with intellij 2016.3.2

@mrfreitas
Copy link

I can confirm that Intellij 2016.3.2 with php annotations v4.2 it's having this problem

@lifo101
Copy link

lifo101 commented Jan 6, 2017

Simple workaround (the aliasing suggestion someone made didn't work for me) is to simply reference the class of the unused imports. This way when you optimize imports Ctrl-Alt-L it won't remove those imports)

    protected function dummy()
    {
        // dummy code to fix bug in 'use' statements not being seen 
        // (IntelliJ v2016.3.2 + PHP Annotations v4.2)
        Route::class;
        Security::class;
    }

image

@dewos
Copy link

dewos commented Jan 10, 2017

@lifo101 you can use @see in annotation, it is more clean

/**
* @Route("/request")
*
* @see Route
*/
class FooController

@PhilETaylor
Copy link

PhilETaylor commented Feb 20, 2018

This is happening again :-(

PHP Annotation Plugin 5.2.1
PhpStorm 2018.1 EAP
Build #PS-181.3741.23, built on February 14, 2018
JRE: 1.8.0_152-release-1136-b11 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.4

EDIT:
Disregard, I see a new build is now available 20 hours ago #108

@sawmurai
Copy link

sawmurai commented Apr 3, 2018

Happens in 2018.1

@scaytrase
Copy link
Author

scaytrase commented Apr 3, 2018

in 2018.1 it happens because of old version plugin incompatibility. you should re-install (remove, restart, install, restart) plugins in order get them back to life

@ddelrio1986
Copy link

Recently upgraded PHPStorm and had to do exactly as @scaytrase described above to get warnings about "use Doctrine\ORM\Mapping as ORM;" imports not being used even though I was using it within docblock annotations. I just uninstalled the PHP Annotations plugin, restarted PHPStorm, installed the PHP Annotations plugin, then restarted PHPStorm again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests