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

"show all symbols" in VSCode has become unreliable #57035

Closed
stereotype441 opened this issue Nov 5, 2024 · 13 comments
Closed

"show all symbols" in VSCode has become unreliable #57035

stereotype441 opened this issue Nov 5, 2024 · 13 comments
Assignees
Labels
analyzer-server area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@stereotype441
Copy link
Member

I recently rebuilt my analysis server. Previously I was running the version from 1e624b8; now I'm running the version from c549a73.

I'm noticing that the "show all symbols" command in VSCode no longer reliably shows me results. If I search for a class that I'm certain exists, about half the time I simply see "no matching workspace symbols".

I don't have repro steps, but here's an interesting clue: I just checked out a branch in which I know I have a method somewhere whose name starts with solo_. I triggered "show all symbols" and typed solo_, and as I was typing, I briefly saw the method I was looking for. But when I typed the final _, the result disappeared. Then I hit backspace to discard the final _, and the result appeared again.

@stereotype441 stereotype441 added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-server labels Nov 5, 2024
@bwilkerson
Copy link
Member

@scheglov @DanTup

@DanTup
Copy link
Collaborator

DanTup commented Nov 6, 2024

Yeah, there's definitely something weird gong on here... When I type "danny", I see "danny_foo" up until typing the "y", then it also disappears:

search.mp4

I'll take a look.

@DanTup DanTup self-assigned this Nov 6, 2024
@DanTup DanTup added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Nov 6, 2024
@DanTup
Copy link
Collaborator

DanTup commented Nov 6, 2024

Looks like the request is failing with an error:

[10:41:28 AM] [Analyzer] [Info] ==> {"jsonrpc":"2.0","id":8,"method":"workspace/symbol","params":{"query":"danny"},"clientRequestTime":1730889688702}
[10:41:28 AM] [Analyzer] [Info] <== {"id":8,"jsonrpc":"2.0","error":{"code":-32001,"message":"An error occurred while handling workspace/symbol request"}}
[10:41:28 AM] [Analyzer] [Info] <== {
	"jsonrpc": "2.0",
	"method": "window/logMessage",
	"params": {
		"message": "
An error occurred while handling workspace/symbol request:
	Bad state: Expected existing element: root::dart:async::@fragment::dart:async/stream_controller.dart::@class::_AsyncStreamController::@constructor::new
#0      LinkedElementFactory.elementOfReference (package:analyzer/src/summary2/linked_element_factory.dart:225:7)
#1      ResolutionReader._readRawElement (package:analyzer/src/summary2/bundle_reader.dart:2460:28)
#2      ResolutionReader.readElement (package:analyzer/src/summary2/bundle_reader.dart:1966:19)
#3      SummaryDataReader.readTypedListCast.<anonymous closure> (package:analyzer/src/summary2/data_reader.dart:154:18)
#4      new _List.generate (dart:core-patch/array.dart:113:28)
#5      SummaryDataReader.readTypedListCast (package:analyzer/src/summary2/data_reader.dart:153:12)
#6      ResolutionReader.readElementList (package:analyzer/src/summary2/bundle_reader.dart:2030:20)
#7      ClassElementLinkedData._read (package:analyzer/src/summary2/bundle_reader.dart:148:39)
#8      ElementLinkedData.read (package:analyzer/src/summary2/bundle_reader.dart:269:5)
#9      InterfaceElementImpl.supertype (package:analyzer/src/dart/element/element.dart:5790:17)
#10     ClassElementImpl._buildMixinAppConstructors (package:analyzer/src/dart/element/element.dart:1091:21)
#11     InterfaceElementImpl.constructors (package:analyzer/src/dart/element/element.dart:5717:5)
#12     _FindCompilationUnitDeclarations._addClasses (package:analyzer/src/dart/analysis/search.dart:1087:32)
#13     _FindCompilationUnitDeclarations.compute (package:analyzer/src/dart/analysis/search.dart:1063:5)
#14     _FindDeclarations.compute.<anonymous closure> (package:analyzer/src/dart/analysis/search.dart:1284:22)
#15     OperationPerformanceImpl.run (package:analyzer/src/util/performance/operation_performance.dart:155:23)
#16     _FindDeclarations.compute (package:analyzer/src/dart/analysis/search.dart:1275:25)
<asynchronous suspension>
#17     FindDeclarations.compute.<anonymous closure> (package:analyzer/src/dart/analysis/search.dart:185:7)
<asynchronous suspension>
#18     OperationPerformanceImpl.runAsync (package:analyzer/src/util/performance/operation_performance.dart:174:14)
<asynchronous suspension>
#19     FindDeclarations.compute (package:analyzer/src/dart/analysis/search.dart:184:5)
<asynchronous suspension>
#20     WorkspaceSymbolHandler.handle.<anonymous closure> (package:analysis_server/src/lsp/handlers/handler_workspace_symbols.dart:60:9)
<asynchronous suspension>
#21     OperationPerformanceImpl.runAsync (package:analyzer/src/util/performance/operation_performance.dart:174:14)
<asynchronous suspension>
#22     WorkspaceSymbolHandler.handle (package:analysis_server/src/lsp/handlers/handler_workspace_symbols.dart:56:5)
<asynchronous suspension>
#23     ServerStateMessageHandler.handleMessage (package:analysis_server/src/lsp/handlers/handlers.dart:446:11)
<asynchronous suspension>
#24     LspAnalysisServer._handleRequestMessage (package:analysis_server/src/lsp/lsp_analysis_server.dart:1080:18)
<asynchronous suspension>
#25     LspAnalysisServer.handleMessage.<anonymous closure>.<anonymous closure> (package:analysis_server/src/lsp/lsp_analysis_server.dart:509:15)
<asynchronous suspension>
#26     OperationPerformanceImpl.runAsync (package:analyzer/src/util/performance/operation_performance.dart:174:14)
<asynchronous suspension>
#27     LspAnalysisServer.handleMessage.<anonymous closure> (package:analysis_server/src/lsp/lsp_analysis_server.dart:491:11)
<asynchronous suspension>
",
		"type": 1
	}
}

@scheglov I'm not familiar with this error - any ideas? It does seem to work sometimes.. I triggered this while initial analysis was still happening but I don't know if that's related.

@FMorschel
Copy link
Contributor

Coincidentally or not, both of your examples stopped working after the fifth character. Just to point this out. I'll see if I can find some other pattern as well.

@FMorschel
Copy link
Contributor

I could not repro the same response of 5 characters within a test file for the SDK. But I have a theory that when the list gets to a length lower than some number (not sure if it is simply smaller than the shown amount on screen or what) of elements, that happens. Seems that whenever I get to a point where multiple elements would vanish at once, this behaviour shows itself.

@FMorschel
Copy link
Contributor

Also, when testing the above I got an error as well. Here are the specific error and the full log (it is from the SDK so I have no sensitive data):

{"id":16,"jsonrpc":"2.0","method":"window/workDoneProgress/create","params":{"token":"ANALYZING"}}
[12:45:43] [Analyzer] [Info] ==> Content-Length: 73
[12:45:43] [Analyzer] [Info] ==> {"jsonrpc":"2.0","id":16,"result":null,"clientRequestTime":1730907943840}
[12:45:43] [Analyzer] [Info] <== Content-Length: 118
Content-Type: application/vscode-jsonrpc; charset=utf-8
[12:45:43] [Analyzer] [Info] <== {"jsonrpc":"2.0","method":"$/progress","params":{"token":"ANALYZING","value":{"kind":"begin","title":"Analyzing…"}}}
[12:45:44] [Analyzer] [Error] [Bad state: Expected existing element: root::dart:_internal::@fragment::dart:_internal/list.dart::@class::UnmodifiableListBase::@constructor::new
#0      LinkedElementFactory.elementOfReference (package:analyzer/src/summary2/linked_element_factory.dart:225:7)
#1      ResolutionReader._readRawElement (package:analyzer/src/summary2/bundle_reader.dart:2464:28)
#2      ResolutionReader.readElement (package:analyzer/src/summary2/bundle_reader.dart:1970:19)
#3      ConstructorElementLinkedData._read (package:analyzer/src/summary2/bundle_reader.dart:231:39)
#4      ElementLinkedData.read (package:analyzer/src/summary2/bundle_reader.dart:269:5)
#5      ExecutableElementImpl.parameters (package:analyzer/src/dart/element/element.dart:3583:17)
#6      ExecutableMember.parameters (package:analyzer/src/dart/element/member.dart:280:24)
#7      ElementResolver._resolveArgumentsToFunction (package:analyzer/src/generated/element_resolver.dart:453:37)
#8      ElementResolver.visitInstanceCreationExpression (package:analyzer/src/generated/element_resolver.dart:248:9)
#9      InstanceCreationExpressionResolver._resolveInstanceCreationExpression (package:analyzer/src/dart/resolver/instance_creation_expression_resolver.dart:59:31)
#10     InstanceCreationExpressionResolver.resolve (package:analyzer/src/dart/resolver/instance_creation_expression_resolver.dart:49:5)
#11     ResolverVisitor.visitInstanceCreationExpression (package:analyzer/src/generated/resolver.dart:3061:41)
#12     InstanceCreationExpressionImpl.resolveExpression (package:analyzer/src/dart/ast/ast.dart:10410:14)
#13     ResolverVisitor.dispatchExpression (package:analyzer/src/generated/resolver.dart:763:16)
#14     TypeAnalyzer.analyzeExpression (package:_fe_analyzer_shared/src/type_inference/type_analyzer.dart:564:9)
#15     ResolverVisitor.visitConstructorFieldInitializer (package:analyzer/src/generated/resolver.dart:2371:5)
#16     ConstructorFieldInitializerImpl.accept (package:analyzer/src/dart/ast/ast.dart:4390:15)

analyzer.txt

@scheglov scheglov assigned scheglov and unassigned DanTup Nov 6, 2024
@scheglov scheglov added the P2 A bug or feature request we're likely to work on label Nov 6, 2024
@scheglov
Copy link
Contributor

scheglov commented Nov 6, 2024

In all cases these are synthetic constructors of class type aliases like

abstract class UnmodifiableListBase<E> = ListBase<E>
    with UnmodifiableListMixin<E>;

I believe I broke it with recent changes.
I will try to reproduce as a unit test and fix.

@scheglov
Copy link
Contributor

scheglov commented Nov 6, 2024

Hm... Cannot reproduce so far.

  solo_test_classAlias_constructors_afterReading() async {
    newFile('$testPackageLibPath/a.dart', r'''
part of 'test.dart';
class X = A with M;
''');

    var library = await buildLibrary('''
part 'a.dart';
class A {}
mixin M {}
''');

    _elementOfLibrary(
      library,
      ['@fragment', 'package:test/a.dart','@class', 'X', '@constructor', 'new'],
    );
  }

@scheglov scheglov added P1 A high priority bug; for example, a single project is unusable or has many test failures and removed P2 A bug or feature request we're likely to work on labels Nov 6, 2024
@scheglov
Copy link
Contributor

scheglov commented Nov 6, 2024

OK, I can reproduce it.
The reproduction steps are actually easier than I tried to use initially.

  solo_test_classAlias_constructors_afterReading() async {
    var library = await buildLibrary('''
abstract mixin class A {}
mixin M {}
class X = A with M;
''');

    var X = _elementOfLibrary(
      library,
      ['@fragment', 'package:test/test.dart','@class', 'X'],
    ) as ClassElementImpl;
    X.constructors;
  }

@DanTup
Copy link
Collaborator

DanTup commented Nov 6, 2024

Ah, great! I only had a manual repro and hadn't yet figured out what was going on.

I had synced SDK at 9645a71 and added void danny_foo() {} to the top of lsp_analysis_server.dart, then when searching for danny it would intermittently(?) fail with that error. I'm not sure why it isn't consistent - perhaps as I type more characters the filter means it's looking through more elements and hitting one that triggers the issue?

@FMorschel
Copy link
Contributor

In my empty project for understanding bugs, I can repro this with nothing similar to the above:

20241106_160432.mp4

I don't think this is all there is to it but maybe Dan is right and something else got triggered by the more characters I wrote but that is not what I would expect.

@DanTup
Copy link
Collaborator

DanTup commented Nov 6, 2024

We search the SDK and packages too, so it's possible something in there is triggering this. The _FindDeclarations implementation exits early when it his maxResults, so it's possible that with your first few characters you don't hit any of the elements that trigger this, then as you type more characters and it has to search further, it does.

@scheglov
Copy link
Contributor

scheglov commented Nov 6, 2024

https://dart-review.googlesource.com/c/sdk/+/393960

The issue was that during _buildMixinAppConstructors:

  1. We first set no-constructors to prevent infinite recursion
  2. Then ask for supertype, this starts reading linked data.
  3. When reading ClassElementLinkedData, we read "merged" constructors using References.
  4. So, we again call constructors that sees that there was no-constructors empty list already set, so it does nothing.
  5. So, ClassElementLinkedData cannot find the element for the reference, and throws.

The solution is to read supertype first, and only then shortcut the potential infinite recursion.

copybara-service bot pushed a commit that referenced this issue Nov 6, 2024
Bug: #57035
Change-Id: I48aa20815b56c49f08e22509126f74891e694644
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393960
Commit-Queue: Konstantin Shcheglov <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
@scheglov scheglov closed this as completed Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-server area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

5 participants