| 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 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 new RequestError(RequestErrorCode.SERVER_ERROR, exception.toString
()); | 505 new RequestError(RequestErrorCode.SERVER_ERROR, exception.toString
()); |
| 506 if (stackTrace != null) { | 506 if (stackTrace != null) { |
| 507 error.stackTrace = stackTrace.toString(); | 507 error.stackTrace = stackTrace.toString(); |
| 508 } | 508 } |
| 509 Response response = new Response(request.id, error: error); | 509 Response response = new Response(request.id, error: error); |
| 510 channel.sendResponse(response); | 510 channel.sendResponse(response); |
| 511 return; | 511 return; |
| 512 } | 512 } |
| 513 } | 513 } |
| 514 channel.sendResponse(new Response.unknownRequest(request)); | 514 channel.sendResponse(new Response.unknownRequest(request)); |
| 515 }, onError: _sendServerErrorNotification); | 515 }, onError: (exception, stackTrace) { |
| 516 sendServerErrorNotification(exception, stackTrace, fatal: true); |
| 517 }); |
| 516 } | 518 } |
| 517 | 519 |
| 518 /** | 520 /** |
| 519 * Returns `true` if there is a subscription for the given [server] and [file]
. | 521 * Returns `true` if there is a subscription for the given [server] and [file]
. |
| 520 */ | 522 */ |
| 521 bool hasAnalysisSubscription(AnalysisService service, String file) { | 523 bool hasAnalysisSubscription(AnalysisService service, String file) { |
| 522 Set<String> files = analysisServices[service]; | 524 Set<String> files = analysisServices[service]; |
| 523 return files != null && files.contains(file); | 525 return files != null && files.contains(file); |
| 524 } | 526 } |
| 525 | 527 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 // perform the operation | 598 // perform the operation |
| 597 try { | 599 try { |
| 598 operation.perform(this); | 600 operation.perform(this); |
| 599 } catch (exception, stackTrace) { | 601 } catch (exception, stackTrace) { |
| 600 AnalysisEngine.instance.logger.logError("${exception}\n${stackTrace}"); | 602 AnalysisEngine.instance.logger.logError("${exception}\n${stackTrace}"); |
| 601 if (rethrowExceptions) { | 603 if (rethrowExceptions) { |
| 602 throw new AnalysisException( | 604 throw new AnalysisException( |
| 603 'Unexpected exception during analysis', | 605 'Unexpected exception during analysis', |
| 604 new CaughtException(exception, stackTrace)); | 606 new CaughtException(exception, stackTrace)); |
| 605 } | 607 } |
| 606 _sendServerErrorNotification(exception, stackTrace); | 608 sendServerErrorNotification(exception, stackTrace, fatal: true); |
| 607 shutdown(); | 609 shutdown(); |
| 608 } finally { | 610 } finally { |
| 609 if (!operationQueue.isEmpty) { | 611 if (!operationQueue.isEmpty) { |
| 610 _schedulePerformOperation(); | 612 _schedulePerformOperation(); |
| 611 } else { | 613 } else { |
| 612 sendStatusNotification(null); | 614 sendStatusNotification(null); |
| 613 _onAnalysisCompleteController.add(null); | 615 _onAnalysisCompleteController.add(null); |
| 614 } | 616 } |
| 615 } | 617 } |
| 616 } | 618 } |
| 617 | 619 |
| 618 /** | 620 /** |
| 619 * Trigger reanalysis of all files from disk. | 621 * Trigger reanalysis of all files from disk. |
| 620 */ | 622 */ |
| 621 void reanalyze() { | 623 void reanalyze() { |
| 622 // Clear any operations that are pending. | 624 // Clear any operations that are pending. |
| 623 operationQueue.clear(); | 625 operationQueue.clear(); |
| 624 // Instruct the contextDirectoryManager to rebuild all contexts from | 626 // Instruct the contextDirectoryManager to rebuild all contexts from |
| 625 // scratch. | 627 // scratch. |
| 626 contextDirectoryManager.refresh(); | 628 contextDirectoryManager.refresh(); |
| 627 } | 629 } |
| 628 | 630 |
| 629 /** | 631 /** |
| 630 * Report to the client that the given [exception] was caught with the | |
| 631 * associated [stackTrace]. | |
| 632 */ | |
| 633 void reportException(dynamic exception, StackTrace stackTrace) { | |
| 634 _sendServerErrorNotification(exception, stackTrace); | |
| 635 } | |
| 636 | |
| 637 /** | |
| 638 * Schedules execution of the given [ServerOperation]. | 632 * Schedules execution of the given [ServerOperation]. |
| 639 */ | 633 */ |
| 640 void scheduleOperation(ServerOperation operation) { | 634 void scheduleOperation(ServerOperation operation) { |
| 641 addOperation(operation); | 635 addOperation(operation); |
| 642 if (!performOperationPending) { | 636 if (!performOperationPending) { |
| 643 _schedulePerformOperation(); | 637 _schedulePerformOperation(); |
| 644 } | 638 } |
| 645 } | 639 } |
| 646 | 640 |
| 647 /** | 641 /** |
| (...skipping 25 matching lines...) Expand all Loading... |
| 673 } | 667 } |
| 674 | 668 |
| 675 /** | 669 /** |
| 676 * Send the given [response] to the client. | 670 * Send the given [response] to the client. |
| 677 */ | 671 */ |
| 678 void sendResponse(Response response) { | 672 void sendResponse(Response response) { |
| 679 channel.sendResponse(response); | 673 channel.sendResponse(response); |
| 680 } | 674 } |
| 681 | 675 |
| 682 /** | 676 /** |
| 677 * Sends a `server.error` notification. |
| 678 */ |
| 679 void sendServerErrorNotification(exception, stackTrace, {bool fatal: false}) { |
| 680 // prepare exception.toString() |
| 681 String exceptionString; |
| 682 if (exception != null) { |
| 683 exceptionString = exception.toString(); |
| 684 } else { |
| 685 exceptionString = 'null exception'; |
| 686 } |
| 687 // prepare stackTrace.toString() |
| 688 String stackTraceString; |
| 689 if (stackTrace != null) { |
| 690 stackTraceString = stackTrace.toString(); |
| 691 } else { |
| 692 stackTraceString = 'null stackTrace'; |
| 693 } |
| 694 // send the notification |
| 695 channel.sendNotification( |
| 696 new ServerErrorParams( |
| 697 fatal, |
| 698 exceptionString, |
| 699 stackTraceString).toNotification()); |
| 700 } |
| 701 |
| 702 /** |
| 683 * Send status notification to the client. The `operation` is the operation | 703 * Send status notification to the client. The `operation` is the operation |
| 684 * being performed or `null` if analysis is complete. | 704 * being performed or `null` if analysis is complete. |
| 685 */ | 705 */ |
| 686 void sendStatusNotification(ServerOperation operation) { | 706 void sendStatusNotification(ServerOperation operation) { |
| 687 // Only send status when subscribed. | 707 // Only send status when subscribed. |
| 688 if (!serverServices.contains(ServerService.STATUS)) { | 708 if (!serverServices.contains(ServerService.STATUS)) { |
| 689 return; | 709 return; |
| 690 } | 710 } |
| 691 // Only send status when it changes | 711 // Only send status when it changes |
| 692 bool isAnalyzing = operation != null; | 712 bool isAnalyzing = operation != null; |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 } | 928 } |
| 909 | 929 |
| 910 /** | 930 /** |
| 911 * Schedules [performOperation] exection. | 931 * Schedules [performOperation] exection. |
| 912 */ | 932 */ |
| 913 void _schedulePerformOperation() { | 933 void _schedulePerformOperation() { |
| 914 assert(!performOperationPending); | 934 assert(!performOperationPending); |
| 915 new Future(performOperation); | 935 new Future(performOperation); |
| 916 performOperationPending = true; | 936 performOperationPending = true; |
| 917 } | 937 } |
| 918 | |
| 919 /** | |
| 920 * Sends a fatal `server.error` notification. | |
| 921 */ | |
| 922 void _sendServerErrorNotification(exception, stackTrace) { | |
| 923 // prepare exception.toString() | |
| 924 String exceptionString; | |
| 925 if (exception != null) { | |
| 926 exceptionString = exception.toString(); | |
| 927 } else { | |
| 928 exceptionString = 'null exception'; | |
| 929 } | |
| 930 // prepare stackTrace.toString() | |
| 931 String stackTraceString; | |
| 932 if (stackTrace != null) { | |
| 933 stackTraceString = stackTrace.toString(); | |
| 934 } else { | |
| 935 stackTraceString = 'null stackTrace'; | |
| 936 } | |
| 937 // send the notification | |
| 938 channel.sendNotification( | |
| 939 new ServerErrorParams( | |
| 940 true, | |
| 941 exceptionString, | |
| 942 stackTraceString).toNotification()); | |
| 943 } | |
| 944 } | 938 } |
| 945 | 939 |
| 946 | 940 |
| 947 class AnalysisServerOptions { | 941 class AnalysisServerOptions { |
| 948 bool enableIncrementalResolutionApi = false; | 942 bool enableIncrementalResolutionApi = false; |
| 949 bool enableIncrementalResolutionValidation = false; | 943 bool enableIncrementalResolutionValidation = false; |
| 950 } | 944 } |
| 951 | 945 |
| 952 /** | 946 /** |
| 953 * A [ContextsChangedEvent] indicate what contexts were added or removed. | 947 * A [ContextsChangedEvent] indicate what contexts were added or removed. |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1079 * [packageUriResolver]. | 1073 * [packageUriResolver]. |
| 1080 */ | 1074 */ |
| 1081 SourceFactory _createSourceFactory(UriResolver packageUriResolver) { | 1075 SourceFactory _createSourceFactory(UriResolver packageUriResolver) { |
| 1082 List<UriResolver> resolvers = <UriResolver>[ | 1076 List<UriResolver> resolvers = <UriResolver>[ |
| 1083 new DartUriResolver(analysisServer.defaultSdk), | 1077 new DartUriResolver(analysisServer.defaultSdk), |
| 1084 new ResourceUriResolver(resourceProvider), | 1078 new ResourceUriResolver(resourceProvider), |
| 1085 packageUriResolver]; | 1079 packageUriResolver]; |
| 1086 return new SourceFactory(resolvers); | 1080 return new SourceFactory(resolvers); |
| 1087 } | 1081 } |
| 1088 } | 1082 } |
| OLD | NEW |