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

Exception when attempting to compute the file changes for the file move: Server error: The edit.getRefactoring request was cancelled." #42710

Open
ghost opened this issue Jul 15, 2020 · 44 comments
Labels
analyzer-refactoring analyzer-server area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@ghost
Copy link

ghost commented Jul 15, 2020

@liudonghua123 commented on Jul 15, 2020, 6:38 AM UTC:

Thanks for the feedback! If your issue is related to the Flutter framework itself,
please open an issue at
github.com/flutter/flutter.

Steps to Reproduce

  1. open project in android studio
  2. move/refactor some dart files under lib from a directory to another directory, both directory are under lib.
  3. move expection dialog shown Exception when attempting to compute the file changes for the file move: Server error: The edit.getRefactoring request was cancelled."
    image
  4. The dart files moved, but the imports are not changed, so the code broken.

Please tell us what you were doing and what went wrong

Version info

D:\code\flutter\colorful_classroom_app>flutter doctor -v
[✓] Flutter (Channel master, 1.20.0-8.0.pre.101, on Microsoft Windows [Version 10.0.19041.388], locale en-US)
    • Flutter version 1.20.0-8.0.pre.101 at D:\apps\flutter
    • Framework revision fcb5806933 (54 minutes ago), 2020-07-14 22:41:01 -0700
    • Engine revision 99c2b3a245
    • Dart version 2.9.0 (build 2.9.0-21.0.dev 20bf2fcf56)
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at D:\android\Android_SDK
    • Platform android-29, build-tools 29.0.2
    • ANDROID_HOME = D:\android\Android_SDK
    • Java binary at: D:\apps\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.5.4)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.5.30011.22
    • Windows 10 SDK version 10.0.18362.0

[✓] Android Studio (version 4.0)
    • Android Studio at D:\apps\Android Studio
    • Flutter plugin version 47.1.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[✓] VS Code, 32-bit edition (version 1.46.1)
    • VS Code at C:\Program Files (x86)\Microsoft VS Code
    • Flutter extension version 3.12.1

[✓] Connected device (4 available)
    • Windows (desktop) • windows    • windows-x64    • Microsoft Windows [Version 10.0.19041.388]
    • Web Server (web)  • web-server • web-javascript • Flutter Tools
    • Chrome (web)      • chrome     • web-javascript • Google Chrome 84.0.4147.89
    • Edge (web)        • edge       • web-javascript • Microsoft Edge 83.0.478.61

• No issues found!

This issue was moved by stevemessick from flutter/flutter-intellij#4702.

@lrhn lrhn added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Jul 16, 2020
@alexeylopukh-aloteq
Copy link

@lrhn When will this be fixed? It is impossible to work with this.

@lrhn lrhn added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Oct 29, 2020
@lrhn
Copy link
Member

lrhn commented Oct 29, 2020

I'm not on the analyzer team, so I wouldn't be able to answer that. Let's see if the analyzer team has a comment.

@knyghtryda
Copy link

Any updates on this? This is still happening on flutter 2.0.5 and android studio 4.1.3.

@CattoDoesCode
Copy link

Flutter 2.2.1, Android Studio 4.2.1, still an issue.

@idkq
Copy link

idkq commented Jul 27, 2021

I believe this happens when you move multiple files that are interdependent. So there must be a logic to move the files that are not dependent first, change their reference, and then move the others.

An alternative is move file by file (one by one)

@jcollins-g jcollins-g added analyzer-server analyzer-refactoring P2 A bug or feature request we're likely to work on labels Sep 1, 2021
@aliyazdi75
Copy link

This behavior happens only on windows. I've tested with linux an it worked as expected (except when you move the whole folder, refactoring doesn't work (neither windows nor linux)).

@bwilkerson
Copy link
Member

@DanTup Is this something you could look at?

@DanTup
Copy link
Collaborator

DanTup commented Feb 22, 2022

@bwilkerson is there a way to enable the instrumentation log in Android Studio? I tried searching the settings but can't find anywhere to add additional args.

I can't reproduce this specific error message, but it does fail for me on Windows in Android Studio with the following error:

Dart analysis issue: FileSystemException(path=M:\Dev\TestStuff\FlutterTestApp\lib\folder2\file2.dart; message=Cannot open file)

My feeling is that these messages could be caused by:

  • A race caused by AS sending concurrent requests to rename files (right now the analysis server only supports a single refactor at a time, and a second one will cancel the first)
  • AS maybe renaming the file(s) before all of the refactor requests have completed

In VS Code, the renames go through a queue so they won't be sent concurrently (since VS Code may also call us multiple times if multiple items are dragged) - should AS do the same?

