| 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 final PackageMapProvider packageMapProvider; | 101 final PackageMapProvider packageMapProvider; |
| 102 | 102 |
| 103 /** | 103 /** |
| 104 * A flag indicating whether the server is running. When false, contexts | 104 * A flag indicating whether the server is running. When false, contexts |
| 105 * will no longer be added to [contextWorkQueue], and [performOperation] will | 105 * will no longer be added to [contextWorkQueue], and [performOperation] will |
| 106 * discard any tasks it finds on [contextWorkQueue]. | 106 * discard any tasks it finds on [contextWorkQueue]. |
| 107 */ | 107 */ |
| 108 bool running; | 108 bool running; |
| 109 | 109 |
| 110 /** | 110 /** |
| 111 * A flag indicating the value of the 'analyzing' parameter sent in the last |
| 112 * status message to the client. |
| 113 */ |
| 114 bool statusAnalyzing = false; |
| 115 |
| 116 /** |
| 111 * A list of the request handlers used to handle the requests sent to this | 117 * A list of the request handlers used to handle the requests sent to this |
| 112 * server. | 118 * server. |
| 113 */ | 119 */ |
| 114 List<RequestHandler> handlers; | 120 List<RequestHandler> handlers; |
| 115 | 121 |
| 116 /** | 122 /** |
| 117 * The current default [DartSdk]. | 123 * The current default [DartSdk]. |
| 118 */ | 124 */ |
| 119 DartSdk defaultSdk = SHARED_SDK; | 125 DartSdk defaultSdk = SHARED_SDK; |
| 120 | 126 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 void performOperation() { | 346 void performOperation() { |
| 341 if (!running) { | 347 if (!running) { |
| 342 // An error has occurred, or the connection to the client has been | 348 // An error has occurred, or the connection to the client has been |
| 343 // closed, since this method was scheduled on the event queue. So | 349 // closed, since this method was scheduled on the event queue. So |
| 344 // don't do anything. Instead clear the operation queue. | 350 // don't do anything. Instead clear the operation queue. |
| 345 operationQueue.clear(); | 351 operationQueue.clear(); |
| 346 return; | 352 return; |
| 347 } | 353 } |
| 348 // prepare next operation | 354 // prepare next operation |
| 349 ServerOperation operation = operationQueue.take(); | 355 ServerOperation operation = operationQueue.take(); |
| 356 sendStatusNotification(operation); |
| 350 // perform the operation | 357 // perform the operation |
| 351 try { | 358 try { |
| 352 operation.perform(this); | 359 operation.perform(this); |
| 353 } catch (exception, stackTrace) { | 360 } catch (exception, stackTrace) { |
| 354 AnalysisEngine.instance.logger.logError("${exception}\n${stackTrace}"); | 361 AnalysisEngine.instance.logger.logError("${exception}\n${stackTrace}"); |
| 355 if (rethrowExceptions) { | 362 if (rethrowExceptions) { |
| 356 throw new AnalysisException( | 363 throw new AnalysisException( |
| 357 'Unexpected exception during analysis', | 364 'Unexpected exception during analysis', |
| 358 new CaughtException(exception, stackTrace)); | 365 new CaughtException(exception, stackTrace)); |
| 359 } | 366 } |
| 360 } finally { | 367 } finally { |
| 361 if (!operationQueue.isEmpty) { | 368 if (!operationQueue.isEmpty) { |
| 362 _schedulePerformOperation(); | 369 _schedulePerformOperation(); |
| 363 } else { | 370 } else { |
| 364 sendStatusNotification(null); | 371 sendStatusNotification(null); |
| 365 } | 372 } |
| 366 } | 373 } |
| 367 } | 374 } |
| 368 | 375 |
| 369 /** | 376 /** |
| 370 * Send status notification to the client. The `contextId` indicates | 377 * Send status notification to the client. The `operation` is the operation |
| 371 * the current context being analyzed or `null` if analysis is complete. | 378 * being performed or `null` if analysis is complete. |
| 372 */ | 379 */ |
| 373 void sendStatusNotification(String contextId) { | 380 void sendStatusNotification(ServerOperation operation) { |
| 381 // Only send status when it changes |
| 382 bool isAnalyzing = operation != null; |
| 383 if (statusAnalyzing == isAnalyzing) { |
| 384 return; |
| 385 } |
| 386 statusAnalyzing = isAnalyzing; |
| 374 Notification notification = new Notification(SERVER_STATUS); | 387 Notification notification = new Notification(SERVER_STATUS); |
| 375 Map<String, Object> analysis = new Map(); | 388 Map<String, Object> analysis = new Map(); |
| 376 if (contextId != null) { | 389 analysis['analyzing'] = isAnalyzing; |
| 377 analysis['analyzing'] = true; | |
| 378 // TODO(danrubel): replace contextId with real analysisTarget | |
| 379 analysis['analysisTarget'] = contextId; | |
| 380 } else { | |
| 381 analysis['analyzing'] = false; | |
| 382 } | |
| 383 notification.params['analysis'] = analysis; | 390 notification.params['analysis'] = analysis; |
| 384 channel.sendNotification(notification); | 391 channel.sendNotification(notification); |
| 385 } | 392 } |
| 386 | 393 |
| 387 /** | 394 /** |
| 388 * Implementation for `analysis.setAnalysisRoots`. | 395 * Implementation for `analysis.setAnalysisRoots`. |
| 389 * | 396 * |
| 390 * TODO(scheglov) implement complete projects/contexts semantics. | 397 * TODO(scheglov) implement complete projects/contexts semantics. |
| 391 * | 398 * |
| 392 * The current implementation is intentionally simplified and expected | 399 * The current implementation is intentionally simplified and expected |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 /** | 627 /** |
| 621 * An enumeration of the services provided by the server domain. | 628 * An enumeration of the services provided by the server domain. |
| 622 */ | 629 */ |
| 623 class ServerService extends Enum2<ServerService> { | 630 class ServerService extends Enum2<ServerService> { |
| 624 static const ServerService STATUS = const ServerService('STATUS', 0); | 631 static const ServerService STATUS = const ServerService('STATUS', 0); |
| 625 | 632 |
| 626 static const List<ServerService> VALUES = const [STATUS]; | 633 static const List<ServerService> VALUES = const [STATUS]; |
| 627 | 634 |
| 628 const ServerService(String name, int ordinal) : super(name, ordinal); | 635 const ServerService(String name, int ordinal) : super(name, ordinal); |
| 629 } | 636 } |
| OLD | NEW |