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

move to file fail on a simple case (4 lines) #59968

Open
stephane-archer opened this issue Jan 23, 2025 · 9 comments
Open

move to file fail on a simple case (4 lines) #59968

stephane-archer opened this issue Jan 23, 2025 · 9 comments
Assignees
Labels
analyzer-refactoring 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

@stephane-archer
Copy link

Image Image Image

An error occurred while handling workspace/executeCommand request

import 'package:flutter_riverpod/flutter_riverpod.dart';

final isExposureAnalysisToolActivatedProvider = StateProvider<bool>(
  (ref) {return false;}
);
@stephane-archer stephane-archer added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Jan 23, 2025
@FMorschel
Copy link
Contributor

CC @DanTup

@bwilkerson bwilkerson added analyzer-refactoring P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Jan 23, 2025
@DanTup
Copy link
Collaborator

DanTup commented Jan 27, 2025

@stephane-archer I wasn't able to reproduce this in a new project using your code above. Is it possible you could capture a log file performing this operation?

Could you try capturing debugging logs while reproducing this?

  • Open the file and get to a point where you're ready to perform the "Move to File" refactor
  • Run the Dart: Capture Analysis Server Logs command
  • Perform the refactor, triggering the error
  • Click Cancel on the logging notification to stop logging and open the log
  • Remove anything sensitive from the log
  • Attach the log here or in a gist

Thanks!

@stephane-archer
Copy link
Author

@DanTup

!! ⚠️ PLEASE REVIEW THIS LOG FOR SENSITIVE INFORMATION BEFORE SHARING ⚠️ !!
Dart Code extension: 3.102.0
Flutter extension: 3.102.0 (activated)

App: Visual Studio Code
App Host: desktop
Version: mac 1.96.4

Workspace type: Flutter (LSP)
Workspace name: Lutme

Dart (3.6.1): /Users/fractale/flutter/bin/cache/dart-sdk
Flutter (3.27.3): /Users/fractale/flutter (No device)


Logging Categories:
    General, Analyzer, CommandProcesses

