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

Side by Side Diff: pkg/analysis_server/lib/src/analysis_server.dart

Issue 299513003: improve analysis server notifications (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: remove analysis.complete notification 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/domain_server.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 8
9 import 'package:analysis_server/src/analysis_logger.dart'; 9 import 'package:analysis_server/src/analysis_logger.dart';
10 import 'package:analysis_server/src/channel.dart'; 10 import 'package:analysis_server/src/channel.dart';
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 * server. 61 * server.
62 */ 62 */
63 List<RequestHandler> handlers; 63 List<RequestHandler> handlers;
64 64
65 /** 65 /**
66 * A table mapping context id's to the analysis contexts associated with them. 66 * A table mapping context id's to the analysis contexts associated with them.
67 */ 67 */
68 final Map<String, AnalysisContext> contextMap = new Map<String, AnalysisContex t>(); 68 final Map<String, AnalysisContext> contextMap = new Map<String, AnalysisContex t>();
69 69
70 /** 70 /**
71 * A table mapping analysis contexts to the context id's associated with them.
72 */
73 final Map<AnalysisContext, String> contextIdMap = new Map<AnalysisContext, Str ing>();
74
75 /**
71 * A list of the analysis contexts for which analysis work needs to be 76 * A list of the analysis contexts for which analysis work needs to be
72 * performed. 77 * performed.
73 * 78 *
74 * Invariant: when this list is non-empty, there is exactly one pending call 79 * Invariant: when this list is non-empty, there is exactly one pending call
75 * to [performTask] on the event queue. When this list is empty, there are 80 * to [performTask] on the event queue. When this list is empty, there are
76 * no calls to [performTask] on the event queue. 81 * no calls to [performTask] on the event queue.
77 */ 82 */
78 final List<AnalysisContext> contextWorkQueue = new List<AnalysisContext>(); 83 final List<AnalysisContext> contextWorkQueue = new List<AnalysisContext>();
79 84
80 /** 85 /**
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 contextWorkQueue.clear(); 160 contextWorkQueue.clear();
156 } 161 }
157 if (contextWorkQueue.isEmpty) { 162 if (contextWorkQueue.isEmpty) {
158 // Nothing to do. 163 // Nothing to do.
159 return; 164 return;
160 } 165 }
161 // 166 //
162 // Look for a context that has work to be done and then perform one task. 167 // Look for a context that has work to be done and then perform one task.
163 // 168 //
164 List<ChangeNotice> notices = null; 169 List<ChangeNotice> notices = null;
170 String contextId;
165 try { 171 try {
166 AnalysisContext context = contextWorkQueue[0]; 172 AnalysisContext context = contextWorkQueue[0];
173 contextId = contextIdMap[context];
167 AnalysisResult result = context.performAnalysisTask(); 174 AnalysisResult result = context.performAnalysisTask();
168 notices = result.changeNotices; 175 notices = result.changeNotices;
169 } finally { 176 } finally {
170 if (notices == null) { 177 if (notices == null) {
171 // Either we have no more work to do for this context, or there was an 178 // Either we have no more work to do for this context, or there was an
172 // unhandled exception trying to perform the analysis. In either case, 179 // unhandled exception trying to perform the analysis. In either case,
173 // remove the context form the work queue so we won't try to do more 180 // remove the context form the work queue so we won't try to do more
174 // analysis on it. 181 // analysis on it.
175 contextWorkQueue.removeAt(0); 182 contextWorkQueue.removeAt(0);
176 } 183 }
177 // 184 //
178 // Schedule this method to be run again if there is any more work to be 185 // Schedule this method to be run again if there is any more work to be
179 // done. 186 // done.
180 // 187 //
181 if (!contextWorkQueue.isEmpty) { 188 if (!contextWorkQueue.isEmpty) {
182 _scheduleTask(); 189 _scheduleTask();
183 } 190 }
184 } 191 }
185 if (notices != null) { 192 if (notices != null) {
186 sendNotices(notices); 193 sendNotices(contextId, notices);
187 } 194 }
188 } 195 }
189 196
190 /** 197 /**
191 * Send the information in the given list of notices back to the client. 198 * Send the information in the given list of notices back to the client.
192 */ 199 */
193 void sendNotices(List<ChangeNotice> notices) { 200 void sendNotices(String contextId, List<ChangeNotice> notices) {
194 for (int i = 0; i < notices.length; i++) { 201 for (int i = 0; i < notices.length; i++) {
195 ChangeNotice notice = notices[i]; 202 ChangeNotice notice = notices[i];
196 Notification notification = new Notification(ERROR_NOTIFICATION_NAME); 203 Notification notification = new Notification(ERROR_NOTIFICATION_NAME);
204 notification.setParameter(CONTEXT_ID_PARAM, contextId);
197 notification.setParameter(SOURCE_PARAM, notice.source.encoding); 205 notification.setParameter(SOURCE_PARAM, notice.source.encoding);
198 notification.setParameter(ERRORS_PARAM, notice.errors.map( 206 notification.setParameter(ERRORS_PARAM, notice.errors.map(
199 errorToJson).toList()); 207 errorToJson).toList());
200 sendNotification(notification); 208 sendNotification(notification);
201 } 209 }
202 } 210 }
203 211
204 static Map<String, Object> errorToJson(AnalysisError analysisError) { 212 static Map<String, Object> errorToJson(AnalysisError analysisError) {
205 // TODO(paulberry): move this function into the AnalysisError class. 213 // TODO(paulberry): move this function into the AnalysisError class.
206 214
(...skipping 19 matching lines...) Expand all
226 void sendNotification(Notification notification) { 234 void sendNotification(Notification notification) {
227 channel.sendNotification(notification); 235 channel.sendNotification(notification);
228 } 236 }
229 237
230 void _scheduleTask() { 238 void _scheduleTask() {
231 new Future(performTask).catchError((ex, st) { 239 new Future(performTask).catchError((ex, st) {
232 AnalysisEngine.instance.logger.logError("${ex}\n${st}"); 240 AnalysisEngine.instance.logger.logError("${ex}\n${st}");
233 }); 241 });
234 } 242 }
235 } 243 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/domain_server.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698