@@ -8,8 +8,7 @@ import 'dart:io' as io;
88import 'dart:math' show max;
99
1010import 'package:analysis_server/protocol/protocol.dart' ;
11- import 'package:analysis_server/protocol/protocol_constants.dart'
12- show PROTOCOL_VERSION;
11+ import 'package:analysis_server/protocol/protocol_constants.dart' ;
1312import 'package:analysis_server/protocol/protocol_generated.dart'
1413 hide AnalysisOptions;
1514import 'package:analysis_server/src/analysis_server_abstract.dart' ;
@@ -20,14 +19,19 @@ import 'package:analysis_server/src/domain_analysis.dart';
2019import 'package:analysis_server/src/domain_analytics.dart' ;
2120import 'package:analysis_server/src/domain_completion.dart' ;
2221import 'package:analysis_server/src/domain_diagnostic.dart' ;
23- import 'package:analysis_server/src/domain_execution.dart' ;
2422import 'package:analysis_server/src/domain_kythe.dart' ;
2523import 'package:analysis_server/src/domain_server.dart' ;
2624import 'package:analysis_server/src/domains/analysis/occurrences.dart' ;
2725import 'package:analysis_server/src/domains/analysis/occurrences_dart.dart' ;
2826import 'package:analysis_server/src/edit/edit_domain.dart' ;
2927import 'package:analysis_server/src/flutter/flutter_domain.dart' ;
3028import 'package:analysis_server/src/flutter/flutter_notifications.dart' ;
29+ import 'package:analysis_server/src/handler/legacy/execution_create_context.dart' ;
30+ import 'package:analysis_server/src/handler/legacy/execution_delete_context.dart' ;
31+ import 'package:analysis_server/src/handler/legacy/execution_get_suggestions.dart' ;
32+ import 'package:analysis_server/src/handler/legacy/execution_map_uri.dart' ;
33+ import 'package:analysis_server/src/handler/legacy/execution_set_subscriptions.dart' ;
34+ import 'package:analysis_server/src/handler/legacy/legacy_handler.dart' ;
3135import 'package:analysis_server/src/operation/operation_analysis.dart' ;
3236import 'package:analysis_server/src/plugin/notification_manager.dart' ;
3337import 'package:analysis_server/src/protocol_server.dart' as server;
@@ -65,11 +69,30 @@ import 'package:telemetry/crash_reporting.dart';
6569import 'package:telemetry/telemetry.dart' as telemetry;
6670import 'package:watcher/watcher.dart' ;
6771
72+ /// A function that can be executed to create a handler for a request.
73+ typedef HandlerGenerator = LegacyHandler Function (
74+ AnalysisServer , Request , CancellationToken );
75+
6876typedef OptionUpdater = void Function (AnalysisOptionsImpl options);
6977
7078/// Instances of the class [AnalysisServer] implement a server that listens on a
7179/// [CommunicationChannel] for analysis requests and process them.
7280class AnalysisServer extends AbstractAnalysisServer {
81+ /// A map from the name of a request to a function used to create a request
82+ /// handler.
83+ static final Map <String , HandlerGenerator > handlerGenerators = {
84+ EXECUTION_REQUEST_CREATE_CONTEXT : (server, request, cancellationToken) =>
85+ ExecutionCreateContextHandler (server, request, cancellationToken),
86+ EXECUTION_REQUEST_DELETE_CONTEXT : (server, request, cancellationToken) =>
87+ ExecutionDeleteContextHandler (server, request, cancellationToken),
88+ EXECUTION_REQUEST_GET_SUGGESTIONS : (server, request, cancellationToken) =>
89+ ExecutionGetSuggestionsHandler (server, request, cancellationToken),
90+ EXECUTION_REQUEST_MAP_URI : (server, request, cancellationToken) =>
91+ ExecutionMapUriHandler (server, request, cancellationToken),
92+ EXECUTION_REQUEST_SET_SUBSCRIPTIONS : (server, request, cancellationToken) =>
93+ ExecutionSetSubscriptionsHandler (server, request, cancellationToken),
94+ };
95+
7396 /// The channel from which requests are received and to which responses should
7497 /// be sent.
7598 final ServerCommunicationChannel channel;
@@ -225,7 +248,6 @@ class AnalysisServer extends AbstractAnalysisServer {
225248 EditDomainHandler (this ),
226249 SearchDomainHandler (this ),
227250 CompletionDomainHandler (this ),
228- ExecutionDomainHandler (this , executionContext),
229251 DiagnosticDomainHandler (this ),
230252 AnalyticsDomainHandler (this ),
231253 KytheDomainHandler (this ),
@@ -295,33 +317,54 @@ class AnalysisServer extends AbstractAnalysisServer {
295317 runZonedGuarded (() {
296318 var cancellationToken = CancelableToken ();
297319 cancellationTokens[request.id] = cancellationToken;
298- var count = handlers.length ;
299- for ( var i = 0 ; i < count; i ++ ) {
320+ var generator = handlerGenerators[request.method] ;
321+ if (generator != null ) {
300322 try {
301- var response = handlers[i].handleRequest (request, cancellationToken);
302- if (response == Response .DELAYED_RESPONSE ) {
303- return ;
304- }
305- if (response != null ) {
306- sendResponse (response);
307- return ;
308- }
323+ var handler = generator (this , request, cancellationToken);
324+ handler.handle ();
309325 } on InconsistentAnalysisException {
310326 sendResponse (Response .contentModified (request));
311- return ;
312327 } on RequestFailure catch (exception) {
313328 sendResponse (exception.response);
314- return ;
315329 } catch (exception, stackTrace) {
316330 var error =
317331 RequestError (RequestErrorCode .SERVER_ERROR , exception.toString ());
318332 error.stackTrace = stackTrace.toString ();
319333 var response = Response (request.id, error: error);
320334 sendResponse (response);
321- return ;
322335 }
336+ } else {
337+ // TODO(brianwilkerson) When all the handlers are in [handlerGenerators]
338+ // remove local variable and for loop below.
339+ var count = handlers.length;
340+ for (var i = 0 ; i < count; i++ ) {
341+ try {
342+ var response =
343+ handlers[i].handleRequest (request, cancellationToken);
344+ if (response == Response .DELAYED_RESPONSE ) {
345+ return ;
346+ }
347+ if (response != null ) {
348+ sendResponse (response);
349+ return ;
350+ }
351+ } on InconsistentAnalysisException {
352+ sendResponse (Response .contentModified (request));
353+ return ;
354+ } on RequestFailure catch (exception) {
355+ sendResponse (exception.response);
356+ return ;
357+ } catch (exception, stackTrace) {
358+ var error = RequestError (
359+ RequestErrorCode .SERVER_ERROR , exception.toString ());
360+ error.stackTrace = stackTrace.toString ();
361+ var response = Response (request.id, error: error);
362+ sendResponse (response);
363+ return ;
364+ }
365+ }
366+ sendResponse (Response .unknownRequest (request));
323367 }
324- sendResponse (Response .unknownRequest (request));
325368 }, (exception, stackTrace) {
326369 instrumentationService.logException (
327370 FatalException (
0 commit comments