Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(900)

Unified Diff: pkg/analysis_server/lib/src/analysis_server.dart

Issue 308923003: Initial implementation for 'analysis.setSubscriptions' API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/domain_analysis.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
*/
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/domain_analysis.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698