vscode-intelephense icon indicating copy to clipboard operation
vscode-intelephense copied to clipboard

Support move file/folder refactoring

Open bmewburn opened this issue 5 years ago • 12 comments

Move a file or folder and have namespaces corrected if the original path and namespace was aligned.

bmewburn avatar Dec 12 '19 20:12 bmewburn

This would me much appreciated. It’s the only thing that Storm offers (that I use) and vscode doesn’t.

I now find myself opening storm to do some class/namespace refactors, after which I continue work as usual in code.

I wouldn’t mind if this would be a premium feature (like rename class).

georgeboot avatar May 02 '20 18:05 georgeboot

Would be really neat addition to premium features. Any plans about this one?

artoaaltonen avatar Jan 26 '21 12:01 artoaaltonen

@bmewburn The website states that Intelephense does support this as a premium feature:

Rename. Easily rename symbols with automatic file/folder renaming too.

However, I don't have this option available, and this issue seems to imply that the website is incorrect. Could you please clarify this? Thanks!

levacic avatar Feb 04 '21 07:02 levacic

@levacic renaming a class or namespace should also rename the file/folder if the old name matched the filename/folder. This ticket is to support the other way around, renaming a file/folder renames the namespace and/or class.

bmewburn avatar Feb 04 '21 08:02 bmewburn

@bmewburn That sounds great, however - I don't really see a way how to trigger this behavior, and I've tried a bunch of stuff. Most of the other premium features do work correctly for me (e.g. find all implementations, go to type definition/declaration, PHPDoc generation etc.). I've also tried to find if this is documented anywhere, but had no luck with that either.

Thanks!

Edit: I've just realized that the other features weren't working for me either, and the license key got unset for some reason - I've set it back and got access to the "Rename symbol" option which wasn't there before. My mistake!

It does work correctly when renaming a class name for example, however when I try to rename a namespace, it doesn't get moved to a new location. Is Intelephense aware of autoloading configuration and stuff like that? I'm working with Laravel, where the majority of the code will usually be under the App namespace, in the app folder in the project root - which isn't an exact match - e.g. the class App\Foo\Bar will be in the app/Foo/Bar.php file.

levacic avatar Feb 04 '21 18:02 levacic

@levacic if it's not behaving as expected please open a new ticket with a code example that reproduces the problem and I will take a look.

bmewburn avatar Feb 04 '21 20:02 bmewburn

@bmewburn maybe for this we can use the https://code.visualstudio.com/api/references/vscode-api#workspace events like onWillRenameFiles this way u can get the old & new path of the folder & contents then make a project search & rename for the namespaces.

ctf0 avatar Mar 15 '22 08:03 ctf0

i worked on this today and its added to https://github.com/ctf0/vscode-php-refactor, give it a try and reply back for any issues.

ctf0 avatar Dec 08 '22 15:12 ctf0

Any update on this? I'd love to have PHP move refactoring in VSCode. Like someone mentioned above, I also have to switch to PHPStorm to do move refactoring.

VictorVRE avatar Nov 22 '23 02:11 VictorVRE

Little bump on this feature that is quite important. Big projects are a pain to refactor. Refactoring a namespace symbol already works, so handling all children files of a directory should be rather trivial. cc @bmewburn

innocenzi avatar Dec 21 '23 00:12 innocenzi

Another bump as this is the ONLY thing keeping me in phpstorm at the moment.

PatrickVeltrop avatar Jun 21 '24 08:06 PatrickVeltrop

Related: https://github.com/bmewburn/vscode-intelephense/issues/2480

innocenzi avatar Jun 21 '24 18:06 innocenzi