You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[feature request] Extract class to a new file #30310
Unfortunately, no. I think there's a lot of value to this and similar refactorings that aid in code re-organization, but this work hasn't yet been prioritized high enough to be scheduled.
Reacted by Michele Cantelli, Stargator, Halil ibrahim Kuley, Idris Adetunmbi, Frank Mühlschlegel, Petr Nymsa, mrRedSun and Ryan Park
This has 86 likes now... in case you are using that as a voting system. (PS: As of today... this is the 10th highest liked issues)
@bwilkerson code re-organization is a programmer productivity task. I would very much love to see things that will make me more productive. Hence I disagree on your lack of value stance. Imagine the combined effort spent in manual refactoring!
Reacted by Kristen McWilliam, Luiz Meier, Michele Cantelli, Rune Bjørsnøs, slimlime, Thomas Burkhart, Youngjae Ji, Fedorenko Dmitry, Dan Bright, 李云鹏 and 3 more
Reacted by CicherMK, Stargator, slimlime, André Kremser, Fedorenko Dmitry, AdrianKujawskiDOR, Tormod Liseth, roadroot, Ivan Rybalko, Ryan Park and 2 more
Moving to an existing file is supported.. however I just tested it and see that when I select an existing file VS Code gives this message:
This message is misleading, and we actually do not replace the file, we merge into it. It seems like it's because of the VS Code API we use to select a file (showSaveDialog). I'm not sure if it's always done and I missed it, or it's new.
I've opened microsoft/vscode#203326 in VS Code to see if there could be a way to suppress this (or have an API for selecting files that does not do this).
@Autom8r-82 oof, that one is even worse (it more explicitly states that something bad will happen that will not). Thanks for the heads up - I'll see if I can find any other options for this.
I missed that there was an existing flag to enable it
A flag to enable what? My understanding is that (for VS Code) this refactor is available on the latest SDKs and will add any necessary imports. No flags should be required (since v3.72.0 of Dart-Code was released and the stable SDK available at the time). If that's not what you're seeing, please let me know / file an issue.
(there are some issues with the dialog showing an overwrite prompt noted above which are not resolved yet though)
Here you said that this was an experimental feature
FYI, I'm making some slight changes to the opt-in flag for experimental refactors. The existing flag ("dart.experimentalNewRefactors") was for entirely enabling the new refactoring system. This was fine for initial development but doesn't allow us to have both experimental + stable refactors using this system in future.
In an upcoming release, that flag will be replaced by "dart.experimentalRefactors" (the word "New" has been removed) and it will now control only specific refactors that are marked as experimental.
For the time being, the "Move to File" refactor will continue to be considered experimental. You're welcome to try it out and provide feedback to help find any remaining issues, but be aware that in the current stable and current Dart 3 pre-release SDKs it's incomplete and has several known issues, such as:
* file headers may be inserted after the moved class
* moved classes may be inserted above import statements
* moving sealed classes does not automatically move their direct subclasses
* moving sealed classes/subclasses that are spread across `part` files is allowed and results in invalid code (for now, moving sealed types with direct subclasses in other `part`s will not be supported)
If you find any issues not listed above, please file new issues (and feel free to cc me). If you want to update your settings in advance so the experimental refactor doesn't disappear when you get an SDK with this change, you can include both flags in your VS Code settings:
"dart.experimentalNewRefactors": true,// current flag"dart.experimentalRefactors": true,// future flag
Though be aware that these flags may also cause other incomplete refactors to show up in future, so you may wish to disable them once this refactor is no longer considered experimental.
I have not seen any indications (or I missed it completely) on any comments after that explaining it was available.
I'm sorry, I've not seen that release post of the extension. Found out about this site not long ago. But please enlighten me on why is this issue still open then. I came here and figured it was still under development because it was opened.
Edit
It is only because of those issues with the dialogues?
@FMorschel sorry for the confusion, you're right that I didn't post in this issue when this refactor was marked as not-experimental (which I did in a3399e3), only in the Dart-Code issue/release notes. I certainly should've noted it here.
Currently this refactor is only available in VS Code and not in IntelliJ/Android Studio. Making it available to IntelliJ/AS will require work in their Dart plugin, but might also require some additional work here to allow them to call the new refactoring system (possibly through LSP).
I just landed on this issue and I think there should also be the feature available to not just extract class to ao new file but also extract any member of the class to another class and update the usages of that member accordingly with the object of the target class.
... extract any member of the class to another class and update the usages of that member accordingly with the object of the target class.
This deserves an issue of its own. Would you mind opening one? And perhaps expand, in the new issue, on what you're looking for. For example, are you thinking of something that would move members up or down in the class hierarchy, or are you thinking more generally about moving to an arbitrary class? Would it be limited to existing classes, or are you wanting it to create a new class? What are some examples of what you mean by "update the usages"? What should it do about references to other members that are no longer visible? How should references to the moved member be updated?
Activity
scullabyte commentedon Apr 19, 2020
Any update on this? Possibly a way to do this with another application that will update all references? Thanks!
cnsumner commentedon Apr 20, 2020
This would be extremely useful in VSCode. I have to do this operation manually 10s of times while mocking out an app UI.
nilsreichardt commentedon May 30, 2020
Any updates?
bwilkerson commentedon Jun 1, 2020
Unfortunately, no. I think there's a lot of value to this and similar refactorings that aid in code re-organization, but this work hasn't yet been prioritized high enough to be scheduled.
magnussp commentedon Oct 21, 2020
Would love to see this feature added. Makes life so much easier.
ajaygautam commentedon Nov 24, 2020
This has 86 likes now... in case you are using that as a voting system. (PS: As of today... this is the 10th highest liked issues)
@bwilkerson code re-organization is a programmer productivity task. I would very much love to see things that will make me more productive. Hence I disagree on your lack of value stance. Imagine the combined effort spent in manual refactoring!
keehoo commentedon Jan 30, 2021
almost 4 years... geez..
dkbast commentedon Feb 15, 2021
Looks like Jetbrains has this in Rider for .net ... I keep ending up on this site every few months when looking for this feature so I thought I'd share it here:
https://www.jetbrains.com/help/rider/Refactorings__Move__Type_to_Another_File.html
dfaveur commentedon Feb 25, 2021
Yes please. It is very cumbersome currently to isolate widget per file
krema commentedon Mar 13, 2021
I just discovered a plugin that we can use in the meantime at least for flutter.
https://github.com/marius-h/flutter_enhancement_suite
43 remaining items
DanTup commentedon Jan 24, 2024
Moving to an existing file is supported.. however I just tested it and see that when I select an existing file VS Code gives this message:
This message is misleading, and we actually do not replace the file, we merge into it. It seems like it's because of the VS Code API we use to select a file (showSaveDialog). I'm not sure if it's always done and I missed it, or it's new.
I've opened microsoft/vscode#203326 in VS Code to see if there could be a way to suppress this (or have an API for selecting files that does not do this).
RyanParkGH commentedon Jan 24, 2024
@DanTup thanks for the insight! I stopped dead in my tracks after receiving the new, rather, scary looking warning in VS Code:
I'll have to give this a go myself, it'll be very useful indeed!
DanTup commentedon Jan 24, 2024
@Autom8r-82 oof, that one is even worse (it more explicitly states that something bad will happen that will not). Thanks for the heads up - I'll see if I can find any other options for this.
FMorschel commentedon Jun 5, 2024
Just to point out the importing of necessary libraries could be handled by #30296.
bwilkerson commentedon Jun 5, 2024
I was under the impression that imports are correctly being computed. Is that not the case?
FMorschel commentedon Jun 5, 2024
I missed that there was an existing flag to enable it. Sorry 🙃! Figured it was still unavailable.
DanTup commentedon Jun 6, 2024
A flag to enable what? My understanding is that (for VS Code) this refactor is available on the latest SDKs and will add any necessary imports. No flags should be required (since v3.72.0 of Dart-Code was released and the stable SDK available at the time). If that's not what you're seeing, please let me know / file an issue.
(there are some issues with the dialog showing an overwrite prompt noted above which are not resolved yet though)
FMorschel commentedon Jun 6, 2024
Here you said that this was an experimental feature
I have not seen any indications (or I missed it completely) on any comments after that explaining it was available.
I'm sorry, I've not seen that release post of the extension. Found out about this site not long ago. But please enlighten me on why is this issue still open then. I came here and figured it was still under development because it was opened.
Edit
It is only because of those issues with the dialogues?
DanTup commentedon Jun 6, 2024
@FMorschel sorry for the confusion, you're right that I didn't post in this issue when this refactor was marked as not-experimental (which I did in a3399e3), only in the Dart-Code issue/release notes. I certainly should've noted it here.
Currently this refactor is only available in VS Code and not in IntelliJ/Android Studio. Making it available to IntelliJ/AS will require work in their Dart plugin, but might also require some additional work here to allow them to call the new refactoring system (possibly through LSP).
bwilkerson commentedon Jun 10, 2024
@jwren
theashggl commentedon Jul 7, 2026
I just landed on this issue and I think there should also be the feature available to not just extract class to ao new file but also extract any member of the class to another class and update the usages of that member accordingly with the object of the target class.
bwilkerson commentedon Jul 7, 2026
This deserves an issue of its own. Would you mind opening one? And perhaps expand, in the new issue, on what you're looking for. For example, are you thinking of something that would move members up or down in the class hierarchy, or are you thinking more generally about moving to an arbitrary class? Would it be limited to existing classes, or are you wanting it to create a new class? What are some examples of what you mean by "update the usages"? What should it do about references to other members that are no longer visible? How should references to the moved member be updated?
FMorschel commentedon Jul 7, 2026
I'm not exactly sure, but I think I saw an issue for this once, so maybe look for that too.