From da6dc03a15822d83d9180bd766c02d11aacdc06b Mon Sep 17 00:00:00 2001 From: asiva Date: Fri, 17 Jan 2025 10:58:12 -0800 Subject: [PATCH] [dartdev] switch the analysis server to use VMInteropHandler instead of spawning an isolate (higher memory footprint) Change-Id: I74bcb382c6269183beb4b8f2fcd04aee10eaa549 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/404921 Reviewed-by: Derek Xu Commit-Queue: Siva Annamalai --- .../lib/src/commands/language_server.dart | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/pkg/dartdev/lib/src/commands/language_server.dart b/pkg/dartdev/lib/src/commands/language_server.dart index 553732f36696..1e0ff3b08923 100644 --- a/pkg/dartdev/lib/src/commands/language_server.dart +++ b/pkg/dartdev/lib/src/commands/language_server.dart @@ -10,6 +10,7 @@ import 'package:args/args.dart'; import '../core.dart'; import '../sdk.dart'; import '../utils.dart'; +import '../vm_interop_handler.dart'; class LanguageServerCommand extends DartdevCommand { static const String commandName = 'language-server'; @@ -45,16 +46,22 @@ For more information about the server's capabilities and configuration, see: var args = argResults!.arguments; if (!args.any((arg) => arg.startsWith('--$protocol'))) { args = [...args, '--$protocol=$lsp']; - } else { - // Need to make a copy as argResults!.arguments is an - // UnmodifiableListView object which cannot be passed as - // the args for spawnUri. - args = [...args]; } - return await runFromSnapshot( - snapshot: sdk.analysisServerSnapshot, - args: args, - verbose: verbose, - ); + try { + VmInteropHandler.run( + sdk.analysisServerSnapshot, + args, + packageConfigOverride: null, + useExecProcess : false, + ); + return 0; + } catch (e, st) { + log.stderr('Error: launching language analysis server failed'); + log.stderr(e.toString()); + if (verbose) { + log.stderr(st.toString()); + } + return 255; + } } }