Skip to content

Message: An error occurred while handling textDocument/references request Code: -32001 #60005

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

Closed
leaf-node opened this issue Jan 28, 2025 · 14 comments
Labels
area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. 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

@leaf-node
Copy link

In VSCodium version 1.96.4.25026-el9 and VSCodium Insiders version 1.97.0.25026-el9 on OpenSUSE Tumbleweed, with Dart 3.6.1 installed by Flutter 3.27.3, I am no longer able to find references to Dart code that exists in other files. The LSP log in VSCodium shows the following after trying to search for a variable reference:

[Error - 6:16:14 PM] Request textDocument/references failed.
  Message: An error occurred while handling textDocument/references request
  Code: -32001 
[Error - 6:16:14 PM] An error occurred while handling textDocument/references request: Null check operator used on a null value
#0      Search._searchReferences_Local (package:analyzer/src/dart/analysis/search.dart:761:33)
#1      Search._searchReferences_Parameter (package:analyzer/src/dart/analysis/search.dart:801:26)
#2      Search.references (package:analyzer/src/dart/analysis/search.dart:386:14)
#3      SearchEngineImpl.searchReferences (package:analysis_server/src/services/search/search_engine_internal.dart:119:41)
#4      ElementReferencesComputer._findSingleElementReferences (package:analysis_server/src/search/element_references.dart:61:25)
#5      ElementReferencesComputer._findElementsReferences.<anonymous closure> (package:analysis_server/src/search/element_references.dart:52:18)
#6      OperationPerformanceImpl.runAsync (package:analyzer/src/util/performance/operation_performance.dart:174:29)
#7      ElementReferencesComputer._findElementsReferences (package:analysis_server/src/search/element_references.dart:50:46)
<asynchronous suspension>
#8      OperationPerformanceImpl.runAsync (package:analyzer/src/util/performance/operation_performance.dart:174:14)
<asynchronous suspension>
#9      ElementReferencesComputer.compute (package:analysis_server/src/search/element_references.dart:25:20)
<asynchronous suspension>
#10     OperationPerformanceImpl.runAsync (package:analyzer/src/util/performance/operation_performance.dart:174:14)
<asynchronous suspension>
#11     ReferencesHandler._getReferences (package:analysis_server/src/lsp/handlers/handler_references.dart:84:19)
<asynchronous suspension>
#12     ErrorOrRecord2Extension.mapResults (package:analysis_server/src/lsp/error_or.dart:125:12)
<asynchronous suspension>
#13     OperationPerformanceImpl.runAsync (package:analyzer/src/util/performance/operation_performance.dart:174:14)
<asynchronous suspension>
#14     ReferencesHandler.handle (package:analysis_server/src/lsp/handlers/handler_references.dart:42:12)
<asynchronous suspension>
#15     ServerStateMessageHandler.handleMessage (package:analysis_server/src/lsp/handlers/handlers.dart:452:11)
<asynchronous suspension>
#16     LspAnalysisServer._handleRequestMessage (package:analysis_server/src/lsp/lsp_analysis_server.dart:1068:18)
<asynchronous suspension>
#17     LspAnalysisServer.handleMessage.<anonymous closure>.<anonymous closure> (package:analysis_server/src/lsp/lsp_analysis_server.dart:509:15)
<asynchronous suspension>
#18     OperationPerformanceImpl.runAsync (package:analyzer/src/util/performance/operation_performance.dart:174:14)
<asynchronous suspension>
#19     LspAnalysisServer.handleMessage.<anonymous closure> (package:analysis_server/src/lsp/lsp_analysis_server.dart:491:11)
<asynchronous suspension>

I see that the LSP is running in my process list:

andrew      5234  1.5  0.7 1580044 511784 ?      Sl   17:26   0:06 /home/andrew/.local/lib/flutter/bin/cache/dart-sdk/bin/dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.102.0

In the helix editor, version 25.1 (dabfb6ce), I see the following when I try to lookup a reference that exists outside of the file currently in view:

protocol error: ServerError(-32001): An error occurred while handling textDocument/references request

As an example, this error occurs when finding references (by right clicking) for allowClickAccept in the following project, file and line number: https://github.com/okcode-studio/open_alert_viewer/blob/main/lib/ui/settings/cubit/account_settings_cubit.dart#L157, but I'm seeing this in other files and for other references too.

I have tried clearing my ~/.dart*, ~/.pub-cache, ~/.cache and ran git clean -fxd in my Flutter checkout, but the problem persists.

This issue started probably within the last few hours or so, even before updating VSCodium from 1.95 to the most recent version, 1.96. Testing VSCodium Insiders did not resolve the issue either.

