| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:collection'; | 6 import 'dart:collection'; |
| 7 import 'dart:core'; | 7 import 'dart:core'; |
| 8 import 'dart:io' as io; | 8 import 'dart:io' as io; |
| 9 import 'dart:math' show max; | 9 import 'dart:math' show max; |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 import 'package:analysis_server/src/domains/analysis/occurrences.dart'; | 24 import 'package:analysis_server/src/domains/analysis/occurrences.dart'; |
| 25 import 'package:analysis_server/src/domains/analysis/occurrences_dart.dart'; | 25 import 'package:analysis_server/src/domains/analysis/occurrences_dart.dart'; |
| 26 import 'package:analysis_server/src/operation/operation_analysis.dart'; | 26 import 'package:analysis_server/src/operation/operation_analysis.dart'; |
| 27 import 'package:analysis_server/src/plugin/notification_manager.dart'; | 27 import 'package:analysis_server/src/plugin/notification_manager.dart'; |
| 28 import 'package:analysis_server/src/plugin/plugin_manager.dart'; | 28 import 'package:analysis_server/src/plugin/plugin_manager.dart'; |
| 29 import 'package:analysis_server/src/plugin/plugin_watcher.dart'; | 29 import 'package:analysis_server/src/plugin/plugin_watcher.dart'; |
| 30 import 'package:analysis_server/src/plugin/server_plugin.dart'; | 30 import 'package:analysis_server/src/plugin/server_plugin.dart'; |
| 31 import 'package:analysis_server/src/protocol_server.dart' as server; | 31 import 'package:analysis_server/src/protocol_server.dart' as server; |
| 32 import 'package:analysis_server/src/server/diagnostic_server.dart'; | 32 import 'package:analysis_server/src/server/diagnostic_server.dart'; |
| 33 import 'package:analysis_server/src/services/correction/namespace.dart'; | 33 import 'package:analysis_server/src/services/correction/namespace.dart'; |
| 34 import 'package:analysis_server/src/services/index/index.dart'; | |
| 35 import 'package:analysis_server/src/services/search/search_engine.dart'; | 34 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| 36 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; | 35 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; |
| 37 import 'package:analysis_server/src/utilities/null_string_sink.dart'; | 36 import 'package:analysis_server/src/utilities/null_string_sink.dart'; |
| 38 import 'package:analyzer/context/context_root.dart'; | 37 import 'package:analyzer/context/context_root.dart'; |
| 39 import 'package:analyzer/dart/ast/ast.dart'; | 38 import 'package:analyzer/dart/ast/ast.dart'; |
| 40 import 'package:analyzer/dart/element/element.dart'; | 39 import 'package:analyzer/dart/element/element.dart'; |
| 41 import 'package:analyzer/exception/exception.dart'; | 40 import 'package:analyzer/exception/exception.dart'; |
| 42 import 'package:analyzer/file_system/file_system.dart'; | 41 import 'package:analyzer/file_system/file_system.dart'; |
| 43 import 'package:analyzer/file_system/physical_file_system.dart'; | 42 import 'package:analyzer/file_system/physical_file_system.dart'; |
| 44 import 'package:analyzer/instrumentation/instrumentation.dart'; | 43 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 * The object used to manage the execution of plugins. | 122 * The object used to manage the execution of plugins. |
| 124 */ | 123 */ |
| 125 PluginManager pluginManager; | 124 PluginManager pluginManager; |
| 126 | 125 |
| 127 /** | 126 /** |
| 128 * The [ResourceProvider] using which paths are converted into [Resource]s. | 127 * The [ResourceProvider] using which paths are converted into [Resource]s. |
| 129 */ | 128 */ |
| 130 final ResourceProvider resourceProvider; | 129 final ResourceProvider resourceProvider; |
| 131 | 130 |
| 132 /** | 131 /** |
| 133 * The [Index] for this server, may be `null` if indexing is disabled. | |
| 134 */ | |
| 135 final Index index; | |
| 136 | |
| 137 /** | |
| 138 * The [SearchEngine] for this server, may be `null` if indexing is disabled. | 132 * The [SearchEngine] for this server, may be `null` if indexing is disabled. |
| 139 */ | 133 */ |
| 140 SearchEngine searchEngine; | 134 SearchEngine searchEngine; |
| 141 | 135 |
| 142 /** | 136 /** |
| 143 * The plugin associated with this analysis server. | 137 * The plugin associated with this analysis server. |
| 144 */ | 138 */ |
| 145 final ServerPlugin serverPlugin; | 139 final ServerPlugin serverPlugin; |
| 146 | 140 |
| 147 /** | 141 /** |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 * | 331 * |
| 338 * If [rethrowExceptions] is true, then any exceptions thrown by analysis are | 332 * If [rethrowExceptions] is true, then any exceptions thrown by analysis are |
| 339 * propagated up the call stack. The default is true to allow analysis | 333 * propagated up the call stack. The default is true to allow analysis |
| 340 * exceptions to show up in unit tests, but it should be set to false when | 334 * exceptions to show up in unit tests, but it should be set to false when |
| 341 * running a full analysis server. | 335 * running a full analysis server. |
| 342 */ | 336 */ |
| 343 AnalysisServer( | 337 AnalysisServer( |
| 344 this.channel, | 338 this.channel, |
| 345 this.resourceProvider, | 339 this.resourceProvider, |
| 346 PubPackageMapProvider packageMapProvider, | 340 PubPackageMapProvider packageMapProvider, |
| 347 this.index, | |
| 348 this.serverPlugin, | 341 this.serverPlugin, |
| 349 this.options, | 342 this.options, |
| 350 this.sdkManager, | 343 this.sdkManager, |
| 351 this.instrumentationService, | 344 this.instrumentationService, |
| 352 {this.diagnosticServer, | 345 {this.diagnosticServer, |
| 353 ResolverProvider fileResolverProvider: null, | 346 ResolverProvider fileResolverProvider: null, |
| 354 ResolverProvider packageResolverProvider: null}) | 347 ResolverProvider packageResolverProvider: null}) |
| 355 : notificationManager = | 348 : notificationManager = |
| 356 new NotificationManager(channel, resourceProvider) { | 349 new NotificationManager(channel, resourceProvider) { |
| 357 _performance = performanceDuringStartup; | 350 _performance = performanceDuringStartup; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 _onFileAddedController = new StreamController.broadcast(); | 405 _onFileAddedController = new StreamController.broadcast(); |
| 413 // temporary plugin support: | 406 // temporary plugin support: |
| 414 _onFileChangedController = new StreamController.broadcast(); | 407 _onFileChangedController = new StreamController.broadcast(); |
| 415 running = true; | 408 running = true; |
| 416 onAnalysisStarted.first.then((_) { | 409 onAnalysisStarted.first.then((_) { |
| 417 onAnalysisComplete.then((_) { | 410 onAnalysisComplete.then((_) { |
| 418 performanceAfterStartup = new ServerPerformance(); | 411 performanceAfterStartup = new ServerPerformance(); |
| 419 _performance = performanceAfterStartup; | 412 _performance = performanceAfterStartup; |
| 420 }); | 413 }); |
| 421 }); | 414 }); |
| 422 _setupIndexInvalidation(); | |
| 423 searchEngine = new SearchEngineImpl(driverMap.values); | 415 searchEngine = new SearchEngineImpl(driverMap.values); |
| 424 Notification notification = new ServerConnectedParams(VERSION, io.pid, | 416 Notification notification = new ServerConnectedParams(VERSION, io.pid, |
| 425 sessionId: instrumentationService.sessionId) | 417 sessionId: instrumentationService.sessionId) |
| 426 .toNotification(); | 418 .toNotification(); |
| 427 channel.sendNotification(notification); | 419 channel.sendNotification(notification); |
| 428 channel.listen(handleRequest, onDone: done, onError: error); | 420 channel.listen(handleRequest, onDone: done, onError: error); |
| 429 handlers = serverPlugin.createDomains(this); | 421 handlers = serverPlugin.createDomains(this); |
| 430 } | 422 } |
| 431 | 423 |
| 432 /** | 424 /** |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 Duration get uptime { | 492 Duration get uptime { |
| 501 DateTime start = new DateTime.fromMillisecondsSinceEpoch( | 493 DateTime start = new DateTime.fromMillisecondsSinceEpoch( |
| 502 performanceDuringStartup.startTime); | 494 performanceDuringStartup.startTime); |
| 503 return new DateTime.now().difference(start); | 495 return new DateTime.now().difference(start); |
| 504 } | 496 } |
| 505 | 497 |
| 506 /** | 498 /** |
| 507 * The socket from which requests are being read has been closed. | 499 * The socket from which requests are being read has been closed. |
| 508 */ | 500 */ |
| 509 void done() { | 501 void done() { |
| 510 index?.stop(); | |
| 511 running = false; | 502 running = false; |
| 512 } | 503 } |
| 513 | 504 |
| 514 /** | 505 /** |
| 515 * There was an error related to the socket from which requests are being | 506 * There was an error related to the socket from which requests are being |
| 516 * read. | 507 * read. |
| 517 */ | 508 */ |
| 518 void error(argument) { | 509 void error(argument) { |
| 519 running = false; | 510 running = false; |
| 520 } | 511 } |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 /** | 891 /** |
| 901 * Returns `true` if errors should be reported for [file] with the given | 892 * Returns `true` if errors should be reported for [file] with the given |
| 902 * absolute path. | 893 * absolute path. |
| 903 */ | 894 */ |
| 904 bool shouldSendErrorsNotificationFor(String file) { | 895 bool shouldSendErrorsNotificationFor(String file) { |
| 905 return contextManager.isInAnalysisRoot(file); | 896 return contextManager.isInAnalysisRoot(file); |
| 906 } | 897 } |
| 907 | 898 |
| 908 void shutdown() { | 899 void shutdown() { |
| 909 running = false; | 900 running = false; |
| 910 if (index != null) { | |
| 911 index.stop(); | |
| 912 } | |
| 913 // Defer closing the channel and shutting down the instrumentation server so | 901 // Defer closing the channel and shutting down the instrumentation server so |
| 914 // that the shutdown response can be sent and logged. | 902 // that the shutdown response can be sent and logged. |
| 915 new Future(() { | 903 new Future(() { |
| 916 instrumentationService.shutdown(); | 904 instrumentationService.shutdown(); |
| 917 channel.close(); | 905 channel.close(); |
| 918 }); | 906 }); |
| 919 } | 907 } |
| 920 | 908 |
| 921 /** | 909 /** |
| 922 * Implementation for `analysis.updateContent`. | 910 * Implementation for `analysis.updateContent`. |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1038 bool _hasAnalysisServiceSubscription(AnalysisService service, String file) { | 1026 bool _hasAnalysisServiceSubscription(AnalysisService service, String file) { |
| 1039 return analysisServices[service]?.contains(file) ?? false; | 1027 return analysisServices[service]?.contains(file) ?? false; |
| 1040 } | 1028 } |
| 1041 | 1029 |
| 1042 _scheduleAnalysisImplementedNotification() async { | 1030 _scheduleAnalysisImplementedNotification() async { |
| 1043 Set<String> files = analysisServices[AnalysisService.IMPLEMENTED]; | 1031 Set<String> files = analysisServices[AnalysisService.IMPLEMENTED]; |
| 1044 if (files != null) { | 1032 if (files != null) { |
| 1045 scheduleImplementedNotification(this, files); | 1033 scheduleImplementedNotification(this, files); |
| 1046 } | 1034 } |
| 1047 } | 1035 } |
| 1048 | |
| 1049 /** | |
| 1050 * Listen for context events and invalidate index. | |
| 1051 * | |
| 1052 * It is possible that this method will do more in the future, e.g. listening | |
| 1053 * for summary information and linking pre-indexed packages into the index, | |
| 1054 * but for now we only invalidate project specific index information. | |
| 1055 */ | |
| 1056 void _setupIndexInvalidation() { | |
| 1057 if (index == null) { | |
| 1058 return; | |
| 1059 } | |
| 1060 // TODO(brianwilkerson) onContextsChanged never has anything written to it. | |
| 1061 // Figure out whether we need something like this under the new analysis | |
| 1062 // driver, and remove this method if not. | |
| 1063 // onContextsChanged.listen((ContextsChangedEvent event) { | |
| 1064 // for (AnalysisContext context in event.added) { | |
| 1065 // context | |
| 1066 // .onResultChanged(RESOLVED_UNIT3) | |
| 1067 // .listen((ResultChangedEvent event) { | |
| 1068 // if (event.wasComputed) { | |
| 1069 // Object value = event.value; | |
| 1070 // if (value is CompilationUnit) { | |
| 1071 // index.indexDeclarations(value); | |
| 1072 // } | |
| 1073 // } | |
| 1074 // }); | |
| 1075 // context | |
| 1076 // .onResultChanged(RESOLVED_UNIT) | |
| 1077 // .listen((ResultChangedEvent event) { | |
| 1078 // if (event.wasInvalidated) { | |
| 1079 // LibrarySpecificUnit target = event.target; | |
| 1080 // index.removeUnit(event.context, target.library, target.unit); | |
| 1081 // } | |
| 1082 // }); | |
| 1083 // } | |
| 1084 // for (AnalysisContext context in event.removed) { | |
| 1085 // index.removeContext(context); | |
| 1086 // } | |
| 1087 // }); | |
| 1088 } | |
| 1089 } | 1036 } |
| 1090 | 1037 |
| 1091 class AnalysisServerOptions { | 1038 class AnalysisServerOptions { |
| 1092 bool enableIncrementalResolutionApi = false; | 1039 bool enableIncrementalResolutionApi = false; |
| 1093 bool enableIncrementalResolutionValidation = false; | 1040 bool enableIncrementalResolutionValidation = false; |
| 1094 bool useAnalysisHighlight2 = false; | 1041 bool useAnalysisHighlight2 = false; |
| 1095 String fileReadMode = 'as-is'; | 1042 String fileReadMode = 'as-is'; |
| 1096 String newAnalysisDriverLog; | 1043 String newAnalysisDriverLog; |
| 1097 | 1044 |
| 1098 String clientId; | 1045 String clientId; |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1512 /** | 1459 /** |
| 1513 * The [PerformanceTag] for time spent in server request handlers. | 1460 * The [PerformanceTag] for time spent in server request handlers. |
| 1514 */ | 1461 */ |
| 1515 static PerformanceTag serverRequests = server.createChild('requests'); | 1462 static PerformanceTag serverRequests = server.createChild('requests'); |
| 1516 | 1463 |
| 1517 /** | 1464 /** |
| 1518 * The [PerformanceTag] for time spent in split store microtasks. | 1465 * The [PerformanceTag] for time spent in split store microtasks. |
| 1519 */ | 1466 */ |
| 1520 static PerformanceTag splitStore = new PerformanceTag('splitStore'); | 1467 static PerformanceTag splitStore = new PerformanceTag('splitStore'); |
| 1521 } | 1468 } |
| OLD | NEW |