File move / refactoring not working

I'm working on PHPStorm 10.0.3 Mac and for (at least) the last couple of days, file refactoring hasn't been working.

I'm working with classes in a packages/ folder, which are found quite happily in the rest of the app, but when I move or rename the files, with the checkbox on to Search for references, it moves the file, but then does not:

  • Rename the file
  • Update the class name
  • Update the package
  • Update any of the references

I've tried marking a few folders as Sources Root but this hasn't helped either.

Help would be appreciated, thanks.

2

Hi there,

You should apply "Refactor | Rename/Move" on actual class and not file (yes -- these actions are context dependant and do different things depending on context/where they were invoked).

ATM there are no support for renaming/updating PHP code (class name/namespace) when you move php files -- only other way around.

Related tickets (different areas):

0

Hi Andriy,

Thanks for the reply.

 

I don't understand - this used to work, I'm sure!?

 And in which case, why does it bother to ask to search for references?

0

I've just tried it on the actual class, by pressing F6 in the editor, and I get the same result - a move, but no refactoring.

0

I'm not sure -- as far as I remember it was working like this all the time. If I need to rename class or move it to another namespace I'm using those actions on class and it works for me (possibly my code is way too simple). Since I do not use require/include statements directly there is no issues with references. Not sure about use statements thought (have not done such refactoring recently) and definitely will not work for references in strings.

BTW -- that "packages/" folder -- is it part of the project or is it marked as External Library or stuff like that?

0

What was left untouched exactly? Reference in require/include? "Use" statements?

Can you make some very simple project that reproduces the issue (to clear up any misunderstanding and see exactly what is going on; to find the right ticket if there is one)?

If you are 100% sure that it was working for you for 100% in the past (and my comment above is about different case/usage) then maybe you should try "File | Invalidate Caches..." and restart IDE if you have not tried it yet.

1

Yes, use statements.

I might switch to Windows as well and see if my other installation works.

I'll do that when I get a convenient time to switch.

Thanks for the input BTW

0

OK, so I got a chance to try this on Windows, and no luck there either.

I am 99.5% sure that I've moved files in the past, and PHPStorm has done a brilliant job in updating the use statements, as well as class names etc.

I went to move some more files earlier, and it doesn't work. This is strange, as Find Usages does work, so logically, this should be able to work too.

Can anyone shed any light on this?

0

Screenshots please (screencast is even better).

When I'm using Move or Rename on class (yes, there is a difference where action is invoked) PhpStorm correctly updates all "use" statements.

Moving files in Project View does not update "use" statements -- it has been like that since beginning (at least this is how I remember it all the time).

0

OK, cool. I'll try and get myself to a place where I'm happy to do a decent-sized refactor, and I'll try and make a recording :)

0

Also, Andriy, when you say "on the class" do you mean right-clicking on the class declaration in the editor panel?

0

Pretty much yes. You have to have caret placed on the class name.

https://youtrack.jetbrains.com/issue/WI-31021#comment=27-1339557 -- this is about renaming part of the namespace/folder name but describes the process on how it works right now (and how many comments it took to explain what "invoke on namespace" means).

As far as I understand you are renaming file and want everything else updated in sync. This is not supported right now. Your possible tickets:

0
Avatar
Permanently deleted user

