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.

27 comments

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.

0

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

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

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

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

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

0

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

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.

 

 

0

@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

Please sign in to leave a comment.