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

Analyzer fails on VSCode Extract Method #43459

Closed
timsneath opened this issue Sep 17, 2020 · 9 comments
Closed

Analyzer fails on VSCode Extract Method #43459

timsneath opened this issue Sep 17, 2020 · 9 comments
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.

Comments

@timsneath
Copy link
Contributor

On attempting to refactor (extract method) from VSCode, I got this error from the analyzer:

[Error - 6:23:40 PM] Request workspace/executeCommand failed.
  Message: An error occurred while handling workspace/executeCommand request
  Code: -32001 
[Error - 6:23:40 PM] An error occurred while handling workspace/executeCommand request: InconsistentAnalysisException: Requested result might be inconsistent with previously returned results

#0      AnalysisSessionImpl._checkConsistency (package:analyzer/src/dart/analysis/session.dart:146:7)
#1      AnalysisSessionImpl.getResolvedUnit (package:analyzer/src/dart/analysis/session.dart:120:5)
#2      addLibraryImports (package:analysis_server/src/services/correction/util.dart:34:37)
#3      ExtractMethodRefactoringImpl.createChange (package:analysis_server/src/services/refactoring/extract_method.dart:382:11)
#4      PerformRefactorCommandHandler.handle.<anonymous closure>.<anonymous closure> (package:analysis_server/src/lsp/handlers/commands/perform_refactor.dart:58:42)
<asynchronous suspension>
#5      PerformRefactorCommandHandler.handle.<anonymous closure>.<anonymous closure> (package:analysis_server/src/lsp/handlers/commands/perform_refactor.dart)
#6      ErrorOr.mapResult (package:analysis_server/lsp_protocol/protocol_special.dart:255:12)
#7      PerformRefactorCommandHandler.handle.<anonymous closure> (package:analysis_server/src/lsp/handlers/commands/perform_refactor.dart:51:12)
#8      ErrorOr.mapResult (package:analysis_server/lsp_protocol/protocol_special.dart:255:12)
#9      PerformRefactorCommandHandler.handle (package:analysis_server/src/lsp/handlers/commands/perform_refactor.dart:48:19)
<asynchronous suspension>
#10     ExecuteCommandHandler.handle (package:analysis_server/src/lsp/handlers/handler_execute_command.dart:44:20)
#11     MessageHandler.handleMessage (package:analysis_server/src/lsp/handlers/handlers.dart:133:12)
#12     ServerStateMessageHandler.handleMessage (package:analysis_server/src/lsp/handlers/handlers.dart:172:36)
#13     LspAnalysisServer.handleMessage.<anonymous closure> (package:analysis_server/src/lsp/lsp_analysis_server.dart:287:47)
#14     _rootRun (dart:async/zone.dart:1190:13)
#15     _CustomZone.run (dart:async/zone.dart:1093:19)
#16     _runZoned (dart:async/zone.dart:1630:10)
#17     runZonedGuarded (dart:async/zone.dart:1618:12)
#18     LspAnalysisServer.handleMessage (package:analysis_server/src/lsp/lsp_analysis_server.dart:282:5)
#19     LspByteStreamServerChannel._readMessage (package:analysis_server/src/lsp/channel/lsp_byte_stream_channel.dart:85:16)
#20     LspByteStreamServerChannel.listen.<anonymous closure> (package:analysis_server/src/lsp/channel/lsp_byte_stream_channel.dart:54:24)
#21     _rootRunUnary (dart:async/zone.dart:1198:47)
#22     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
#23     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
#24     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
#25     _DelayedData.perform (dart:async/stream_impl.dart:611:14)
#26     _StreamImplEvents.handleNext (dart:async/stream_impl.dart:730:11)
#27     _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:687:7)
#28     _rootRun (dart:async/zone.dart:1182:47)
#29     _CustomZone.run (dart:async/zone.dart:1093:19)
#30     _CustomZone.runGuarded (dart:async/zone.dart:997:7)
#31     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
#32     _rootRun (dart:async/zone.dart:1190:13)
#33     _CustomZone.run (dart:async/zone.dart:1093:19)
#34     _CustomZone.runGuarded (dart:async/zone.dart:997:7)
#35     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
#36     _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#37     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#38     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#39     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:169:5)

Dart version