Same problem here with Move class/package using IntelliJ v 15.0.5 (build #IU-143.2287).

Using IntelliJ v 14, I can drag a class from one package to another and all references to the moved class (via imports) in other classes are updated automatically. This has worked forever.

However, using the latest update, the dialog that comes-up does NOT offer the choice of "Move package" or "Move directory" (here I want Move package). Rather, it allows me only to move the directory - and it proceeds to move the directory and, as it is not moving a package, the references to the moved class are not updated.

Again, I tried this on a few of my projects and they all show the same behavior AND it works on IntelliJ v 14 using the exact same project file. In fact, I did the refactor (Move class/package) in IntelliJ 14 and it worked as expected. I tried "Invalidate Caches/restart" a few times as well as deleting the iws and ids files - does not help.

What does "This is not supported right now" mean? It has been in IntelliJ since the beginning of time (at least the last many major releases). I use this feature all the time. Move one class, 20 files get checked-out and modified to match the change.

Please hear that this is NOT a finger problem.

Pierre - IntelliJ user Since 2007 (or so)

0

Brilliant! I thought I was going mad :P

0
Avatar
Permanently deleted user

Yep this is shocking, this has always worked and now it's not. It's such an important time-saving feature. I'm using IntelliJ 14 and it's not even working there now.

0
Avatar
Permanently deleted user

I finally got it to work. I had tried dragging the python file (i'm using IntelliJ Ultimate with Python plug-in installed) and asking it to search for references, and also opening the file and trying to rename the class by clicking refactor -> rename on the class name inside the file. Neither was working. Then i tried refactor -> move on the class name, and i ended up with the same class file open but emptied. I then manually saved the file, and suddenly a bunch of files with updated imports were saved to disk.

Now, if i try dragging files, it works fine. So there's some sort of bug where it's actually doing the refactor but not automatically saving the changes to disk. I use 'git status' on the command to check what has been updated.

0
Avatar
Permanently deleted user

Yep, i have to do manually do cmd+s to save to disk after each refactor.

0

I had this issue on refactoring files and folders. I just trying moving packages but I get a error. 

-2
Avatar
Permanently deleted user

I am facing the same problems. Moving/renaming classes do not work properly. It does not apply changes. Hence search display found places correctly. 

0

Sergey, could you please capture a screencast showing your exact actions and what you think is going wrong?

0

I am trying to move large sass and scss folders with subdirectories in the project window

hoping that all my referenced paths will refactor and be resolved

jetbrains says cant do that

refactoring is broken with complex folder references

code bases are increasingly large

and this feature is not holding water

0

this is an angular5 app

statements such as these in other components scss files refuse to refactor

 

@import '../../../../sass/colors/index';

and I am forced to go into the source code and update them manually

is there a solution to this to avoid all this manual work ?

0

webstorm only resolves paths to components on MOVE when refactoring

it does nothing with internal sass or scss source code

refactoring is the main feature we are PAYING for to do all the heavy lifting for us...

whats the deal webstorm?

0

and to successfully attempt a move for component

you FIRST gotta shutdown client and server and reboot the IDE

then do the move

and resolve any path references not resolved

0

can't recreate - to me, scss imports are correctly updated when moving files/folders.

Please can you share a sample project that can be used to recreate the issue?

0

Does any of you have Prettier file watcher? For me that was the cause - https://intellij-support.jetbrains.com/hc/en-us/requests/1363376?page=1

0
Avatar
Permanently deleted user

Hi I can confirm I also have issues on Webstorm 2018.1.5

I have a folder like such as /src/entities, which contains around 35 folders each with around 5 files. When I use the refactor move function and move the 'entities' folder to another location many of the references (e.g. import { Foo } from ".....") in the rest of the project are broken (building the project does not work) after the move.

To work around this issue, I can move each of the individual 35 folders one at a time to the new location, and this seems to work.

So it would appear as though the refactor move function has an issue with folder depth.

I am happy to provide more info if needed.

 

 

1

@Chris Gibb

Please create a ticket at WebStorm Issue Tracker and provide all info you have there.

If you can create a sample project (or share your own project privately; or know some open source that can show the same behaviour) that would reproduce the issue -- that would be perfect.

0

I having the same problem.. any solution yet?

0

Please see the comment above: we need a test project + steps to repeat to see what's going on

0

Here is a test project:
http://food.vegtalk.org/test_refactoring.zip 

When I refactor -> move the file config.php to folder /include the include path in main.php does not change.

Here is my working phpstorm info:
PhpStorm 2016.1.2
Build #PS-145.1616, built on May 24, 2016
JRE: 1.8.0_76-release-b198 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
OS: Ubuntu 18.04

I also installed the latest phpstorm with the same results:
PhpStorm 2020.1.3
Build #PS-201.8538.41, built on July 8, 2020
Licensed to PhpStorm Evaluator
Expiration date: August 10, 2020
Runtime version: 11.0.7+10-b765.64 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Linux 4.15.0-109-generic
GC: ParNew, ConcurrentMarkSweep
Memory: 1979M
Cores: 12
Registry: run.processes.with.pty=TRUE
Non-Bundled Plugins: Shifter
Current Desktop: ubuntu:GNOME

Here is the manual page that says it should work:
https://www.jetbrains.com/help/phpstorm/move-refactorings.html

1

请先登录再写评论。