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

Removes falsely used usages! Even while option is not active! #175

Open
andimg93 opened this issue Feb 10, 2021 · 7 comments
Open

Removes falsely used usages! Even while option is not active! #175

andimg93 opened this issue Feb 10, 2021 · 7 comments
Assignees
Labels
high priority status: todo Will get to this as soon as I have free time type: bug

Comments

@andimg93
Copy link

andimg93 commented Feb 10, 2021

The plugin is causing much trouble right now, in some of my projects.
I have not activated the feature "Remove unused use-s on save" even though it removes some usages while saving!
image

Trouble code e.g. (heavily abridged):

<?php

use Application\Model\Mandator;
use Application\Model\Supplier;
use Monitoring\Monitor\Supplier\AbstractConnection;
use Wrapper\Service\Cycle;

return [
    'displayName'        => 'Whatever',
    'displayForced'      => true,
    'configuredWebsites' => [
        Mandator::WHATEVER => [
            AbstractConnection::createIdentifier(Supplier::WHATEVER) => [
                'type' => Cycle::TYPE_MONITOR,
            ],
        ]
    ]
];

the usage use Application\Model\Supplier; is always deleted, while saving.

This issue is critical as the plugin is not usable anymore, right now.

@klesun
Copy link
Owner

klesun commented Feb 10, 2021

Hm, thanks for the report, that would be pretty nasty, I'll look later today

@klesun klesun self-assigned this Feb 10, 2021
@klesun klesun added high priority type: bug status: todo Will get to this as soon as I have free time labels Feb 10, 2021
@klesun
Copy link
Owner

klesun commented Feb 10, 2021

Did it start recently? Did you ever tick "Remove unused use-s on save" or did plugin start behave this way on it's own? And what version of phpstorm are you using?

I tried your minimal example with 2021.01.05.001 version of plugin and 2020.3.2 (Ultimate Edition), but I could not reproduce the issue: ticking the setting makes unused imports to disappear on save, unticking makes them to stay. It is possible that plugin config got messed on your machine and shows the setting as unticked, even though it is actually ticked. if that is the case, I wonder if ticking it, then pressing "apply", then unticking and pressing "apply" again would fix the settings state...

Of course, perfectly would be to nail down the exact reason why you get this problems, I'll need your feedback on my questions to do that.

@klesun
Copy link
Owner

klesun commented Feb 10, 2021

Just in case, you did mention you have this problem in multiple projects, is this flag unchecked in each of them? That could be a source of confusion, as it's a project wide setting, not IDE wide...

Also, does it, per chance, reproduce only when several projects are open at once? There is probably a possibility IDEA keeps one project window focused, and takes setting from this focused project, even though the file in which save handler runs belongs to a different project.

Also, do these "falsely used usages" get removed when there are some syntax errors in the file? It's not as bad as behaviour not matching the setting, but that could be fixed as well.

@klesun klesun added status: need reporter's feedback and removed status: todo Will get to this as soon as I have free time labels Feb 10, 2021
@klesun
Copy link
Owner

klesun commented Feb 10, 2021

Also, to be 100% sure, did you try disabling the plugin and restarting the IDEA, does issue not reproduce then?

@andimg93
Copy link
Author

Since it says in the upper right corner that it is only a project related configuration, I would have thought that it is not applied across all projects.

In any case, I have actually activated the functionality in one project. There were no problems with it yet. Have that now actually only noticed after I have removed a use that has then caused trouble.

I use version 2020.3.2 of PHPStorm:
image

The problem must exist based on several open projects. I closed all IDE instances and then opened only one problem project. Activating the plugin again now, there are no problems. Even if you tick the function to remove the unnecessary usages, the problem does not occur again 🧐.

@andimg93
Copy link
Author

Seems to be rather an unfortunate coincidence of several IDE instances/open projects and thus more an exceptional case.
The priority is therefore not so high, even if the user should pay attention to it. Since it is a potential source of trouble/errors.

@klesun
Copy link
Owner

klesun commented Feb 10, 2021

Hm, thank you very much, will try to play around to reproduce it. Based on your feedback and the code, my main theory is that plugin considers setting on for all open projects if at least one of them has it on.

PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);

If my theory is right, the problem is that I assume that IDEA would not allow me to access a document from context of a project that it does not belong to, but probably my assumption was wrong and it would after all.

@klesun klesun added status: todo Will get to this as soon as I have free time and removed status: need reporter's feedback labels Feb 10, 2021
@klesun klesun mentioned this issue May 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
high priority status: todo Will get to this as soon as I have free time type: bug
Projects
None yet
Development

No branches or pull requests

2 participants