Dart SDK version: 2.10.0-124.0.dev (dev) (Mon Sep 14 12:29:28 2020 -0700) on "windows_x64"
@timsneath
Copy link
Contributor Author

Code left me with a newMethod but no popup to rename the method, @DanTup

@DanTup
Copy link
Collaborator

DanTup commented Sep 17, 2020

Code left me with a newMethod but no popup to rename the method

For LSP, this is currently expected - there's not currently a way for us to trigger a rename from a code action (I have an open issue at microsoft/language-server-protocol#764). Ofc, the error is not expected - I'll take a look.

It may be worth enabling the analysis server log so if you see this again (or other issues) you can grab a copy of the LSP traffic without needing to reproduce it. I run with it enabled all the time (it can get big in a long session, but it is overwritten on each session so won't just grow infinitely).

@lrhn lrhn added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Sep 17, 2020
@DanTup
Copy link
Collaborator

DanTup commented Sep 17, 2020

@timsneath I haven't been able to reproduce this - are you working in a plain Dart app, or Flutter? Is it possible the refactor was initially slow and you may have typed (or tried it a second time) as a result?

I've seen some reports of refactoring initially being slow (perhaps due to the server building an index), and wonder whether other actions while it is being processed might result in this (though I'd expect that the refactor should be cancelled and a more specific message explaining that).

@timsneath
Copy link
Contributor Author

Yes -- I think that's what happened (executed the command twice). But as you say, we shouldn't bail with an exception when that occurs :)

@DanTup
Copy link
Collaborator

DanTup commented Sep 19, 2020

Great, thanks for confirming - I think I should be able to reproduce that with some forced delays in the server then. I think there are a few things we should do:

  1. Use LSP's new progress events to show progress when we're doing slow actions (this will give some visual indication if the index is still building) - I have some of this in progress (to replace custom messages for "Analyzing..." status messages) so shouldn't be difficult.
  2. Ensure if VS Code cancels a refactor (eg. because you sent a second one) that we correctly send a cancelled response (I don't think it's what happened here, but suspect if it had, we may have just given a different type of exception instead of a proper cancelled response)
  3. Map servers InconsistentAnalysisException exceptions onto ContentModified responses for LSP (though I'll need to test how VS Code handles this response - hopefully silently)

dart-bot pushed a commit that referenced this issue Sep 30, 2020
… arrives

See #43459.

Change-Id: I52bf26e80b0d6ddb577c89b5a18ff7563e614cb4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/165321
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Danny Tuppeny <danny@tuppeny.com>
@DanTup
Copy link
Collaborator

DanTup commented Sep 30, 2020

Got some fixes on the way that I think will resolve this:

The middle one resolves the error above, though the first one should actually prevent that situation (as the first refactor would be cancelled when the second is sent). The third one for now is just cosmetic (so you know something is happening), but at some point it will be upgraded to a cancellable progress, so you could cancel it from the client if it's taking long (which hopefully isn't common - but refactors involving unindexed files can sometimes have a delay).

dart-bot pushed a commit that referenced this issue Sep 30, 2020
…uring a refactor

See #43459.

Change-Id: I2e32ba0ba1020d18ea574caac42e79ec184a5562
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/165362
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Danny Tuppeny <danny@tuppeny.com>
dart-bot pushed a commit that referenced this issue Sep 30, 2020
See #43459.

Change-Id: I055e4f61499675b9e1ec26e25d894b855f3170c7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/165363
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Danny Tuppeny <danny@tuppeny.com>
@DanTup
Copy link
Collaborator

DanTup commented Sep 30, 2020

Those changes (minus the cancellable one) are all merged (though may take a few days to get to Flutter), though I don't have permission to close this (and forgot to but "Fixes" in the commit message) so one of you will have to do it. Thanks! :-)

@mhwsam
Copy link

mhwsam commented Aug 31, 2024

facing the same issue, "An error occurred while handling workspace/executeCommand re" was trying to build a notepad app like this

@DanTup
Copy link
Collaborator

DanTup commented Aug 31, 2024

@mhwsam this issue is quite old - could you file a new issue with details of how to reproduce this (and ideally a log captured by passing --instrumentation-log-file=/path/to/log.txt when starting the server - though do note the log will contain parts of your open files, so best to reproduce using a simple sample project). Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
Projects
None yet
Development

No branches or pull requests

5 participants