Chromium Code Reviews| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 final PackageMapProvider packageMapProvider; | 95 final PackageMapProvider packageMapProvider; |
| 96 | 96 |
| 97 /** | 97 /** |
| 98 * A flag indicating whether the server is running. When false, contexts | 98 * A flag indicating whether the server is running. When false, contexts |
| 99 * will no longer be added to [contextWorkQueue], and [performOperation] will | 99 * will no longer be added to [contextWorkQueue], and [performOperation] will |
| 100 * discard any tasks it finds on [contextWorkQueue]. | 100 * discard any tasks it finds on [contextWorkQueue]. |
| 101 */ | 101 */ |
| 102 bool running; | 102 bool running; |
| 103 | 103 |
| 104 /** | 104 /** |
| 105 * A flag indicating the value of the 'analyzing' parameter sent in the last | |
| 106 * status message to the client. | |
| 107 */ | |
| 108 bool statusAnalyzing = false; | |
|
Paul Berry
2014/06/25 19:38:16
How about if we call this "wasAnalyzing"
danrubel
2014/06/26 11:53:22
I want to convey that this field is associated wit
| |
| 109 | |
| 110 /** | |
| 105 * A list of the request handlers used to handle the requests sent to this | 111 * A list of the request handlers used to handle the requests sent to this |
| 106 * server. | 112 * server. |
| 107 */ | 113 */ |
| 108 List<RequestHandler> handlers; | 114 List<RequestHandler> handlers; |
| 109 | 115 |
| 110 /** | 116 /** |
| 111 * The current default [DartSdk]. | 117 * The current default [DartSdk]. |
| 112 */ | 118 */ |
| 113 DartSdk defaultSdk = SHARED_SDK; | 119 DartSdk defaultSdk = SHARED_SDK; |
| 114 | 120 |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 void performOperation() { | 339 void performOperation() { |
| 334 if (!running) { | 340 if (!running) { |
| 335 // An error has occurred, or the connection to the client has been | 341 // An error has occurred, or the connection to the client has been |
| 336 // closed, since this method was scheduled on the event queue. So | 342 // closed, since this method was scheduled on the event queue. So |
| 337 // don't do anything. Instead clear the operation queue. | 343 // don't do anything. Instead clear the operation queue. |
| 338 operationQueue.clear(); | 344 operationQueue.clear(); |
| 339 return; | 345 return; |
| 340 } | 346 } |
| 341 // prepare next operation | 347 // prepare next operation |
| 342 ServerOperation operation = operationQueue.take(); | 348 ServerOperation operation = operationQueue.take(); |
| 349 sendStatusNotification(operation); | |
| 343 // perform the operation | 350 // perform the operation |
| 344 try { | 351 try { |
| 345 operation.perform(this); | 352 operation.perform(this); |
| 346 } catch (exception, stackTrace) { | 353 } catch (exception, stackTrace) { |
| 347 AnalysisEngine.instance.logger.logError("${exception}\n${stackTrace}"); | 354 AnalysisEngine.instance.logger.logError("${exception}\n${stackTrace}"); |
| 348 if (rethrowExceptions) { | 355 if (rethrowExceptions) { |
| 349 throw new AnalysisException( | 356 throw new AnalysisException( |
| 350 'Unexpected exception during analysis', | 357 'Unexpected exception during analysis', |
| 351 new CaughtException(exception, stackTrace)); | 358 new CaughtException(exception, stackTrace)); |
| 352 } | 359 } |
| 353 } finally { | 360 } finally { |
| 354 if (!operationQueue.isEmpty) { | 361 if (!operationQueue.isEmpty) { |
| 355 _schedulePerformOperation(); | 362 _schedulePerformOperation(); |
| 356 } else { | 363 } else { |
| 357 sendStatusNotification(null); | 364 sendStatusNotification(null); |
| 358 } | 365 } |
| 359 } | 366 } |
| 360 } | 367 } |
| 361 | 368 |
| 362 /** | 369 /** |
| 363 * Send status notification to the client. The `contextId` indicates | 370 * Send status notification to the client. The `operation` is the operation |
| 364 * the current context being analyzed or `null` if analysis is complete. | 371 * being performed or `null` if analysis is complete. |
| 365 */ | 372 */ |
| 366 void sendStatusNotification(String contextId) { | 373 void sendStatusNotification(ServerOperation operation) { |
| 374 // Only send status when it changes | |
|
Paul Berry
2014/06/25 19:38:16
Then this code can look like:
bool isAnalyzing
danrubel
2014/06/26 11:53:22
You're right. I like it better that way. Done.
| |
| 375 if (statusAnalyzing == (operation != null)) { | |
| 376 return; | |
| 377 } | |
| 378 statusAnalyzing = (operation != null); | |
| 367 Notification notification = new Notification(SERVER_STATUS); | 379 Notification notification = new Notification(SERVER_STATUS); |
| 368 Map<String, Object> analysis = new Map(); | 380 Map<String, Object> analysis = new Map(); |
| 369 if (contextId != null) { | 381 analysis['analyzing'] = statusAnalyzing; |
| 370 analysis['analyzing'] = true; | |
| 371 // TODO(danrubel): replace contextId with real analysisTarget | |
| 372 analysis['analysisTarget'] = contextId; | |
| 373 } else { | |
| 374 analysis['analyzing'] = false; | |
| 375 } | |
| 376 notification.params['analysis'] = analysis; | 382 notification.params['analysis'] = analysis; |
| 377 channel.sendNotification(notification); | 383 channel.sendNotification(notification); |
| 378 } | 384 } |
| 379 | 385 |
| 380 /** | 386 /** |
| 381 * Implementation for `analysis.setAnalysisRoots`. | 387 * Implementation for `analysis.setAnalysisRoots`. |
| 382 * | 388 * |
| 383 * TODO(scheglov) implement complete projects/contexts semantics. | 389 * TODO(scheglov) implement complete projects/contexts semantics. |
| 384 * | 390 * |
| 385 * The current implementation is intentionally simplified and expected | 391 * The current implementation is intentionally simplified and expected |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 613 /** | 619 /** |
| 614 * An enumeration of the services provided by the server domain. | 620 * An enumeration of the services provided by the server domain. |
| 615 */ | 621 */ |
| 616 class ServerService extends Enum2<ServerService> { | 622 class ServerService extends Enum2<ServerService> { |
| 617 static const ServerService STATUS = const ServerService('STATUS', 0); | 623 static const ServerService STATUS = const ServerService('STATUS', 0); |
| 618 | 624 |
| 619 static const List<ServerService> VALUES = const [STATUS]; | 625 static const List<ServerService> VALUES = const [STATUS]; |
| 620 | 626 |
| 621 const ServerService(String name, int ordinal) : super(name, ordinal); | 627 const ServerService(String name, int ordinal) : super(name, ordinal); |
| 622 } | 628 } |
| OLD | NEW |