Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Side by Side Diff: pkg/analysis_server/lib/src/analysis_server.dart

Issue 875163002: Make AnalysisServer.onAnalysisComplete a Future and wait for it before refactoring. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use Completer instead of busy loop Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 */ 165 */
166 Map<AnalysisContext, Completer<AnalysisDoneReason>> contextAnalysisDoneComplet ers = 166 Map<AnalysisContext, Completer<AnalysisDoneReason>> contextAnalysisDoneComplet ers =
167 new HashMap<AnalysisContext, Completer<AnalysisDoneReason>>(); 167 new HashMap<AnalysisContext, Completer<AnalysisDoneReason>>();
168 168
169 /** 169 /**
170 * The option possibly set from the server initialization which disables error notifications. 170 * The option possibly set from the server initialization which disables error notifications.
171 */ 171 */
172 bool _noErrorNotification; 172 bool _noErrorNotification;
173 173
174 /** 174 /**
175 * The [Completer] that completes when analysis is complete.
176 */
177 Completer _onAnalysisCompleteCompleter;
178
179 /**
175 * The controller that is notified when analysis is started. 180 * The controller that is notified when analysis is started.
176 */ 181 */
177 StreamController<AnalysisContext> _onAnalysisStartedController; 182 StreamController<AnalysisContext> _onAnalysisStartedController;
178 183
179 /** 184 /**
180 * The controller that is notified when analysis is complete.
181 */
182 StreamController _onAnalysisCompleteController;
183
184 /**
185 * The controller that is notified when a single file has been analyzed. 185 * The controller that is notified when a single file has been analyzed.
186 */ 186 */
187 StreamController<ChangeNotice> _onFileAnalyzedController; 187 StreamController<ChangeNotice> _onFileAnalyzedController;
188 188
189 /** 189 /**
190 * The controller used to notify others when priority sources change. 190 * The controller used to notify others when priority sources change.
191 */ 191 */
192 StreamController<PriorityChangeEvent> _onPriorityChangeController; 192 StreamController<PriorityChangeEvent> _onPriorityChangeController;
193 193
194 /** 194 /**
(...skipping 29 matching lines...) Expand all
224 contextDirectoryManager = 224 contextDirectoryManager =
225 new ServerContextManager(this, resourceProvider, packageMapProvider); 225 new ServerContextManager(this, resourceProvider, packageMapProvider);
226 contextDirectoryManager.defaultOptions.incremental = true; 226 contextDirectoryManager.defaultOptions.incremental = true;
227 contextDirectoryManager.defaultOptions.incrementalApi = 227 contextDirectoryManager.defaultOptions.incrementalApi =
228 analysisServerOptions.enableIncrementalResolutionApi; 228 analysisServerOptions.enableIncrementalResolutionApi;
229 contextDirectoryManager.defaultOptions.incrementalValidation = 229 contextDirectoryManager.defaultOptions.incrementalValidation =
230 analysisServerOptions.enableIncrementalResolutionValidation; 230 analysisServerOptions.enableIncrementalResolutionValidation;
231 _noErrorNotification = analysisServerOptions.noErrorNotification; 231 _noErrorNotification = analysisServerOptions.noErrorNotification;
232 AnalysisEngine.instance.logger = new AnalysisLogger(); 232 AnalysisEngine.instance.logger = new AnalysisLogger();
233 _onAnalysisStartedController = new StreamController.broadcast(); 233 _onAnalysisStartedController = new StreamController.broadcast();
234 _onAnalysisCompleteController = new StreamController.broadcast();
235 _onFileAnalyzedController = new StreamController.broadcast(); 234 _onFileAnalyzedController = new StreamController.broadcast();
236 _onPriorityChangeController = 235 _onPriorityChangeController =
237 new StreamController<PriorityChangeEvent>.broadcast(); 236 new StreamController<PriorityChangeEvent>.broadcast();
238 running = true; 237 running = true;
239 Notification notification = new ServerConnectedParams().toNotification(); 238 Notification notification = new ServerConnectedParams().toNotification();
240 channel.sendNotification(notification); 239 channel.sendNotification(notification);
241 channel.listen(handleRequest, onDone: done, onError: error); 240 channel.listen(handleRequest, onDone: done, onError: error);
242 } 241 }
243 242
244 /** 243 /**
245 * The stream that is notified when analysis is complete. 244 * The [Future] that completes when analysis is complete.
246 */ 245 */
247 Stream get onAnalysisComplete => _onAnalysisCompleteController.stream; 246 Future get onAnalysisComplete {
247 if (isAnalysisComplete()) {
248 return new Future.value();
249 }
250 if (_onAnalysisCompleteCompleter == null) {
251 _onAnalysisCompleteCompleter = new Completer();
252 }
253 return _onAnalysisCompleteCompleter.future;
254 }
248 255
249 /** 256 /**
250 * The stream that is notified when analysis of a context is started. 257 * The stream that is notified when analysis of a context is started.
251 */ 258 */
252 Stream<AnalysisContext> get onAnalysisStarted { 259 Stream<AnalysisContext> get onAnalysisStarted {
253 return _onAnalysisStartedController.stream; 260 return _onAnalysisStartedController.stream;
254 } 261 }
255 262
256 /** 263 /**
257 * The stream that is notified when contexts are added or removed. 264 * The stream that is notified when contexts are added or removed.
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 'Unexpected exception during analysis', 632 'Unexpected exception during analysis',
626 new CaughtException(exception, stackTrace)); 633 new CaughtException(exception, stackTrace));
627 } 634 }
628 sendServerErrorNotification(exception, stackTrace, fatal: true); 635 sendServerErrorNotification(exception, stackTrace, fatal: true);
629 shutdown(); 636 shutdown();
630 } finally { 637 } finally {
631 if (!operationQueue.isEmpty) { 638 if (!operationQueue.isEmpty) {
632 _schedulePerformOperation(); 639 _schedulePerformOperation();
633 } else { 640 } else {
634 sendStatusNotification(null); 641 sendStatusNotification(null);
635 _onAnalysisCompleteController.add(null); 642 if (_onAnalysisCompleteCompleter != null) {
643 _onAnalysisCompleteCompleter.complete();
644 _onAnalysisCompleteCompleter = null;
645 }
636 } 646 }
637 } 647 }
638 } 648 }
639 649
640 /** 650 /**
641 * Trigger reanalysis of all files from disk. 651 * Trigger reanalysis of all files from disk.
642 */ 652 */
643 void reanalyze() { 653 void reanalyze() {
644 // Clear any operations that are pending. 654 // Clear any operations that are pending.
645 operationQueue.clear(); 655 operationQueue.clear();
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 * [packageUriResolver]. 1119 * [packageUriResolver].
1110 */ 1120 */
1111 SourceFactory _createSourceFactory(UriResolver packageUriResolver) { 1121 SourceFactory _createSourceFactory(UriResolver packageUriResolver) {
1112 List<UriResolver> resolvers = <UriResolver>[ 1122 List<UriResolver> resolvers = <UriResolver>[
1113 new DartUriResolver(analysisServer.defaultSdk), 1123 new DartUriResolver(analysisServer.defaultSdk),
1114 new ResourceUriResolver(resourceProvider), 1124 new ResourceUriResolver(resourceProvider),
1115 packageUriResolver]; 1125 packageUriResolver];
1116 return new SourceFactory(resolvers); 1126 return new SourceFactory(resolvers);
1117 } 1127 }
1118 } 1128 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/edit/edit_domain.dart » ('j') | pkg/analysis_server/lib/src/edit/edit_domain.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698