@leaf-node leaf-node added the legacy-area-analyzer Use area-devexp instead. label Jan 28, 2025
@pq pq added devexp-server Issues related to some aspect of the analysis server P2 A bug or feature request we're likely to work on labels Jan 28, 2025
@pq
Copy link
Member

pq commented Jan 28, 2025

@DanTup @scheglov

@leaf-node
Copy link
Author

I'm also seeing this on Flutter 3.29.0-0.2.pre, with Dart SDK version: 3.7.0-323.1.beta, from the Flutter beta channel.

@DanTup
Copy link
Collaborator

DanTup commented Jan 29, 2025

I don't suppose either of you have a code sample that triggers this?

@scheglov the exception is occurring on the assertion that source is not-null here:

https://github.com/dart-lang/sdk/blob/3.6.1/pkg/analyzer/lib/src/dart/analysis/search.dart#L761

It's not clear to me in what situations source would be null though (the docs are on AnalysisTarget and only say "null if this target is not associated with a source").

@leaf-node
Copy link
Author

I don't suppose either of you have a code sample that triggers this?

I have a part of my repo that runs into this problem (right click on allowClickAccept and search for references):

https://github.com/okcode-studio/open_alert_viewer/blob/main/lib/ui/settings/cubit/account_settings_cubit.dart#L157

I suppose there could be a security risk in running the LSP on untrusted code, but is there a way to test it in a Docker container, or in a VM?

@leaf-node
Copy link
Author

@DanTup I made a simple demo with the freezed and bloc libraries, and was able to reproduce the error:

leaf-node/dart_lsp_test@4598d2c

If you right-click on foo in:

https://github.com/leaf-node/dart_lsp_test/blob/main/lib/foo_cubit.dart#L5

The error is reproduced.

@DanTup
Copy link
Collaborator

DanTup commented Jan 29, 2025

@leaf-node thanks! Although I don't seem able to reproduce it. I checked out that commit from your repository and I can fetch references fine (I'm using Flutter stable 3.27.3 which I think matches you):

references.mp4

Does it repro for you in a clean clone of that repository? If not, could you try copying your pubspec.lock file into the clean clone and flutter pub get to see if that then causes the issue (in case it's triggered by something in specific dependency version and I've solved to different versions).

@leaf-node
Copy link
Author

@leaf-node thanks! Although I don't seem able to reproduce it. I checked out that commit from your repository and I can fetch references fine (I'm using Flutter stable 3.27.3 which I think matches you):

@DanTup Oops, it looks like I gave you the wrong line to test. If you right click on foo on line 12, and select "Find All References" rather than just showing definitions, the bug should reproduce:

https://github.com/leaf-node/dart_lsp_test/blob/8149548e773f0d73ee771fedec279430e4997050/lib/foo_cubit.dart#L12

@leaf-node
Copy link
Author

Oh, I should also mention that if you view the "Output" tab in VSCodium, you can select from the drop-down on the right to show "LSP" logs once an error occurs.

@DanTup
Copy link
Collaborator

DanTup commented Jan 29, 2025

@leaf-node thanks, I can repro now. I tried but failed to reduce the example to something smaller by removing some of the additional layers. I'll wait for @scheglov's input, as he might have a better idea of why this element might not have a source (I wonder if it's related to the callable classes - though I retained them as I tried to reduce the code, but the issue stopped occurring).

@scheglov
Copy link
Contributor

We probably don't have a source because the formal parameter element is synthetic.

@bwilkerson
Copy link
Member

We need to fix the case where the exception is being thrown, and we need to do so in a way that allows us to find all of the references to a parameter, even when the formal parameter element is synthetic. Those might have to be done in two steps, depending on how long it will take to fix the exception.

@bwilkerson bwilkerson added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. and removed legacy-area-analyzer Use area-devexp instead. devexp-server Issues related to some aspect of the analysis server labels Feb 21, 2025
@leaf-node
Copy link
Author

Thanks for looking into this. I should note that the LSP server continues to work for other queries before and after this error, so just this specific type of query is not working. 🙂

@DanTup
Copy link
Collaborator

DanTup commented Feb 24, 2025

https://dart-review.googlesource.com/c/sdk/+/411600 will fix the crash, though still leaves navigation through these parameters not working (no results will be returned).

I'm not sure about the best way to fix this though (my feeling was that nonSynthetic should work for these parameters but based on comments at https://dart-review.googlesource.com/c/sdk/+/406840 I'm not sure it's that simple, so may require some more input).

@johnniwinther
Copy link
Member

Issue for the underlying problem: #60200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. 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

6 participants