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

LSP initialization failure when using VS Code Live Share #52986

Closed
DanTup opened this issue Jul 19, 2023 · 7 comments
Closed

LSP initialization failure when using VS Code Live Share #52986

DanTup opened this issue Jul 19, 2023 · 7 comments
Labels
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

Comments

@DanTup
Copy link
Collaborator

DanTup commented Jul 19, 2023

While investigating #52952, I see this error.

I don't know if it's related to #52952 (I'm definitely not seeing high CPU), so filing as another issue.

Weirdly, it looks similar to the error I reported in dart-lang/glob#80 and I was testing that recently, but I can find no instances of globs like that in this project, so I think that might be a weird coincidence.

1689779340149:Ex:An error occurred while handling initialized notification
Bad state:: No element
#0      List.first (dart::core-patch/growable_array.dart::343::5)
#1      SequenceNode.canMatchAbsolute (package::glob/src/ast.dart::60::38)
#2      OptionsNode.canMatchAbsolute.<anonymous closure> (package::glob/src/ast.dart::371::59)
#3      ListBase.any (dart::collection/list.dart::114::15)
#4      OptionsNode.canMatchAbsolute (package::glob/src/ast.dart::371::40)
#5      SequenceNode.canMatchAbsolute (package::glob/src/ast.dart::60::44)
#6      Glob._patternCanMatchAbsolute (package::glob/glob.dart::70::46)
#7      Glob.matchAsPrefix (package::glob/glob.dart::162::9)
#8      Glob.matches (package::glob/glob.dart::154::32)
#9      LocatedGlob.matches (package::analyzer/src/dart/analysis/context_root.dart::183::19)
#10     ContextLocatorImpl._createContextRootsIn.isExcluded (package::analyzer/src/dart/analysis/context_locator.dart::348::21)
#11     ContextLocatorImpl._createContextRootsIn (package::analyzer/src/dart/analysis/context_locator.dart::374::23)
#12     ContextLocatorImpl._createContextRoots (package::analyzer/src/dart/analysis/context_locator.dart::322::5)
#13     ContextLocatorImpl._createContextRootsIn (package::analyzer/src/dart/analysis/context_locator.dart::375::13)
#14     ContextLocatorImpl._createContextRoots (package::analyzer/src/dart/analysis/context_locator.dart::322::5)
#15     ContextLocatorImpl._createContextRootsIn (package::analyzer/src/dart/analysis/context_locator.dart::375::13)
#16     ContextLocatorImpl._createContextRoots (package::analyzer/src/dart/analysis/context_locator.dart::322::5)
#17     ContextLocatorImpl._createContextRootsIn (package::analyzer/src/dart/analysis/context_locator.dart::375::13)
#18     ContextLocatorImpl.locateRoots (package::analyzer/src/dart/analysis/context_locator.dart::124::7)
#19     new AnalysisContextCollectionImpl (package::analyzer/src/dart/analysis/analysis_context_collection.dart::85::32)
#20     ContextManagerImpl._createAnalysisContexts.performContextRebuildGuarded.performContextRebuild (package::analysis_server/src/context_manager.dart::469::40)
<asynchronous suspension>
#21     ContextManagerImpl._createAnalysisContexts.performContextRebuildGuarded (package::analysis_server/src/context_manager.dart::613::11)
<asynchronous suspension>
#22     ContextManagerImpl.setRoots (package::analysis_server/src/context_manager.dart::299::5)
<asynchronous suspension>
#23     LspAnalysisServer._refreshAnalysisRoots (package::analysis_server/src/lsp/lsp_analysis_server.dart::1054::9)
<asynchronous suspension>
#24     LspAnalysisServer.updateWorkspaceFolders (package::analysis_server/src/lsp/lsp_analysis_server.dart::923::5)
<asynchronous suspension>
#25     InitializedMessageHandler.handle (package::analysis_server/src/lsp/handlers/handler_initialized.dart::36::7)
<asynchronous suspension>
#26     LspAnalysisServer._handleNotificationMessage (package::analysis_server/src/lsp/lsp_analysis_server.dart::979::20)
<asynchronous suspension>
#27     LspAnalysisServer.handleMessage.<anonymous closure>.<anonymous closure> (package::analysis_server/src/lsp/lsp_analysis_server.dart::456::15)
<asynchronous suspension>
#28     OperationPerformanceImpl.runAsync (package::analyzer/src/util/performance/operation_performance.dart::172::14)
<asynchronous suspension>
#29     LspAnalysisServer.handleMessage.<anonymous closure> (package::analysis_server/src/lsp/lsp_analysis_server.dart::437::11)
<asynchronous suspension>
@DanTup DanTup added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-server labels Jul 19, 2023
@bwilkerson
Copy link
Member