Wed Jan 29 2025 [16:26:50 GMT+0100 (Central European Standard Time)] Log file started
[16:26:50] [Analyzer] [Info] ==> Content-Length: 276
[16:26:50] [Analyzer] [Info] ==> {"jsonrpc":"2.0","id":32,"method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart"},"position":{"line":2,"character":34}},"clientRequestTime":1738164410325}
[16:26:50] [Analyzer] [Info] <== Content-Length: 113
Content-Type: application/vscode-jsonrpc; charset=utf-8
[16:26:50] [Analyzer] [Info] <== {"id":32,"jsonrpc":"2.0","result":[{"range":{"end":{"character":45,"line":2},"start":{"character":6,"line":2}}}]}
[16:26:50] [Analyzer] [Info] ==> Content-Length: 230
[16:26:50] [Analyzer] [Info] ==> {"jsonrpc":"2.0","id":33,"method":"textDocument/codeLens","params":{"textDocument":{"uri":"file:///Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart"}},"clientRequestTime":1738164410525}
[16:26:50] [Analyzer] [Info] <== Content-Length: 37
Content-Type: application/vscode-jsonrpc; charset=utf-8
[16:26:50] [Analyzer] [Info] <== {"id":33,"jsonrpc":"2.0","result":[]}
[16:26:55] [Analyzer] [Info] ==> Content-Length: 353
[16:26:55] [Analyzer] [Info] ==> {"jsonrpc":"2.0","id":34,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart"},"range":{"start":{"line":2,"character":34},"end":{"line":2,"character":34}},"context":{"diagnostics":[],"triggerKind":1}},"clientRequestTime":1738164415522}
[16:26:55] [Analyzer] [Info] <== Content-Length: 98
Content-Type: application/vscode-jsonrpc; charset=utf-8
[16:26:55] [Analyzer] [Info] <== {"id":11,"jsonrpc":"2.0","method":"window/workDoneProgress/create","params":{"token":"ANALYZING"}}
[16:26:55] [Analyzer] [Info] ==> Content-Length: 73
[16:26:55] [Analyzer] [Info] ==> {"jsonrpc":"2.0","id":11,"result":null,"clientRequestTime":1738164415526}
[16:26:55] [Analyzer] [Info] <== Content-Length: 118
Content-Type: application/vscode-jsonrpc; charset=utf-8
[16:26:55] [Analyzer] [Info] <== {"jsonrpc":"2.0","method":"$/progress","params":{"token":"ANALYZING","value":{"kind":"begin","title":"Analyzing…"}}}
[16:26:55] [Analyzer] [Info] <== Content-Length: 93
Content-Type: application/vscode-jsonrpc; charset=utf-8
[16:26:55] [Analyzer] [Info] <== {"jsonrpc":"2.0","method":"$/progress","params":{"token":"ANALYZING","value":{"kind":"end"}}}
[16:26:55] [Analyzer] [Info] <== Content-Length: 2033
Content-Type: application/vscode-jsonrpc; charset=utf-8
[16:26:55] [Analyzer] [Info] <== {"id":34,"jsonrpc":"2.0","result":[{"command":{"arguments":[{"path":"/Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart"}],"command":"dart.edit.sortMembers","title":"Sort Members"},"kind":"source.sortMembers","title":"Sort Members"},{"command":{"arguments":[{"path":"/Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart"}],"command":"dart.edit.organizeImports","title":"Organize Imports"},"kind":"source.organizeImports","title":"Organize Imports"},{"command":{"arguments":[{"path":"/Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart"}],"command":"dart.edit.fixAll","title":"Fix All"},"kind":"source.fixAll","title":"Fix All"},{"command":{"arguments":[{"action":"dart.assist.add.typeAnnotation"}],"command":"dart.logAction","title":"Log Action"},"diagnostics":[],"edit":{"documentChanges":[{"edits":[{"newText":"StateProvider<bool> ","range":{"end":{"character":6,"line":2},"start":{"character":6,"line":2}}}],"textDocument":{"uri":"file:///Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart","version":1}}]},"kind":"refactor.add.typeAnnotation","title":"Add type annotation"},{"command":{"arguments":[{"filePath":"/Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart","selectionOffset":92,"selectionLength":0,"arguments":["file:///Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart"]}],"command":"dart.refactor.move_top_level_to_file","title":"Move 'isExposureAnalysisToolActivatedProvider' to file"},"data":{"parameters":[{"actionLabel":"Move","defaultValue":"file:///Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart","filters":{"Dart":["dart"]},"kind":"saveUri","parameterLabel":"Move to:","parameterTitle":"Select a file to move to"}]},"kind":"refactor.move","title":"Move 'isExposureAnalysisToolActivatedProvider' to file"}]}
[16:26:55] [Analyzer] [Info] ==> Content-Length: 353
[16:26:55] [Analyzer] [Info] ==> {"jsonrpc":"2.0","id":35,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart"},"range":{"start":{"line":2,"character":34},"end":{"line":2,"character":34}},"context":{"diagnostics":[],"triggerKind":1}},"clientRequestTime":1738164415714}
[16:26:55] [Analyzer] [Info] <== Content-Length: 98
Content-Type: application/vscode-jsonrpc; charset=utf-8
[16:26:55] [Analyzer] [Info] <== {"id":12,"jsonrpc":"2.0","method":"window/workDoneProgress/create","params":{"token":"ANALYZING"}}
[16:26:55] [Analyzer] [Info] ==> Content-Length: 73
[16:26:55] [Analyzer] [Info] ==> {"jsonrpc":"2.0","id":12,"result":null,"clientRequestTime":1738164415717}
[16:26:55] [Analyzer] [Info] <== Content-Length: 118
Content-Type: application/vscode-jsonrpc; charset=utf-8
[16:26:55] [Analyzer] [Info] <== {"jsonrpc":"2.0","method":"$/progress","params":{"token":"ANALYZING","value":{"kind":"begin","title":"Analyzing…"}}}Content-Length: 93
Content-Type: application/vscode-jsonrpc; charset=utf-8

{"jsonrpc":"2.0","method":"$/progress","params":{"token":"ANALYZING","value":{"kind":"end"}}}
[16:26:56] [Analyzer] [Info] <== Content-Length: 2033
Content-Type: application/vscode-jsonrpc; charset=utf-8
[16:26:56] [Analyzer] [Info] <== {"id":35,"jsonrpc":"2.0","result":[{"command":{"arguments":[{"path":"/Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart"}],"command":"dart.edit.sortMembers","title":"Sort Members"},"kind":"source.sortMembers","title":"Sort Members"},{"command":{"arguments":[{"path":"/Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart"}],"command":"dart.edit.organizeImports","title":"Organize Imports"},"kind":"source.organizeImports","title":"Organize Imports"},{"command":{"arguments":[{"path":"/Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart"}],"command":"dart.edit.fixAll","title":"Fix All"},"kind":"source.fixAll","title":"Fix All"},{"command":{"arguments":[{"action":"dart.assist.add.typeAnnotation"}],"command":"dart.logAction","title":"Log Action"},"diagnostics":[],"edit":{"documentChanges":[{"edits":[{"newText":"StateProvider<bool> ","range":{"end":{"character":6,"line":2},"start":{"character":6,"line":2}}}],"textDocument":{"uri":"file:///Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart","version":1}}]},"kind":"refactor.add.typeAnnotation","title":"Add type annotation"},{"command":{"arguments":[{"filePath":"/Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart","selectionOffset":92,"selectionLength":0,"arguments":["file:///Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart"]}],"command":"dart.refactor.move_top_level_to_file","title":"Move 'isExposureAnalysisToolActivatedProvider' to file"},"data":{"parameters":[{"actionLabel":"Move","defaultValue":"file:///Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart","filters":{"Dart":["dart"]},"kind":"saveUri","parameterLabel":"Move to:","parameterTitle":"Select a file to move to"}]},"kind":"refactor.move","title":"Move 'isExposureAnalysisToolActivatedProvider' to file"}]}
[16:26:57] [Analyzer] [Info] ==> Content-Length: 230
[16:26:57] [Analyzer] [Info] ==> {"jsonrpc":"2.0","id":36,"method":"textDocument/codeLens","params":{"textDocument":{"uri":"file:///Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart"}},"clientRequestTime":1738164417909}
[16:26:57] [Analyzer] [Info] <== Content-Length: 37
Content-Type: application/vscode-jsonrpc; charset=utf-8
[16:26:57] [Analyzer] [Info] <== {"id":36,"jsonrpc":"2.0","result":[]}
[16:27:06] [Analyzer] [Info] ==> Content-Length: 276
[16:27:06] [Analyzer] [Info] ==> {"jsonrpc":"2.0","id":37,"method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart"},"position":{"line":2,"character":34}},"clientRequestTime":1738164426415}
[16:27:06] [Analyzer] [Info] <== Content-Length: 113
Content-Type: application/vscode-jsonrpc; charset=utf-8
[16:27:06] [Analyzer] [Info] <== {"id":37,"jsonrpc":"2.0","result":[{"range":{"end":{"character":45,"line":2},"start":{"character":6,"line":2}}}]}
[16:27:06] [Analyzer] [Info] ==> Content-Length: 230
[16:27:06] [Analyzer] [Info] ==> {"jsonrpc":"2.0","id":38,"method":"textDocument/codeLens","params":{"textDocument":{"uri":"file:///Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart"}},"clientRequestTime":1738164426614}
[16:27:06] [Analyzer] [Info] <== Content-Length: 37
Content-Type: application/vscode-jsonrpc; charset=utf-8
[16:27:06] [Analyzer] [Info] <== {"id":38,"jsonrpc":"2.0","result":[]}
[16:27:06] [Analyzer] [Info] ==> Content-Length: 398
[16:27:06] [Analyzer] [Info] ==> {"jsonrpc":"2.0","id":39,"method":"workspace/executeCommand","params":{"command":"dart.refactor.move_top_level_to_file","arguments":[{"filePath":"/Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart","selectionOffset":92,"selectionLength":0,"arguments":["file:///Users/fractale/CommercialProjects/Lutme/lib/name.dart"]}]},"clientRequestTime":1738164426653}
[16:27:06] [Analyzer] [Info] <== Content-Length: 98
Content-Type: application/vscode-jsonrpc; charset=utf-8
[16:27:06] [Analyzer] [Info] <== {"id":13,"jsonrpc":"2.0","method":"window/workDoneProgress/create","params":{"token":"ANALYZING"}}
[16:27:06] [Analyzer] [Info] ==> Content-Length: 73
[16:27:06] [Analyzer] [Info] ==> {"jsonrpc":"2.0","id":13,"result":null,"clientRequestTime":1738164426663}
[16:27:06] [Analyzer] [Info] <== Content-Length: 118
Content-Type: application/vscode-jsonrpc; charset=utf-8
[16:27:06] [Analyzer] [Info] <== {"jsonrpc":"2.0","method":"$/progress","params":{"token":"ANALYZING","value":{"kind":"begin","title":"Analyzing…"}}}
[16:27:06] [Analyzer] [Info] <== Content-Length: 127
Content-Type: application/vscode-jsonrpc; charset=utf-8
[16:27:06] [Analyzer] [Info] <== {"id":39,"jsonrpc":"2.0","error":{"code":-32001,"message":"An error occurred while handling workspace/executeCommand request"}}
[16:27:06] [Analyzer] [Info] <== Content-Length: 1816
Content-Type: application/vscode-jsonrpc; charset=utf-8
[16:27:06] [Analyzer] [Info] <== {"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"An error occurred while handling workspace/executeCommand request: RangeError (length): Invalid value: Not in inclusive range 0..77: -1\n#0      _Array.[] (dart:core-patch/array.dart)\n#1      _FbGenericList.[] (package:analyzer/src/summary/flat_buffers.dart:742:22)\n#2      Search.prefixesUsedInLibrary (package:analyzer/src/dart/analysis/search.dart:333:53)\n<asynchronous suspension>\n#3      SearchEngineImpl.searchPrefixesUsedInLibrary (package:analysis_server/src/services/search/search_engine_internal.dart:110:12)\n<asynchronous suspension>\n#4      MoveTopLevelToFile.compute (package:analysis_server/src/services/refactoring/move_top_level_to_file.dart:159:13)\n<asynchronous suspension>\n#5      RefactorCommandHandler.handle.<anonymous closure> (package:analysis_server/src/lsp/handlers/commands/refactor_command_handler.dart:81:20)\n<asynchronous suspension>\n#6      ErrorOr.mapResult (package:analysis_server/src/lsp/error_or.dart:94:11)\n<asynchronous suspension>\n#7      ServerStateMessageHandler.handleMessage (package:analysis_server/src/lsp/handlers/handlers.dart:452:11)\n<asynchronous suspension>\n#8      LspAnalysisServer._handleRequestMessage (package:analysis_server/src/lsp/lsp_analysis_server.dart:1068:18)\n<asynchronous suspension>\n#9      LspAnalysisServer.handleMessage.<anonymous closure>.<anonymous closure> (package:analysis_server/src/lsp/lsp_analysis_server.dart:509:15)\n<asynchronous suspension>\n#10     OperationPerformanceImpl.runAsync (package:analyzer/src/util/performance/operation_performance.dart:174:14)\n<asynchronous suspension>\n#11     LspAnalysisServer.handleMessage.<anonymous closure> (package:analysis_server/src/lsp/lsp_analysis_server.dart:491:11)\n<asynchronous suspension>\n","type":1}}Content-Length: 93
Content-Type: application/vscode-jsonrpc; charset=utf-8

{"jsonrpc":"2.0","method":"$/progress","params":{"token":"ANALYZING","value":{"kind":"end"}}}
[16:27:06] [Analyzer] [Info] ==> Content-Length: 353
[16:27:06] [Analyzer] [Info] ==> {"jsonrpc":"2.0","id":40,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart"},"range":{"start":{"line":2,"character":34},"end":{"line":2,"character":34}},"context":{"diagnostics":[],"triggerKind":2}},"clientRequestTime":1738164426731}
[16:27:06] [Analyzer] [Info] <== Content-Length: 98
Content-Type: application/vscode-jsonrpc; charset=utf-8
[16:27:06] [Analyzer] [Info] <== {"id":14,"jsonrpc":"2.0","method":"window/workDoneProgress/create","params":{"token":"ANALYZING"}}
[16:27:06] [Analyzer] [Info] ==> Content-Length: 73
[16:27:06] [Analyzer] [Info] ==> {"jsonrpc":"2.0","id":14,"result":null,"clientRequestTime":1738164426734}
[16:27:06] [Analyzer] [Info] <== Content-Length: 118
Content-Type: application/vscode-jsonrpc; charset=utf-8
[16:27:06] [Analyzer] [Info] <== {"jsonrpc":"2.0","method":"$/progress","params":{"token":"ANALYZING","value":{"kind":"begin","title":"Analyzing…"}}}
[16:27:06] [Analyzer] [Info] <== Content-Length: 93
Content-Type: application/vscode-jsonrpc; charset=utf-8
[16:27:06] [Analyzer] [Info] <== {"jsonrpc":"2.0","method":"$/progress","params":{"token":"ANALYZING","value":{"kind":"end"}}}
[16:27:06] [Analyzer] [Info] <== Content-Length: 2096
Content-Type: application/vscode-jsonrpc; charset=utf-8
[16:27:06] [Analyzer] [Info] <== {"id":40,"jsonrpc":"2.0","result":[{"command":{"arguments":[{"path":"/Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart","autoTriggered":true}],"command":"dart.edit.sortMembers","title":"Sort Members"},"kind":"source.sortMembers","title":"Sort Members"},{"command":{"arguments":[{"path":"/Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart","autoTriggered":true}],"command":"dart.edit.organizeImports","title":"Organize Imports"},"kind":"source.organizeImports","title":"Organize Imports"},{"command":{"arguments":[{"path":"/Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart","autoTriggered":true}],"command":"dart.edit.fixAll","title":"Fix All"},"kind":"source.fixAll","title":"Fix All"},{"command":{"arguments":[{"action":"dart.assist.add.typeAnnotation"}],"command":"dart.logAction","title":"Log Action"},"diagnostics":[],"edit":{"documentChanges":[{"edits":[{"newText":"StateProvider<bool> ","range":{"end":{"character":6,"line":2},"start":{"character":6,"line":2}}}],"textDocument":{"uri":"file:///Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart","version":1}}]},"kind":"refactor.add.typeAnnotation","title":"Add type annotation"},{"command":{"arguments":[{"filePath":"/Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart","selectionOffset":92,"selectionLength":0,"arguments":["file:///Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart"]}],"command":"dart.refactor.move_top_level_to_file","title":"Move 'isExposureAnalysisToolActivatedProvider' to file"},"data":{"parameters":[{"actionLabel":"Move","defaultValue":"file:///Users/fractale/CommercialProjects/Lutme/lib/is_exposure_analysis_tool_activated_provider.dart","filters":{"Dart":["dart"]},"kind":"saveUri","parameterLabel":"Move to:","parameterTitle":"Select a file to move to"}]},"kind":"refactor.move","title":"Move 'isExposureAnalysisToolActivatedProvider' to file"}]}
Wed Jan 29 2025 [16:27:11 GMT+0100 (Central European Standard Time)] Log file ended

@FMorschel
Copy link
Contributor

Relevant error is:

An error occurred while handling workspace/executeCommand request: 
RangeError (length): Invalid value: Not in inclusive range 0..77: -1
#0      _Array.[] (dart:core-patch/array.dart)
#1      _FbGenericList.[] (package:analyzer/src/summary/flat_buffers.dart:742:22)
#2      Search.prefixesUsedInLibrary (package:analyzer/src/dart/analysis/search.dart:333:53)
<asynchronous suspension>
#3      SearchEngineImpl.searchPrefixesUsedInLibrary (package:analysis_server/src/services/search/search_engine_internal.dart:110:12)
<asynchronous suspension>
#4      MoveTopLevelToFile.compute (package:analysis_server/src/services/refactoring/move_top_level_to_file.dart:159:13)
<asynchronous suspension>
#5      RefactorCommandHandler.handle.<anonymous closure> (package:analysis_server/src/lsp/handlers/commands/refactor_command_handler.dart:81:20)
<asynchronous suspension>
#6      ErrorOr.mapResult (package:analysis_server/src/lsp/error_or.dart:94:11)
<asynchronous suspension>
#7      ServerStateMessageHandler.handleMessage (package:analysis_server/src/lsp/handlers/handlers.dart:452:11)
<asynchronous suspension>
#8      LspAnalysisServer._handleRequestMessage (package:analysis_server/src/lsp/lsp_analysis_server.dart:1068:18)
<asynchronous suspension>
#9      LspAnalysisServer.handleMessage.<anonymous closure>.<anonymous closure> (package:analysis_server/src/lsp/lsp_analysis_server.dart:509:15)
<asynchronous suspension>
#10     OperationPerformanceImpl.runAsync (package:analyzer/src/util/performance/operation_performance.dart:174:14)
<asynchronous suspension>
#11     LspAnalysisServer.handleMessage.<anonymous closure> (package:analysis_server/src/lsp/lsp_analysis_server.dart:491:11)
<asynchronous suspension>

I'll try following the stack trace here, if I find anything I'll let you know.

@FMorschel
Copy link
Contributor

I still could not repro your error on a test but I'll keep trying. Seems like the problem is inside _IndexRequest.findElementId at pkg\analyzer\lib\src\dart\analysis\search.dart.

There have been some changes to this file between stable and main so when I reproduce your error on a test, I'll see if this still happens on main. Unless you can test this or similar code (same error) on the Dart main/Flutter master channel for us to be sure it is still occurring. If I it doesn't happen anymore I'll see if I can still find what the error was and to add a test.

@DanTup
Copy link
Collaborator

DanTup commented Jan 29, 2025

I was able to repro - the problem was that I didn't have a reference to the element being removed. I was able to reduce it to this trivial example (which surprises me, because this seems basic enough that there should be tests covering it):

move_error.mp4

@FMorschel
Copy link
Contributor

What about MoveTopLevelToFileTest.test_single_variable? Why doesn't it repro this?

@DanTup
Copy link
Collaborator

DanTup commented Jan 29, 2025

What about MoveTopLevelToFileTest.test_single_variable? Why doesn't it repro this?

At a glance, it doesn't seem like there are any references to the variable being moved there (which is how I tried to repro it initially). My guess is that if there was another file that referenced variableToMove, it would.

@DanTup
Copy link
Collaborator

DanTup commented Jan 29, 2025

It repros with this:

  /// https://github.com/dart-lang/sdk/issues/59968#issuecomment-2622191812
  @soloTest
  Future<void> test_single_variable2() async {
    var originalSource = '''
class A {}


int variableT^oMove = 3;

class B {}
''';
    var declarationName = 'variableToMove';

    var expected = '''
>>>>>>>>>> lib/main.dart
class A {}

class B {}
>>>>>>>>>> lib/variable_to_move.dart created
int variableToMove = 3;
''';

    var otherFilePath = '$projectFolderPath/lib/other.dart';
    var otherFileContent = '''
import "main.dart";

void f() {
  print(variableToMove);
}
''';

    await _singleDeclaration(
      originalSource: originalSource,
      expected: expected,
      declarationName: declarationName,
      otherFilePath: otherFilePath,
      otherFileContent: otherFileContent,
    );
  }

However, I can't easily debug it right now because of #59992.

@DanTup DanTup self-assigned this Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-refactoring 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

4 participants