Related: I have an open change for supporting renaming folders (https://dart-review.googlesource.com/c/sdk/+/158005) which I'm hoping to be able to merge soon (I'm waiting for a new VS Code LSP client to be published for some final testing/tweaking of cancellation). It doesn't help with multiple items being renamed/moved together but that's probably a logical next step (either by extending the protocol to support multiple items, or handling concurrent renames).

@bwilkerson
Copy link
Member

is there a way to enable the instrumentation log in Android Studio?

Yes. Open "Help > Find Action...". Search for "Registry..." and run the action. Search for "dart.server.additional.arguments" and edit it to add command-line arguments that will be sent to the server. Finally, restart the server.

@DanTup
Copy link
Collaborator

DanTup commented Feb 22, 2022

Thanks!

I still can't repro the original error message, but I see that report is quite old now. @aliyazdi75 can you confirm if you're seeing the same error noted in the title ("request was cancelled") or something else (perhaps the same issue I'm seeing?).

@bwilkerson for the error I'm seeing (log below), the issue seems to be that when computing edits for a rename, the references to that file are checked to see if they're package URIs or not, and that involves reading their content. However if they were renamed just before their content was read, the read fails.

Eg.:

  • file1 references file2, file2 references file1
  • in editor, drag both to a new folder
  • editor sends MOVE_FILE for file1 and gets the edits
  • edit performs the rename on disk around the same time as sending MOVE_FILE for file2
  • analyzer is computing edits for file2 and tries to read file1s content (which has just been renamed on disk) and fails

I can't think of a simple fix, although I suspect retrying the refactor after this happened (perhaps after a short delay) would succeed, as the renamed file would've been handled and the new rename would be looking at the reference from its new location, not the old one.

# Request for edits to move file1
1645547999993:Req:{"id"::"16","method"::"edit.getRefactoring","params"::{"kind"::"MOVE_FILE","file"::"M::\\Dev\\TestStuff\\FlutterTestApp\\lib\\folder1\\file1.dart","offset"::0,"length"::0,"validateOnly"::true,"options"::{"newFile"::"M::\\Dev\\TestStuff\\FlutterTestApp\\lib\\folder2\\file1.dart"}},"clientRequestTime"::1645547999991}
1645548000023:Res:{"id"::"16","result"::{"initialProblems"::[],"optionsProblems"::[],"finalProblems"::[]}}
1645548000035:Req:{"id"::"17","method"::"edit.getRefactoring","params"::{"kind"::"MOVE_FILE","file"::"M::\\Dev\\TestStuff\\FlutterTestApp\\lib\\folder1\\file1.dart","offset"::0,"length"::0,"validateOnly"::false,"options"::{"newFile"::"M::\\Dev\\TestStuff\\FlutterTestApp\\lib\\folder2\\file1.dart"}},"clientRequestTime"::1645548000035}
1645548000084:Res:{"id"::"17","result"::{"initialProblems"::[],"optionsProblems"::[],"finalProblems"::[],"change"::{"message"::"","edits"::[{"file"::"M::\\Dev\\TestStuff\\FlutterTestApp\\lib\\folder1\\file2.dart","fileStamp"::0,"edits"::[{"offset"::7,"length"::45,"replacement"::"'package::flutter_test_app/folder2/file1.dart'"}]}],"linkedEditGroups"::[]}}}

# Edits applied to file2 to update import
1645548000128:Req:{"id"::"18","method"::"analysis.updateContent","params"::{"files"::{"M::\\Dev\\TestStuff\\FlutterTestApp\\lib\\folder1\\file2.dart"::{"type"::"add","content"::"import 'package::flutter_test_app/folder2/file1.dart';\n\nclass File2 {}\n\nFile1? a;"}}},"clientRequestTime"::1645548000127}


# Begin request to rename file 2
1645548000128:Req:{"id"::"19","method"::"edit.getRefactoring","params"::{"kind"::"MOVE_FILE","file"::"M::\\Dev\\TestStuff\\FlutterTestApp\\lib\\folder1\\file2.dart","offset"::0,"length"::0,"validateOnly"::true,"options"::{"newFile"::"M::\\Dev\\TestStuff\\FlutterTestApp\\lib\\folder2\\file2.dart"}},"clientRequestTime"::1645548000127}
1645548000142:Res:{"id"::"18","result"::{}}
1645548000151:Res:{"id"::"19","result"::{"initialProblems"::[],"optionsProblems"::[],"finalProblems"::[]}}
1645548000169:Req:{"id"::"20","method"::"edit.getRefactoring","params"::{"kind"::"MOVE_FILE","file"::"M::\\Dev\\TestStuff\\FlutterTestApp\\lib\\folder1\\file2.dart","offset"::0,"length"::0,"validateOnly"::false,"options"::{"newFile"::"M::\\Dev\\TestStuff\\FlutterTestApp\\lib\\folder2\\file2.dart"}},"clientRequestTime"::1645548000152}

# File 1 is renamed on disk
1645548000199:Watch:<unknown>:M::\Dev\TestStuff\FlutterTestApp\lib\folder1\file1.dart:remove
1645548000201:Noti:{"event"::"analysis.flushResults","params"::{"files"::["M::\\Dev\\TestStuff\\FlutterTestApp\\lib\\folder1\\file1.dart"]}}
1645548000202:Watch:<unknown>:M::\Dev\TestStuff\FlutterTestApp\lib\folder2\file1.dart:add

# Error while computing edits for file2.. Tried to go to disk for modification stamp but the file has gone
1645548000227:Ex:FileSystemException(path=M::\Dev\TestStuff\FlutterTestApp\lib\folder1\file1.dart; message=Cannot retrieve modification time):
#0      _PhysicalFile.modificationStamp (package::analyzer/file_system/physical_file_system.dart::116::7)
#1      _OverlayFile.modificationStamp (package::analyzer/file_system/overlay_file_system.dart::146::18)
#2      FileSource.contentsFromFile (package::analyzer/src/source/source_resource.dart::68::14)
#3      FileSource.contents (package::analyzer/src/source/source_resource.dart::55::12)
#4      MoveFileRefactoringImpl._isPackageReference (package::analysis_server/src/services/refactoring/move_file.dart::179::34)
#5      MoveFileRefactoringImpl._computeNewUri (package::analysis_server/src/services/refactoring/move_file.dart::160::9)
#6      MoveFileRefactoringImpl.createChange.<anonymous closure> (package::analysis_server/src/services/refactoring/move_file.dart::148::22)
#7      ChangeBuilderImpl.addDartFileEdit (package::analyzer_plugin/src/utilities/change_builder/change_builder_core.dart::145::20)
<asynchronous suspension>
#8      MoveFileRefactoringImpl.createChange (package::analysis_server/src/services/refactoring/move_file.dart::147::7)
<asynchronous suspension>
#9      _RefactoringManager.getRefactoring.<anonymous closure> (package::analysis_server/src/edit/edit_domain.dart::1035::23)
<asynchronous suspension>

Edit: I also realise why VS Code doesn't see this - we currently make no attempt to handle multi-item renames in LSP (the "queue" was pre-LSP) so the refactor never runs when dragging multiple files there.

@bwilkerson
Copy link
Member

I think your analysis is correct. I can think of two possible solutions.

The first is to re-order the events on the client side. If we were to make all of the changes to each file before asking to move the next then we'd simulate a series of individual file moves, which is what server currently supports.

The second is to support multi-file moves in server directly. This is probably more work, but might be a little faster.

I don't remember enough about how this is implemented to know what the risks of these two approaches are.

@DanTup
Copy link
Collaborator

DanTup commented Feb 22, 2022

The second is to support multi-file moves in server directly. This is probably more work, but might be a little faster.

I think this is very similar to the in-progress changes to support directories (since we just collect all the files in the directory and enumerate through them). It would need an update to the protocol (for Android Studio - LSP already accepts multiple) and an update to the Android Studio plugin, but it probably is the best option (and something I'd like to do after landing the other changes).

The directory work is partly blocked for LSP (waiting on a new LSP client release, but also trying to handle more cases where we have inconsistent LineInfos for similar reasons to these), but I think it could be landed for non-LSP (although there will also need to be some work on the client to take advantage of it - passing folders over, but also ensuring the user can cancel if they decide it's taking too long).

Edit: That said, if we go down that route, it should probably be documented that clients should not send MOVE_FILES while also renaming files on disk in this way, since this error would remain a possibility.

@aliyazdi75
Copy link

@DanTup
Yes, I can still reproduce this on only Windows. It is so strange. It only happens on specific files with specific imports. I still couldn't reproduce this on some simple projects, but it happened on one of my big projects for specific files. If I can find a simple way I will inform you. This is the error message:
image

@javiermrz
Copy link

Still happens to me on MacOS and Flutter 3. Exactly same error message.

@MAlazhariy
Copy link

I'm also facing this problem and with every new version of Android Studio, I say to myself "maybe they solved the problem in this version", but no 😅

However, there is a way for me to solve this problem in a very simple and easy manner from within Android Studio (or vs code)

When I:

  • Change the name of the folder.
  • Or moving more than one file to another directory
  • Or moving a directory to another one

This problem occurs.

What is the solution for me?

Suppose we have a directory like: lib>view>screens, and we want to move it to the path lib/presentation>view>screens. In this case, I'll move the view directory into a new one called presentation.

However, after moving, the error dialog mentioned in above will pop up.

In this case, I will select package:malazhariy/view/ in any file affected by the problem and then modify the path according to the change I made, in this case, it would be: package:malazhariy/presentation/view/

  • Before: package:malazhariy/view/
  • After: .. package:malazhariy/presentation/view/

I will repeat this step for all affected files once by using the Replace in files command and its shortcut in AD is Ctrl+Shift+R for Windows. And I will modify the path of all files and once I press the Replace all button, the problem should be solved.


Note: When importing a file, avoid importing it like this ../../../../utils/styles.dart and make sure to import it like this 'package:flutter_restaurant/utils/styles.dart' to avoid any future problems of this kind.

This was my way of dealing with this problem 😁

Untitled.Project.mp4

@S-Man42
Copy link

S-Man42 commented Jan 13, 2023

Same problem for me. On my Windows machine I get the mentioned error message, on a newly installed Ubuntu VM I don't get the message, but the result is the same: The depending import paths will not be updated...

@PackRuble
Copy link

This is a very unfortunate thing. The only thing that saves is moving one file at a time. Then everything works as expected

@zxlbxx
Copy link

zxlbxx commented Jan 28, 2023

still on android studio 2022.1.1 with macOS 13.1 and flutter 3.3.8

@romatallinn
Copy link

romatallinn commented May 28, 2023

Still a problem; macOS, flutter 3.10, studio flamingo. 😢

@ifsygn
Copy link

ifsygn commented Jun 27, 2023

Still a problem; Windows 11, Flutter 3.10, Android Studio Flamingo

@est7
Copy link

est7 commented Jun 29, 2023

Why is this problem never solved...

@javiermrz
Copy link

javiermrz commented Jul 9, 2023

I started using Android Studio for Flutter, then switched to IntelliJ some time after and my experience has been great ever since. Haven't had errors like this, and you also have a Device Manager in IntelliJ for the emulator, so you don't need to open Android Studio. Hope this helps some people ♥️

@cyberpwnn
Copy link

Seriously why is this still a problem. What's a developer who cant refactor.

@Sumit258000
Copy link

Still facing same problem in Android Studio Giraffe | 2022.3.1

@StephenBrough
Copy link

Seeing this on Windows, Android Studio Iguana 2023.2.1 Canary 1. Almost every file I move now runs into this error and I have to go manually change every reference. Bit annoying :/

@romanr
Copy link

romanr commented Sep 25, 2023

Hello, and it's 3.5 years later. I mean, how important does the issue have to be to get it fixed? It's the refactoring that does not work.
And there is no workaround except you can try the lottery - refactoring files one by one. So, should we be getting an IDE from another vendor?

Moreover, the error causes havoc that you can't undo. Because, of course, it will show dialog that says there was an error and it too far gone now, it can't undo the mess. It's the worst-case scenario!
Android Studio-Cannot Undo-0926 0248 @2x

You have "one job". This is the job of the IDE, to refactor. If not this, then what? What are you doing releasing all those Hedgehogs and Iguanas if you're not fixing the main functionality of the IDE??

@ernestlipson
Copy link

ernestlipson commented Oct 2, 2023

It's Almost the end of 2023 and this Is still an issue. Facing the Same issue with Android Studio Giraffe | 2022.3.1 and Flutter 3.10.6

@romanr
Copy link

romanr commented Oct 2, 2023

@jcollins-g @idkq Was this issue mistakenly evaluated as P2 (likely to work on it) and not P1 (will work on it) ?
Looking at all the P1 issues in comparison, I struggle to find any issue that is more breaking than this one.

@Anksji
Copy link

Anksji commented Oct 11, 2023

facing same issue when it will be solved?

@Anksji
Copy link

Anksji commented Oct 11, 2023

we can't able to refract the code?

@DanTup
Copy link
Collaborator

DanTup commented Oct 16, 2023

Sorry for the lack of updates. This issue is unfortunately not just a simple bug fix. The reason for the error is that the IntelliJ plugin sends concurrent requests to the Dart analysis server when multiple items are moved. This is incorrect (since multiple moves could produce conflicting edits) but the Dart analysis server originally only supported moving a single item at a time so there was no real way to fix this besides IntelliJ disabling updating of imports when dragging multiple items (which is what VS Code was doing).

I've recently landed some changes to the server to support moving multiple items (and handling where individual moves might product conflicting edits). This is already working in VS Code if you're on bleeding-edge code (because with the LSP protocol changes like this don't require client changes) however there is still some work to do to have IntelliJ use it.

@bwilkerson
Copy link
Member

@alexander-doroshko

@GerogeLeon
Copy link

I wonder if the Dart has been abandoned and is not maintained anymore, because this issue has not been fixed for three years and is still not fixed, which is quite abnormal.

@romanr
Copy link

romanr commented Oct 28, 2023

Dart is both done and not done. We live in a schizo-corporate era of half-made products. Corporations develop products up until the point when it can be reported to shareholders that it's done. What are you're saying? bugs? okay we will look into that, but resources are already diverted to to other projects.
What? the bug that defeats the purpose of the product? I don't know, maybe it's your subjective opinion. how can it be that bad if the product was released after all, are you saying we're stupid?

@bwilkerson
Copy link
Member

Although I can understand how it might feel that way based on how long some issues have been open, Dart has not been abandoned. On the contrary, it is actively being maintained and improved. As part of the team that works on the IDE support I can assure you that all of us strive to provide the best product we can for our users. That includes both Google and non-Google contributors.

But we, like every team in every company that I've ever worked with, have a finite number of resources. That means that tradeoffs have to be made. We have to choose which features to build and which bugs to fix. Our first consideration is always how we can provide the greatest amount of help to the largest number of users. I'm certainly not claiming that we always make the right tradeoffs, and we are deeply aware of the fact that every feature we don't implement and every bug we don't fix negatively impacts at least some of our users, and sometimes many of them, but making tradeoffs like these is just a reality of life. Anywhere. Whether in large corporations or small companies.

I'm sorry for the frustration and lost productivity that this issue has caused, but as @DanTup mentioned above, some progress has been made. We now understand the cause of the bug and we have fixed the issue in VS Code. The remaining work for IntelliJ needs to happen in the IntelliJ Dart plugin. If it hasn't been reported yet, it might be worthwhile opening an issue here: https://youtrack.jetbrains.com/issues/IDEA in order to raise visibility of the issue.

@alexandr-efimov
Copy link

alexandr-efimov commented Jan 8, 2024

Same on re-packaging:

IntelliJ IDEA 2023.3.2 (Ultimate Edition)
Build #IU-233.13135.103, built on December 20, 2023
Licensed to ....
Runtime version: 17.0.9+7-b1087.9 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 14.1.2
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 12
Metal Rendering is ON
Registry:
ide.balloon.shadow.size=15
debugger.new.tool.window.layout=true
ide.experimental.ui=true
scala.erase.compiler.process.jdk.once=false
Non-Bundled Plugins:
com.jetbrains.packagesearch.intellij-plugin (233.11799.196)
Dart (233.13135.65)
org.jetbrains.android (233.13135.106)
io.flutter (77.0.1)
codiumai.codiumai (0.7.12)
org.intellij.scala (2023.3.19)
Kotlin: 233.13135.103-IJ

Workaround: move file by file, not whole folder

@romanr
Copy link

romanr commented Jan 9, 2024

But we, like every team in every company that I've ever worked with, have a finite number of resources. That means that tradeoffs have to be made. We have to choose which features to build and which bugs to fix.

Exactly, finite resources working on issues in order of priority. but the whole reason this issue at standstill for years is how carelessly it was (de)prioritised.

I submit my question again:

Was this issue mistakenly evaluated as P2 (likely to work on it) and not P1 (will work on it) ?
Looking at all the P1 issues in comparison, I struggle to find any issue that is more breaking than this one.

@tieorange
Copy link

Same issue here

@bwilkerson
Copy link
Member

In one sense I believe that the issue, at least as far as we're able to work on it, has been completed. From what I can tell by scanning the issue I think that all of the issues are on the IntelliJ side. Has an issue been raised on YouTrack? If so, it might be worth posting that link here so that others can find and upvote it.

If I'm misunderstanding the state of things, please let me know.

@DanTup
Copy link
Collaborator

DanTup commented Mar 4, 2024

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.

@austin047
Copy link

austin047 commented Apr 1, 2024

So this issue is not fixed yet?

@TinhHuynh
Copy link

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.

@DanTup
The link is not working. Could you help check please?

@DanTup
Copy link
Collaborator

DanTup commented Apr 15, 2024

@TinhHuynh the link still seems to work for me:

image

@TinhHuynh
Copy link

@DanTup
I have rechecked, and the link works fine now. There was an outage on their website at the time I commented.
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-refactoring analyzer-server area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests