Skip to content

[feature request] Extract class to a new file #30310

Open

Description

@JFixby

image

Activity

  1. added
    devexp-serverIssues related to some aspect of the analysis server
    P2A bug or feature request we're likely to work on
    type-enhancementA request for a change that isn't a bug
    on Aug 1, 2017
  2. scullabyte commented on Apr 19, 2020

    @scullabyte

    Any update on this? Possibly a way to do this with another application that will update all references? Thanks!

  3. cnsumner commented on Apr 20, 2020

    @cnsumner

    This would be extremely useful in VSCode. I have to do this operation manually 10s of times while mocking out an app UI.

  4. nilsreichardt commented on May 30, 2020

    @nilsreichardt
    Contributor

    Any updates?

  5. bwilkerson commented on Jun 1, 2020

    @bwilkerson
    Member

    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.

  6. magnussp commented on Oct 21, 2020

    @magnussp

    Would love to see this feature added. Makes life so much easier.

  7. ajaygautam commented on Nov 24, 2020

    @ajaygautam

    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!

  8. keehoo commented on Jan 30, 2021

    @keehoo

    almost 4 years... geez..

  9. dkbast commented on Feb 15, 2021

    @dkbast

    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

  10. dfaveur commented on Feb 25, 2021

    @dfaveur

    Yes please. It is very cumbersome currently to isolate widget per file

  11. krema commented on Mar 13, 2021

    @krema

    I just discovered a plugin that we can use in the meantime at least for flutter.

    https://github.com/marius-h/flutter_enhancement_suite

    Screen Shot 2021-03-13 at 14 36 32 PM

  12. 43 remaining items

  13. DanTup commented on Jan 24, 2024

    @DanTup
    Collaborator

    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:

    image

    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).

  14. RyanParkGH commented on Jan 24, 2024

    @RyanParkGH

    @DanTup thanks for the insight! I stopped dead in my tracks after receiving the new, rather, scary looking warning in VS Code:

    image

    I'll have to give this a go myself, it'll be very useful indeed!

  15. DanTup commented on Jan 24, 2024

    @DanTup
    Collaborator

    @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.

  16. FMorschel commented on Jun 5, 2024

    @FMorschel
    Contributor

    Just to point out the importing of necessary libraries could be handled by #30296.

  17. bwilkerson commented on Jun 5, 2024

    @bwilkerson
    Member

    I was under the impression that imports are correctly being computed. Is that not the case?

  18. FMorschel commented on Jun 5, 2024

    @FMorschel
    Contributor

    I missed that there was an existing flag to enable it. Sorry 🙃! Figured it was still unavailable.

  19. DanTup commented on Jun 6, 2024

    @DanTup
    Collaborator

    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)

  20. FMorschel commented on Jun 6, 2024

    @FMorschel
    Contributor
    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?

  21. DanTup commented on Jun 6, 2024

    @DanTup
    Collaborator

    @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).

  22. bwilkerson commented on Jun 10, 2024

    @bwilkerson
    Member
  23. added
    area-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.
    and removed on Feb 21, 2025
  24. theashggl commented on Jul 7, 2026

    @theashggl

    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.

  25. bwilkerson commented on Jul 7, 2026

    @bwilkerson
    Member

    ... 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?

  26. FMorschel commented on Jul 7, 2026

    @FMorschel
    Contributor

    are you thinking of something that would move members up or down in the class hierarchy

    I'm not exactly sure, but I think I saw an issue for this once, so maybe look for that too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-refactorsIssues with analysis server refactorsdevexp-serverIssues related to some aspect of the analysis servertype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions