Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename/move directory won't change import #4279

Open
ph55 opened this issue Jan 14, 2020 · 54 comments
Open

Rename/move directory won't change import #4279

ph55 opened this issue Jan 14, 2020 · 54 comments
Milestone

Comments

@ph55
Copy link

ph55 commented Jan 14, 2020

Manual search and replace currently required after renaming library directory.
Please add support for automatic refactor of imports.

Version info
[✓] Flutter (Channel beta, v1.12.13+hotfix.6, on Mac OS X 10.15.2 19C57, locale en-IL)
    • Flutter version 1.12.13+hotfix.6 at /usr/local/lib/flutter
    • Framework revision 18cd7a3601 (5 weeks ago), 2019-12-11 06:35:39 -0800
    • Engine revision 2994f7e1e6
    • Dart version 2.7.0


[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/sasha/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • ANDROID_HOME = /Users/sasha/Library/Android/sdk
    • ANDROID_SDK_ROOT = /Users/sasha/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.3, Build version 11C29
    • CocoaPods version 1.8.4

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 42.1.1
    • Dart plugin version 191.8593
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] IntelliJ IDEA Community Edition (version 2019.3.1)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 42.1.4
    • Dart plugin version 193.5731

[✓] VS Code (version 1.41.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.7.1

[✓] Connected device (3 available)
    • iPhone 11 Pro Max • D06766C9-E399-4AEF-B840-D9F00FF661EE • ios            • com.apple.CoreSimulator.SimRuntime.iOS-13-3 (simulator)
    • Chrome            • chrome                               • web-javascript • Google Chrome 79.0.3945.117
    • Web Server        • web-server                           • web-javascript • Flutter Tools

• No issues found!
@stevemessick stevemessick added this to the On Deck milestone Jan 14, 2020
@stevemessick
Copy link
Member

Thanks for the report!

@scheglov do you know about this?

@scheglov
Copy link
Contributor

@jwren worked on move / rename refactoring support in DAS.

@jwren
Copy link
Member

jwren commented Jan 15, 2020

@ph55 which action/ entry point are you using to rename the directory in IntelliJ? Are all sources within a lib/?

@ph55
Copy link
Author

ph55 commented Jan 15, 2020

@jwren yes, all directories in lib. Only directories. Renaming files will change imports.

Here for example I change helper to helpers:

Screenshots

image

image

Same will happen for core or common folders (any nesting level)

@wilburx9
Copy link

I am experiencing this issue too. My current plugin version is v43.0.1.

@WouterButhker
Copy link

I also still have this problem

@jacobokoenig
Copy link

Is there a plugin for this perhaps?

@reinaldomoreira
Copy link

Still having this problem on v48

@CoderJava
Copy link

Yes. I have the same issue.

@yasinarik
Copy link

The file name changes, directory name changes, and the folder of the files are not auto imported/renamed.

I have a large architecture in-development so this consumes lots of time. Thanks.

@harrisonturton
Copy link

harrisonturton commented Mar 18, 2021

Also having this issue.

When refactoring our prototype codebase into something more scalable (code-wise), this becomes a big pain point. I have to manually go through about a hundred files, delete the broken imports, and then iteratively go through the now-unimported widgets and import them again.

Generally the Intellij plugin has been wonderful! This is the only major pain point I've come across.

@venkatd
Copy link

venkatd commented Mar 23, 2021

This is by far my largest pain point. Also performing a large refactor and I'm losing hours manually moving files.

Given that there are ~40 thumbs up, any chance a few of us could combine resources and sponsor someone to contribute a fix to this? Anyone interested?

@atreeon
Copy link

atreeon commented Mar 23, 2021

I'm also having this issue and it has been really frustrating. Some kind of update would be very much appreciated. I think this used to work once upon a time; I'd have expected regressions to be prioritised. It is a real sink of my time actually. As @venkatd above mentioned it is the 3rd most voted issue in this repository with 40thumbs and it has been live for very long and is also the most reasonable issue to be worked on. Rename functionality should surely be quick and easy fix?

Please can we have an update as to when we should expect this to be fixed? ...or even better get it fixed as soon as possible please?

Thank you

@enginebai
Copy link

The version 57.0.2 still had this issue, this issue happened over 1 years, and it seems to be basic function. Could you treat this issue as one of the top priority??

@harrisonturton
Copy link

harrisonturton commented Jun 24, 2021

@enginebai If it's a blocker, I'm sure the Flutter team would appreciate you submitting a PR to fix this.

In the meantime, a grep xyz | sed s/old/new/ may help you out.

@mjablecnik
Copy link

@stevemessick @helin24 @devoncarew I hope that you know about this problem. When do you plan to fix it please?

@jacob314
Copy link
Contributor

Fyi @DanTup has been working on adding Analysis Server functionality to support this in IntelliJ and VSCode.

@lhengl
Copy link

lhengl commented Dec 2, 2021

December 2021, and still having this issue. I'm on Android Studio Arctic Fox and flutter plugin version 62.0.1.

Is this also a problem in VSCode? Maybe I should move IDE if that's the case, it's really annoying.

@DanTup
Copy link
Contributor

DanTup commented Dec 2, 2021

This also isn't currently supported in VS Code. It is something I have a basic working example for in the server, but it still needs some work (around performance, and how to ensure the request can be cancelled or timeout if it would take too long - for ex. if you tried to rename an enormous folder).

@tieorange
Copy link

Any updates maybe?

I just got a legacy code that needs a refactor. And it's a nightmare to fix every import manually :D

@TadashiCZ
Copy link

Any updates on this? It's been two years already. It is super annoying when doing any refactoring. Thanks.

@paktalin
Copy link

we really need this feature. it's super annoying to refactor the project

@DanTup
Copy link
Contributor

DanTup commented Apr 26, 2022

The server has support for renaming folders since dart-lang/sdk@729b2e5, but it will require changes in IntelliJ/Android Studio to call the API for folders.

For VS Code, I'm waiting on a new version of the VS Code LSP Client (coming in the next few weeks, I believe) so that cancellations can be handled properly, before I enable it there.

@OwlCodR
Copy link

OwlCodR commented Apr 29, 2022

+1

1 similar comment
@AD1N1993
Copy link

+1

@jacob314
Copy link
Contributor

Fyi @jwren. This is a good example of a case we should probably implement in the Dart IntelliJ plugin not the Flutter IntelliJ plugin.

@CrossBread
Copy link

@jacob314 agreed that would make more sense. If you close this, would you link to the issue in the Dart Plugin so we can know where to subscribe for updates?

Thank you for your work on the tools/framework!

@jacob314
Copy link
Contributor

Fyi, there is also an issue tracking supporting this in VSCode.
Dart-Code/Dart-Code#2483

@fedosovmu
Copy link

fedosovmu commented May 18, 2022

I solved this problem for myself by using the "Replace in Files" command

Screenshot 2022-05-18 at 14 36 30 Screenshot 2022-05-18 at 14 37 15

@J-Siu
Copy link

J-Siu commented Jun 4, 2022

I solved this problem for myself by using the "Replace in Files" command

Unless flutter command line / vscode ext implement something like "project move/rename/etc." This should be the way for our own src files.

On the other hand, most of the auto-get file(eg. .filecache, debug_*, etc) are using absolute path instead of relative to project root. Maybe that can be changed.

@ajay-zartek
Copy link

I have the same issue.

@martijnvanderlaan
Copy link

Also same issue. I have to start refactoring a huge code base from a previous team. I really hope there will be a fix soon or a work around.

@Juliocsreis
Copy link

+1

@ahmedtanjim
Copy link

same issue

@DanTup
Copy link
Contributor

DanTup commented Sep 5, 2022

Fyi @DanTup has been working on adding Analysis Server functionality to support this in IntelliJ and VSCode.

Renaming a single folder is now supported in VS Code when using Flutter 3.3 / Dart 2.18 (see https://dartcode.org/releases/#folder-renames). Renaming/moving multiple items at once is not yet supported (it requires additional server work).

Supporting this in Android Studio / IntelliJ will require some additional changes in its plugin (both to pass folder renames through, and also to provide some way of cancelling in the case of starting a large folder rename and wanting to abort if it's slow).

@ilexbor
Copy link

ilexbor commented Jun 17, 2023

It's already June 2023. The problem is already 3.5 years old. Absolutely everyone faces this problem.
When will this problem be solved?

@tolotrasamuel
Copy link

tolotrasamuel commented Jun 21, 2023

First of all, thanks for the developers for building this plugin because honestly, we love all jetbrains IDE.
Secondly, this is the number one most voted issue on Flutter intellij and we would appreciate an update on this. Is there any major technical difficulty that prevents the fix ? As @ilexbor pointed out, it has been 3.5 years of waiting
An estimate timeline would be appreciated

Screen Shot 2023-06-20 at 11 35 42 PM

@vkg001
Copy link

vkg001 commented Jul 17, 2023

I solved this problem for myself by using the "Replace in Files" command

Screenshot 2022-05-18 at 14 36 30 Screenshot 2022-05-18 at 14 37 15

thankyou sooooo much

@Serena867
Copy link

This is still a significant issue. I love the plugin overall, but this makes refactoring anything of any appreciable size an absolute nightmare.

@mym0404
Copy link

mym0404 commented Oct 14, 2023

At first, I thought this is a bug in my IDE only. It makes me surprise all the Flutter developers suffer same.

@littlebytesof
Copy link

littlebytesof commented Nov 17, 2023

Suffering from the same issue, I hope that it will be resolved asap. It makes refactoring so demanding.
The closet workaround I could come up with is to make a new package, move into it the files in the old one, and then delete the latter.

@tolotrasamuel
Copy link

In the normal Replace in Files method is now broken too LOL.
It messes up all the imports, Like seriously this is frustrating

Then after updating Android studio, it freezes when renaming directory

@tolotrasamuel
Copy link

tolotrasamuel commented Dec 1, 2023

Stuck there every time I move a directory. I have to force quit
Screenshot 2023-12-01 at 4 49 51 PM

Update I found the reason, uncheck this

Screenshot 2023-12-01 at 5 34 15 PM

@mjablecnik
Copy link

mjablecnik commented Dec 3, 2023

When I want to rename some directory so I create new directory and move all files from old directory into new one by one.
It is sometime faster then rename directory and then quick force whole IDE due to freeze.. :)

@ziadhassan7
Copy link

Why isn't this getting fixed already!!!!!!!!

@1mohamedelasri
Copy link

Why isn't this getting fixed already!!!!!!!!

I'm also surprised that this is not fixed yet.

@ahmedtanjim
Copy link

Still having the issue

@kvenn
Copy link

kvenn commented Jan 12, 2024

I'd also settle for a "Apply first quick fix on all import related issues"

The quick fix suggests the correct path when there's an import related error, so even as a patch, that could be a solution (remove invalid imports, add the first suggested one).

This works for other languages (through the ambiguous imports). I think the issue with flutter is you can do relative or absolute imports. But that should be easy to just respect your lint settings for.

@Serena867
Copy link

Serena867 commented Jan 16, 2024

I'd also settle for a "Apply first quick fix on all import related issues"

The quick fix suggests the correct path when there's an import related error, so even as a patch, that could be a solution (remove invalid imports, add the first suggested one).

This works for other languages (through the ambiguous imports). I think the issue with flutter is you can do relative or absolute imports. But that should be easy to just respect your lint settings for.

The way I dealt with this when creating a code generator might apply here as my generator needed to move files around and detect correct imports. For ambiguous imports, file names, etc I wound up looking at the originally referenced import, getting a hash, and making sure the imports after moving or renaming directories or multiple files imported the correct import by using the file with the same hash when ambiguous imports were detected.

I wouldn't call it the absolute best solution, but it works well enough. This could be a solution that prevents bugs that are hard to track down when using the first available import as that can often be the wrong import.

My quick workaround for this problem was to use build_runner to accept a command for moving directories and files using the methods above. It's not my favourite thing to use, but it was relatively quick to write and saved a lot of time when refactoring.

@erlangparasu
Copy link

Any updates?

@elliotkhd
Copy link

It's been 4 years

@komaxx
Copy link

komaxx commented Mar 2, 2024

I'm starting to think that JetBrains does not want to support Flutter - after all it's competition for their own Kotlin multiplatform product..

@bawantha
Copy link

bawantha commented Mar 4, 2024

Stilll

@DanTup
Copy link
Contributor

DanTup commented Mar 4, 2024

This repository is for the Flutter plugin for IntelliJ that's maintained by the Flutter team but my impression is that this feature should be implemented in the Dart plugin for IntelliJ that's maintained by JetBrains.

I think this is the relevant issue in the JetBrains IntelliJ issue tracker:

https://youtrack.jetbrains.com/issue/IDEA-328359/Renaming-a-folder-in-a-Dart-or-Flutter-project-doesnt-update-imports

Currently that issue only has 10 👍s/votes, so it may be worth adding your votes there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests