| 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 library analysis.server; | 5 library analysis.server; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analysis_server/src/analysis_logger.dart'; | 10 import 'package:analysis_server/src/analysis_logger.dart'; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 * [CommunicationChannel] for analysis requests and process them. | 62 * [CommunicationChannel] for analysis requests and process them. |
| 63 */ | 63 */ |
| 64 class AnalysisServer { | 64 class AnalysisServer { |
| 65 /** | 65 /** |
| 66 * The version of the analysis server. The value should be replaced | 66 * The version of the analysis server. The value should be replaced |
| 67 * automatically during the build. | 67 * automatically during the build. |
| 68 */ | 68 */ |
| 69 static final String VERSION = '0.0.1'; | 69 static final String VERSION = '0.0.1'; |
| 70 | 70 |
| 71 /** | 71 /** |
| 72 * The number of milliseconds to perform operations before inserting |
| 73 * a 1 millisecond delay so that the VM and dart:io can deliver content |
| 74 * to stdin. This should be removed once the underlying problem is fixed. |
| 75 */ |
| 76 static int performOperationDelayFreqency = 25; |
| 77 |
| 78 /** |
| 72 * The channel from which requests are received and to which responses should | 79 * The channel from which requests are received and to which responses should |
| 73 * be sent. | 80 * be sent. |
| 74 */ | 81 */ |
| 75 final ServerCommunicationChannel channel; | 82 final ServerCommunicationChannel channel; |
| 76 | 83 |
| 77 /** | 84 /** |
| 78 * The [ResourceProvider] using which paths are converted into [Resource]s. | 85 * The [ResourceProvider] using which paths are converted into [Resource]s. |
| 79 */ | 86 */ |
| 80 final ResourceProvider resourceProvider; | 87 final ResourceProvider resourceProvider; |
| 81 | 88 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 */ | 191 */ |
| 185 StreamController<PriorityChangeEvent> _onPriorityChangeController; | 192 StreamController<PriorityChangeEvent> _onPriorityChangeController; |
| 186 | 193 |
| 187 /** | 194 /** |
| 188 * True if any exceptions thrown by analysis should be propagated up the call | 195 * True if any exceptions thrown by analysis should be propagated up the call |
| 189 * stack. | 196 * stack. |
| 190 */ | 197 */ |
| 191 bool rethrowExceptions; | 198 bool rethrowExceptions; |
| 192 | 199 |
| 193 /** | 200 /** |
| 201 * The next time (milliseconds since epoch) after which the analysis server |
| 202 * should pause so that pending requests can be fetched by the system. |
| 203 */ |
| 204 // Add 1 sec to prevent delay from impacting short running tests |
| 205 int _nextPerformOperationDelayTime = |
| 206 new DateTime.now().millisecondsSinceEpoch + |
| 207 1000; |
| 208 |
| 209 /** |
| 194 * Initialize a newly created server to receive requests from and send | 210 * Initialize a newly created server to receive requests from and send |
| 195 * responses to the given [channel]. | 211 * responses to the given [channel]. |
| 196 * | 212 * |
| 197 * If [rethrowExceptions] is true, then any exceptions thrown by analysis are | 213 * If [rethrowExceptions] is true, then any exceptions thrown by analysis are |
| 198 * propagated up the call stack. The default is true to allow analysis | 214 * propagated up the call stack. The default is true to allow analysis |
| 199 * exceptions to show up in unit tests, but it should be set to false when | 215 * exceptions to show up in unit tests, but it should be set to false when |
| 200 * running a full analysis server. | 216 * running a full analysis server. |
| 201 */ | 217 */ |
| 202 AnalysisServer(this.channel, this.resourceProvider, | 218 AnalysisServer(this.channel, this.resourceProvider, |
| 203 PackageMapProvider packageMapProvider, this.index, | 219 PackageMapProvider packageMapProvider, this.index, |
| (...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 optionUpdaters.forEach((OptionUpdater optionUpdater) { | 942 optionUpdaters.forEach((OptionUpdater optionUpdater) { |
| 927 optionUpdater(options); | 943 optionUpdater(options); |
| 928 }); | 944 }); |
| 929 } | 945 } |
| 930 | 946 |
| 931 /** | 947 /** |
| 932 * Schedules [performOperation] exection. | 948 * Schedules [performOperation] exection. |
| 933 */ | 949 */ |
| 934 void _schedulePerformOperation() { | 950 void _schedulePerformOperation() { |
| 935 assert(!performOperationPending); | 951 assert(!performOperationPending); |
| 936 new Future(performOperation); | 952 /* |
| 953 * TODO (danrubel) Rip out this workaround once the underlying problem |
| 954 * is fixed. Currently, the VM and dart:io do not deliver content |
| 955 * on stdin in a timely manner if the event loop is busy. |
| 956 * To work around this problem, we delay for 1 millisecond |
| 957 * every 25 milliseconds. |
| 958 * |
| 959 * To disable this workaround and see the underlying problem, |
| 960 * set performOperationDelayFreqency to zero |
| 961 */ |
| 962 int now = new DateTime.now().millisecondsSinceEpoch; |
| 963 if (now > _nextPerformOperationDelayTime && |
| 964 performOperationDelayFreqency > 0) { |
| 965 _nextPerformOperationDelayTime = now + performOperationDelayFreqency; |
| 966 new Future.delayed(new Duration(milliseconds: 1), performOperation); |
| 967 } else { |
| 968 new Future(performOperation); |
| 969 } |
| 937 performOperationPending = true; | 970 performOperationPending = true; |
| 938 } | 971 } |
| 939 } | 972 } |
| 940 | 973 |
| 941 | 974 |
| 942 class AnalysisServerOptions { | 975 class AnalysisServerOptions { |
| 943 bool enableIncrementalResolutionApi = false; | 976 bool enableIncrementalResolutionApi = false; |
| 944 bool enableIncrementalResolutionValidation = false; | 977 bool enableIncrementalResolutionValidation = false; |
| 945 bool noErrorNotification = false; | 978 bool noErrorNotification = false; |
| 946 String fileReadMode = 'as-is'; | 979 String fileReadMode = 'as-is'; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1076 * [packageUriResolver]. | 1109 * [packageUriResolver]. |
| 1077 */ | 1110 */ |
| 1078 SourceFactory _createSourceFactory(UriResolver packageUriResolver) { | 1111 SourceFactory _createSourceFactory(UriResolver packageUriResolver) { |
| 1079 List<UriResolver> resolvers = <UriResolver>[ | 1112 List<UriResolver> resolvers = <UriResolver>[ |
| 1080 new DartUriResolver(analysisServer.defaultSdk), | 1113 new DartUriResolver(analysisServer.defaultSdk), |
| 1081 new ResourceUriResolver(resourceProvider), | 1114 new ResourceUriResolver(resourceProvider), |
| 1082 packageUriResolver]; | 1115 packageUriResolver]; |
| 1083 return new SourceFactory(resolvers); | 1116 return new SourceFactory(resolvers); |
| 1084 } | 1117 } |
| 1085 } | 1118 } |
| OLD | NEW |