Can we determine which glob is causing the problem? There might be another bug in glob that needs to be reported.

Independently of that, it would be good if (a) this code was guarded by a try/catch so that invalid globs didn't crash the server (or alternatively that we identified invalid globs earlier and never passed them to this method) and (b) we could identify invalid globs as part of analyzing the analysis options file (where I'm guessing they come from) and report them to users via a diagnostic.

@DanTup
Copy link
Collaborator Author

DanTup commented Jul 19, 2023

Yeah, I'm trying to debug. What's weird is that VS Code blames the DCM extension (see bottom of screenshot) and I haven't been able to trigger it without DCM enabled.

image

However, it shows up in my instrumentation log file, so I don't see how it can possibly be related to DCM (and chatting with @incendial DCM doesn't have these files).

I'll update when I have a better idea of what is going on 🙃

@incendial
Copy link
Contributor

I believe there is a common bug (probably in the analyzer??) and both extensions throw it 😁

@bwilkerson
Copy link
Member

This stack trace looks very similar to the one given in #52986 (at least from the first stack frame from the glob package and up).

@incendial
Copy link
Contributor

They begin to differ at the analyzer layer and I have it forked, so it makes sense the stack is different there. At least it's my hypothesis.
176 for me:
Screenshot 2023-07-19 at 19 39 55
182 for you:

return glob.matches(relativePath);

@DanTup
Copy link
Collaborator Author

DanTup commented Jul 19, 2023

Ok, a few things I've figured out:

  • It's unrelated to DCM. The reason it didn't repro earlier was that the Dart extension wasn't being activated until I enabled DCM (but that was actually also prompting me to "trust" the workspace, which is what enabled the Dart extension to activate).

I'm not sure why DCM is picking up the error (and showing the notification - something I don't see when DCM is disabled), but it's being blamed because it's (apparently) showing the notification. I'll look into that more when I've fixed the other issues.

As for why we're seeing an error, I actually think this is the same as #52952 now. It appears to be analyzing my entire disk (and found the {**/,}foo.dart in a project I used to test dart-lang/glob#80!).

The reason it's doing this, is that in the Live Share window, this is being sent to the LSP server:

"workspaceFolders": [
			{
				"uri": "file:///",
				"name": "flutter_counter"
			}
		]

This appears to be telling the server that we have the root folder open (which I definitely do not). I'll do some digging in the Live Share repo to see if this has been discussed before, and if not might file an issue - I feel like that URI should be a vsls:/ scheme - which is what shows up in the workspace settings if I open them:

"folders":[
		{
			"name": "flutter_counter",
			"uri": "vsls:/"
		}
	],

@DanTup
Copy link
Collaborator Author

DanTup commented Jul 19, 2023

This is actually a Dart-Code issue. There's code in Dart-Code to normalize file casing (to work around some issues where VS Code continues to give us the original casing if a file is renamed by only case), and it doesn't handle non-file-URIs correctly (everything ends up as a file:/).

This is causing a translation of vsls:/ to file:/ which is causing this issue.

I've opened Dart-Code/Dart-Code#4652 and will get a fix to the pre-release extension channel soon.

@bwilkerson

Independently of that, it would be good if (a) this code was guarded by a try/catch so that invalid globs didn't crash the server (or alternatively that we identified invalid globs earlier and never passed them to this method) and (b) we could identify invalid globs as part of analyzing the analysis options file (where I'm guessing they come from) and report them to users via a diagnostic.

I've opened #52988 to track improving this. I think it was probably the intention that package:glob would never throw, but perhaps (given bugs can exist) it should be handled.

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. P2 A bug or feature request we're likely to work on
Projects
None yet
Development

No branches or pull requests

4 participants