| Index: pkg/analysis_server/lib/src/analysis_server.dart
|
| diff --git a/pkg/analysis_server/lib/src/analysis_server.dart b/pkg/analysis_server/lib/src/analysis_server.dart
|
| index 412dd64b8e035e230172c6b1bf600207fefe768b..ef7bfcb458cc3c9a7f9c8aec542791f906d3bdc3 100644
|
| --- a/pkg/analysis_server/lib/src/analysis_server.dart
|
| +++ b/pkg/analysis_server/lib/src/analysis_server.dart
|
| @@ -120,6 +120,12 @@ class AnalysisServer {
|
| Set<ServerService> serverServices = new Set<ServerService>();
|
|
|
| /**
|
| + * A table mapping [AnalysisService]s to the file paths for which these
|
| + * notifications should be sent.
|
| + */
|
| + Map<AnalysisService, Set<String>> analysisServices = <AnalysisService, Set<String>>{};
|
| +
|
| + /**
|
| * Initialize a newly created server to receive requests from and send
|
| * responses to the given [channel].
|
| */
|
| @@ -244,28 +250,37 @@ class AnalysisServer {
|
| ChangeNotice notice = notices[i];
|
| Source source = notice.source;
|
| CompilationUnit dartUnit = notice.compilationUnit;
|
| - // TODO(scheglov) use subscriptions to determine notifications to send
|
| + // TODO(scheglov) use default subscriptions
|
| + String file = source.fullName;
|
| + if (dartUnit != null) {
|
| + Set<String> files = analysisServices[AnalysisService.HIGHLIGHTS];
|
| + if (files != null && files.contains(file)) {
|
| + sendAnalysisNotificationHighlights(file, dartUnit);
|
| + }
|
| + }
|
| if (!source.isInSystemLibrary) {
|
| // errors
|
| - {
|
| - Notification notification = new Notification(NOTIFICATION_ERRORS);
|
| - notification.setParameter(FILE, source.fullName);
|
| - notification.setParameter(ERRORS, notice.errors.map(errorToJson).toList());
|
| - sendNotification(notification);
|
| - }
|
| - // highlights
|
| - if (dartUnit != null) {
|
| - Notification notification = new Notification(NOTIFICATION_HIGHLIGHTS);
|
| - notification.setParameter(FILE, source.fullName);
|
| - notification.setParameter(
|
| - REGIONS,
|
| - new DartUnitHighlightsComputer(dartUnit).compute());
|
| - sendNotification(notification);
|
| - }
|
| + sendAnalysisNotificationErrors(file, notice.errors);
|
| }
|
| }
|
| }
|
|
|
| + void sendAnalysisNotificationErrors(String file, List<AnalysisError> errors) {
|
| + Notification notification = new Notification(NOTIFICATION_ERRORS);
|
| + notification.setParameter(FILE, file);
|
| + notification.setParameter(ERRORS, errors.map(errorToJson).toList());
|
| + sendNotification(notification);
|
| + }
|
| +
|
| + void sendAnalysisNotificationHighlights(String file, CompilationUnit dartUnit) {
|
| + Notification notification = new Notification(NOTIFICATION_HIGHLIGHTS);
|
| + notification.setParameter(FILE, file);
|
| + notification.setParameter(
|
| + REGIONS,
|
| + new DartUnitHighlightsComputer(dartUnit).compute());
|
| + sendNotification(notification);
|
| + }
|
| +
|
| /**
|
| * Send status notification to the client. The `contextId` indicates
|
| * the current context being analyzed or `null` if analysis is complete.
|
| @@ -332,6 +347,33 @@ class AnalysisServer {
|
| }
|
|
|
| /**
|
| + * Implementation for `analysis.setSubscriptions`.
|
| + */
|
| + void setAnalysisSubscriptions(Map<AnalysisService, Set<String>> subscriptions) {
|
| + // send notifications for already analyzed sources
|
| + subscriptions.forEach((service, Set<String> newFiles) {
|
| + Set<String> oldFiles = analysisServices[service];
|
| + Set<String> todoFiles = oldFiles != null ? newFiles.difference(oldFiles) : newFiles;
|
| + for (String file in todoFiles) {
|
| + if (service == AnalysisService.ERRORS) {
|
| + Source source = _getSource(file);
|
| + AnalysisContext analysisContext = _getAnalysisContext(file);
|
| + List<AnalysisError> errors = analysisContext.getErrors(source).errors;
|
| + sendAnalysisNotificationErrors(file, errors);
|
| + }
|
| + if (service == AnalysisService.HIGHLIGHTS) {
|
| + CompilationUnit dartUnit = test_getResolvedCompilationUnit(file);
|
| + if (dartUnit != null) {
|
| + sendAnalysisNotificationHighlights(file, dartUnit);
|
| + }
|
| + }
|
| + }
|
| + });
|
| + // remember new subscriptions
|
| + this.analysisServices = subscriptions;
|
| + }
|
| +
|
| + /**
|
| * Return the [AnalysisContext] that is used to analyze the given [path].
|
| * Return `null` if there is no such context.
|
| */
|
|
|