| 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 import 'dart:core' hide Resource; | 9 import 'dart:core' hide Resource; |
| 10 import 'dart:math' show max; | 10 import 'dart:math' show max; |
| 11 | 11 |
| 12 import 'package:analysis_server/plugin/analysis/analyzed_files.dart'; | |
| 13 import 'package:analysis_server/plugin/analysis/resolver_provider.dart'; | 12 import 'package:analysis_server/plugin/analysis/resolver_provider.dart'; |
| 14 import 'package:analysis_server/plugin/protocol/protocol.dart' hide Element; | 13 import 'package:analysis_server/plugin/protocol/protocol.dart' hide Element; |
| 15 import 'package:analysis_server/src/analysis_logger.dart'; | 14 import 'package:analysis_server/src/analysis_logger.dart'; |
| 16 import 'package:analysis_server/src/channel/channel.dart'; | 15 import 'package:analysis_server/src/channel/channel.dart'; |
| 17 import 'package:analysis_server/src/context_manager.dart'; | 16 import 'package:analysis_server/src/context_manager.dart'; |
| 18 import 'package:analysis_server/src/operation/operation.dart'; | 17 import 'package:analysis_server/src/operation/operation.dart'; |
| 19 import 'package:analysis_server/src/operation/operation_analysis.dart'; | 18 import 'package:analysis_server/src/operation/operation_analysis.dart'; |
| 20 import 'package:analysis_server/src/operation/operation_queue.dart'; | 19 import 'package:analysis_server/src/operation/operation_queue.dart'; |
| 21 import 'package:analysis_server/src/plugin/server_plugin.dart'; | 20 import 'package:analysis_server/src/plugin/server_plugin.dart'; |
| 22 import 'package:analysis_server/src/services/correction/namespace.dart'; | 21 import 'package:analysis_server/src/services/correction/namespace.dart'; |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 ServerContextManagerCallbacks contextManagerCallbacks = | 310 ServerContextManagerCallbacks contextManagerCallbacks = |
| 312 new ServerContextManagerCallbacks(this, resourceProvider); | 311 new ServerContextManagerCallbacks(this, resourceProvider); |
| 313 contextManager.callbacks = contextManagerCallbacks; | 312 contextManager.callbacks = contextManagerCallbacks; |
| 314 defaultContextOptions.incremental = true; | 313 defaultContextOptions.incremental = true; |
| 315 defaultContextOptions.incrementalApi = | 314 defaultContextOptions.incrementalApi = |
| 316 options.enableIncrementalResolutionApi; | 315 options.enableIncrementalResolutionApi; |
| 317 defaultContextOptions.incrementalValidation = | 316 defaultContextOptions.incrementalValidation = |
| 318 options.enableIncrementalResolutionValidation; | 317 options.enableIncrementalResolutionValidation; |
| 319 defaultContextOptions.generateImplicitErrors = false; | 318 defaultContextOptions.generateImplicitErrors = false; |
| 320 _noErrorNotification = options.noErrorNotification; | 319 _noErrorNotification = options.noErrorNotification; |
| 321 AnalysisEngine.instance.logger = new AnalysisLogger(); | 320 AnalysisEngine.instance.logger = new AnalysisLogger(this); |
| 322 _onAnalysisStartedController = new StreamController.broadcast(); | 321 _onAnalysisStartedController = new StreamController.broadcast(); |
| 323 _onFileAnalyzedController = new StreamController.broadcast(); | 322 _onFileAnalyzedController = new StreamController.broadcast(); |
| 324 _onPriorityChangeController = | 323 _onPriorityChangeController = |
| 325 new StreamController<PriorityChangeEvent>.broadcast(); | 324 new StreamController<PriorityChangeEvent>.broadcast(); |
| 326 running = true; | 325 running = true; |
| 327 onAnalysisStarted.first.then((_) { | 326 onAnalysisStarted.first.then((_) { |
| 328 onAnalysisComplete.then((_) { | 327 onAnalysisComplete.then((_) { |
| 329 performanceAfterStartup = new ServerPerformance(); | 328 performanceAfterStartup = new ServerPerformance(); |
| 330 _performance = performanceAfterStartup; | 329 _performance = performanceAfterStartup; |
| 331 }); | 330 }); |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 error.stackTrace = stackTrace.toString(); | 705 error.stackTrace = stackTrace.toString(); |
| 707 } | 706 } |
| 708 Response response = new Response(request.id, error: error); | 707 Response response = new Response(request.id, error: error); |
| 709 channel.sendResponse(response); | 708 channel.sendResponse(response); |
| 710 return; | 709 return; |
| 711 } | 710 } |
| 712 } | 711 } |
| 713 channel.sendResponse(new Response.unknownRequest(request)); | 712 channel.sendResponse(new Response.unknownRequest(request)); |
| 714 }); | 713 }); |
| 715 }, onError: (exception, stackTrace) { | 714 }, onError: (exception, stackTrace) { |
| 716 sendServerErrorNotification(exception, stackTrace, fatal: true); | 715 sendServerErrorNotification( |
| 716 'Failed to handle request: ${request.toJson()}', |
| 717 exception, |
| 718 stackTrace, |
| 719 fatal: true); |
| 717 }); | 720 }); |
| 718 } | 721 } |
| 719 | 722 |
| 720 /** | 723 /** |
| 721 * Returns `true` if there is a subscription for the given [service] and | 724 * Returns `true` if there is a subscription for the given [service] and |
| 722 * [file]. | 725 * [file]. |
| 723 */ | 726 */ |
| 724 bool hasAnalysisSubscription(AnalysisService service, String file) { | 727 bool hasAnalysisSubscription(AnalysisService service, String file) { |
| 725 Set<String> files = analysisServices[service]; | 728 Set<String> files = analysisServices[service]; |
| 726 return files != null && files.contains(file); | 729 return files != null && files.contains(file); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 // loop is in progress. No problem; we just need to exit the operation | 790 // loop is in progress. No problem; we just need to exit the operation |
| 788 // loop and wait for the next operation to be added. | 791 // loop and wait for the next operation to be added. |
| 789 ServerPerformanceStatistics.idle.makeCurrent(); | 792 ServerPerformanceStatistics.idle.makeCurrent(); |
| 790 return; | 793 return; |
| 791 } | 794 } |
| 792 sendStatusNotification(operation); | 795 sendStatusNotification(operation); |
| 793 // perform the operation | 796 // perform the operation |
| 794 try { | 797 try { |
| 795 operation.perform(this); | 798 operation.perform(this); |
| 796 } catch (exception, stackTrace) { | 799 } catch (exception, stackTrace) { |
| 797 AnalysisEngine.instance.logger.logError("${exception}\n${stackTrace}"); | 800 sendServerErrorNotification( |
| 801 'Failed to perform operation: $operation', exception, stackTrace, |
| 802 fatal: true); |
| 798 if (rethrowExceptions) { | 803 if (rethrowExceptions) { |
| 799 throw new AnalysisException('Unexpected exception during analysis', | 804 throw new AnalysisException('Unexpected exception during analysis', |
| 800 new CaughtException(exception, stackTrace)); | 805 new CaughtException(exception, stackTrace)); |
| 801 } | 806 } |
| 802 sendServerErrorNotification(exception, stackTrace, fatal: true); | |
| 803 shutdown(); | 807 shutdown(); |
| 804 } finally { | 808 } finally { |
| 805 if (_test_onOperationPerformedCompleter != null) { | 809 if (_test_onOperationPerformedCompleter != null) { |
| 806 _test_onOperationPerformedCompleter.complete(operation); | 810 _test_onOperationPerformedCompleter.complete(operation); |
| 807 _test_onOperationPerformedCompleter = null; | 811 _test_onOperationPerformedCompleter = null; |
| 808 } | 812 } |
| 809 if (!operationQueue.isEmpty) { | 813 if (!operationQueue.isEmpty) { |
| 810 ServerPerformanceStatistics.intertask.makeCurrent(); | 814 ServerPerformanceStatistics.intertask.makeCurrent(); |
| 811 _schedulePerformOperation(); | 815 _schedulePerformOperation(); |
| 812 } else { | 816 } else { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 /** | 886 /** |
| 883 * Send the given [response] to the client. | 887 * Send the given [response] to the client. |
| 884 */ | 888 */ |
| 885 void sendResponse(Response response) { | 889 void sendResponse(Response response) { |
| 886 channel.sendResponse(response); | 890 channel.sendResponse(response); |
| 887 } | 891 } |
| 888 | 892 |
| 889 /** | 893 /** |
| 890 * Sends a `server.error` notification. | 894 * Sends a `server.error` notification. |
| 891 */ | 895 */ |
| 892 void sendServerErrorNotification(exception, stackTrace, {bool fatal: false}) { | 896 void sendServerErrorNotification(String msg, exception, stackTrace, |
| 897 {bool fatal: false}) { |
| 893 // prepare exception.toString() | 898 // prepare exception.toString() |
| 894 String exceptionString; | 899 String exceptionString; |
| 895 if (exception != null) { | 900 if (exception != null) { |
| 896 exceptionString = exception.toString(); | 901 exceptionString = exception.toString(); |
| 897 } else { | 902 } else { |
| 898 exceptionString = 'null exception'; | 903 exceptionString = 'null exception'; |
| 899 } | 904 } |
| 905 // prepare message |
| 906 String message = msg != null ? '$msg\n$exceptionString' : exceptionString; |
| 900 // prepare stackTrace.toString() | 907 // prepare stackTrace.toString() |
| 901 String stackTraceString; | 908 String stackTraceString; |
| 902 if (stackTrace != null) { | 909 if (stackTrace != null) { |
| 903 stackTraceString = stackTrace.toString(); | 910 stackTraceString = stackTrace.toString(); |
| 904 } else { | 911 } else { |
| 905 try { | 912 try { |
| 906 throw 'ignored'; | 913 throw 'ignored'; |
| 907 } catch (ignored, stackTrace) { | 914 } catch (ignored, stackTrace) { |
| 908 stackTraceString = stackTrace.toString(); | 915 stackTraceString = stackTrace.toString(); |
| 909 } | 916 } |
| 910 if (stackTraceString == null) { | 917 if (stackTraceString == null) { |
| 911 // This code should be unreachable. | 918 // This code should be unreachable. |
| 912 stackTraceString = 'null stackTrace'; | 919 stackTraceString = 'null stackTrace'; |
| 913 } | 920 } |
| 914 } | 921 } |
| 915 // send the notification | 922 // send the notification |
| 916 channel.sendNotification( | 923 channel.sendNotification( |
| 917 new ServerErrorParams(fatal, exceptionString, stackTraceString) | 924 new ServerErrorParams(fatal, message, stackTraceString) |
| 918 .toNotification()); | 925 .toNotification()); |
| 919 } | 926 } |
| 920 | 927 |
| 921 /** | 928 /** |
| 922 * Send status notification to the client. The `operation` is the operation | 929 * Send status notification to the client. The `operation` is the operation |
| 923 * being performed or `null` if analysis is complete. | 930 * being performed or `null` if analysis is complete. |
| 924 */ | 931 */ |
| 925 void sendStatusNotification(ServerOperation operation) { | 932 void sendStatusNotification(ServerOperation operation) { |
| 926 // Only send status when subscribed. | 933 // Only send status when subscribed. |
| 927 if (!serverServices.contains(ServerService.STATUS)) { | 934 if (!serverServices.contains(ServerService.STATUS)) { |
| (...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1633 /** | 1640 /** |
| 1634 * The [PerformanceTag] for time spent in server request handlers. | 1641 * The [PerformanceTag] for time spent in server request handlers. |
| 1635 */ | 1642 */ |
| 1636 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); | 1643 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); |
| 1637 | 1644 |
| 1638 /** | 1645 /** |
| 1639 * The [PerformanceTag] for time spent in split store microtasks. | 1646 * The [PerformanceTag] for time spent in split store microtasks. |
| 1640 */ | 1647 */ |
| 1641 static PerformanceTag splitStore = new PerformanceTag('splitStore'); | 1648 static PerformanceTag splitStore = new PerformanceTag('splitStore'); |
| 1642 } | 1649 } |
| OLD | NEW |