Rearrange code not working
Rearrange code is not working on PHPStorm. Before creating a sample class, wanted to know if the message highlighted in the image above could be the reason for the error.
Did not click on Disable because was not fully aware of the consequences and also did not know where to Enable the override back. Where are the 'Code Arrangement' related EditorConfig settings present?
PHPStorm Info:
PhpStorm 2021.3.2
Build #PS-213.6777.58, built on January 31, 2022
Licensed to Nikhil Ranka
Runtime version: 11.0.13+7-b1751.25 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 2018M
Cores: 8
Registry:
run.processes.with.pty=TRUE
editor.distraction.free.mode=true
ide.balloon.shadow.size=0
Non-Bundled Plugins:
net.seesharpsoft.intellij.plugins.csv (2.18.2)
dev.meanmail.plugin.nginx-intellij-plugin (2021.3-2021.3)
com.intellij.ideolog (203.0.27.0)
com.intellij.properties (213.6461.46)
com.github.copilot (1.1.14.882)
com.cral.JSONKeyFinder (2.0.6)
String Manipulation (9.4.0)
mobi.hsz.idea.gitignore (4.3.0)
nl.deschepers.laraveltinker (2.3.3)
ru.adelf.idea.dotenv (2022.1)
aws.toolkit (1.40-213)
Please sign in to leave a comment.
Hi there,
Settings (Preferences on macOS) | Editor | Code Style | Enable EditorConfig support
There are no such settings. Such a message will be shown even if there is no .editorconfig file in your project.
Although, if you can export your whole current Code Style into .editorconfig file. In such a case they will be read from there. Such exported settings will start with ij_ prefix: https://www.jetbrains.com/help/phpstorm/2021.3/configuring-code-style.html#editorconfig
1) That screenshot: are those your own made rules or default ones? AFAIK default ones are different that what I see on your screenshot. I suggest you try with defaults as well.
2) When you do Reformat Code -- is the corresponding option actually enabled?
Try "Code | Reformat File..." (Ctrl+Alt+Shift+L here on Windows) -- settings from there will be remembered and used for the usual "Code | Reformat Code" action (Ctrl+Alt+L on Windows)
There is also dedicated "Code | Rearrange Code" action
3) Maybe your code is already properly arranged? What do you have and what do you expect to have?
Here's a video of the Reformatting exercise in action after disabling EditorConfig override. Upload id: 2022_04_05_FN8KhbnuHAyD8HzT (file: CodeRearrange.mp4)
Notice how the protected function is moved above the public function. There is no specific rule added for abstract methods - so the expectation, probably flawed, is that it should remain at the bottom
Attempted to Rerrange the code both directly and via Reformat File dialog with Rearrange option checked. Same results.
Did not find an option to apply the default rules back.
Does PHPStorm provide a way using which the exact settings that will be overridden by the current EditorConfig, if it exists, can be looked at?
What is your IDE version BTW (just in case)?
No.
Me too (using 2021.3.3). But there was a way in older versions (I've used it like 2.5 years ago, maybe even longer time ago...)
Can you please export your Code Style as a XML file and share it (the whole file)?
All customisation to the arrangement rules should be stored in your CodeStyle config file (e.g. I've enabled the "Sort by name" option and it got saved there after exiting the IDE) under the <arrangement> node.
These are the defaults that I see:
If you select an entry for "method", you will see this:
If you click on the "gear" icon, you will be able to edit (or add/delete) own aliases: ("by modifiers" and "by visibility"):
Looking at your rules and the method that gets moved .. I believe it's not about abstract modifier but about getter/setter detection. Try disabling the very first checkbox and try again: any difference?
P.S. The correct capitalisation is "PhpStorm"
That's absolutely correct. Spot on Andriy Bazanov 🎯
PhpStorm 2021.3.2
Build #PS-213.6777.58, built on January 31, 2022
After adding additional rules for abstract managed to ensure that abstract methods are seen at the last.
A way to suggest that the Keep Dependent methods together setting does not affect the abstract methods' position and keeps them at the bottom would be great. Aware of any way to do this?
Noted 😂. Thanks for correcting 👍
Cannot advise on this. JetBrains Support member should be able to help here.
As for me the way how it works right now seems to be OK. The logic behind it's name clearly suggests (to me at very least) that it should have a priority over ordering methods by name or modifier (which means: it first groups items by that Grouping rule and only then, inside the group, it orders items by your Matching rules).
Makes sense Andriy Bazanov. Grouping first and ordering next. However, having a way to ensure the abstract method declarations appear at the last.
A flag to skip declarations when under the Keep Dependent methods together setting should help.
Will wait for JB support to respond.
There are no options for that, sorry. You can submit this as a new feature to review to our tracker at https://youtrack.jetbrains.com/newIssue