Chromium Code Reviews| 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 | 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'; |
| 11 import 'package:analysis_server/src/protocol.dart'; | 11 import 'package:analysis_server/src/protocol.dart'; |
| 12 import 'package:analyzer/src/generated/engine.dart'; | 12 import 'package:analyzer/src/generated/engine.dart'; |
| 13 import 'package:analyzer/src/generated/error.dart'; | |
| 13 | 14 |
| 14 /** | 15 /** |
| 15 * Instances of the class [AnalysisServer] implement a server that listens on a | 16 * Instances of the class [AnalysisServer] implement a server that listens on a |
| 16 * [CommunicationChannel] for analysis requests and process them. | 17 * [CommunicationChannel] for analysis requests and process them. |
| 17 */ | 18 */ |
| 18 class AnalysisServer { | 19 class AnalysisServer { |
| 19 /** | 20 /** |
| 20 * The name of the notification of new errors associated with a source. | 21 * The name of the notification of new errors associated with a source. |
| 21 */ | 22 */ |
| 22 static const String ERROR_NOTIFICATION_NAME = 'context.errors'; | 23 static const String ERROR_NOTIFICATION_NAME = 'context.errors'; |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 } | 182 } |
| 182 | 183 |
| 183 /** | 184 /** |
| 184 * Send the information in the given list of notices back to the client. | 185 * Send the information in the given list of notices back to the client. |
| 185 */ | 186 */ |
| 186 void sendNotices(List<ChangeNotice> notices) { | 187 void sendNotices(List<ChangeNotice> notices) { |
| 187 for (int i = 0; i < notices.length; i++) { | 188 for (int i = 0; i < notices.length; i++) { |
| 188 ChangeNotice notice = notices[i]; | 189 ChangeNotice notice = notices[i]; |
| 189 Notification notification = new Notification(ERROR_NOTIFICATION_NAME); | 190 Notification notification = new Notification(ERROR_NOTIFICATION_NAME); |
| 190 notification.setParameter(SOURCE_PARAM, notice.source.encoding); | 191 notification.setParameter(SOURCE_PARAM, notice.source.encoding); |
| 191 notification.setParameter(ERRORS_PARAM, notice.errors); | 192 notification.setParameter(ERRORS_PARAM, new List.from(notice.errors.map( |
|
scheglov
2014/04/23 19:20:56
You could use .map(f).toList().
Paul Berry
2014/04/23 20:36:26
Done.
| |
| 193 errorToJson))); | |
| 192 sendNotification(notification); | 194 sendNotification(notification); |
| 193 } | 195 } |
| 194 } | 196 } |
| 195 | 197 |
| 198 static Map<String, Object> errorToJson(AnalysisError analysisError) { | |
| 199 // TODO(paulberry): move this function into the AnalysisError class. | |
| 200 | |
| 201 // TODO(paulberry): add "ordinal" to errorCode interface so that this trick | |
| 202 // with dynamic is unnecessary. | |
|
scheglov
2014/04/23 19:20:56
You could probably cast it to Enum.
(errorCode as
Paul Berry
2014/04/23 20:36:26
Done.
| |
| 203 dynamic errorCode = analysisError.errorCode; | |
| 204 Map<String, Object> result = { | |
| 205 'source': analysisError.source.encoding, | |
| 206 'errorCode': errorCode.ordinal, | |
|
scheglov
2014/04/23 19:20:56
I don't think that using "ordinal" is valid at all
Paul Berry
2014/04/23 20:36:26
Good point. I've updated the TODO comment accordi
Brian Wilkerson
2014/04/24 15:44:05
There has been some discussion in the past about c
| |
| 207 'offset': analysisError.offset, | |
| 208 'length': analysisError.length, | |
| 209 'message': analysisError.message | |
| 210 }; | |
| 211 if (analysisError.correction != null) { | |
| 212 result['correction'] = analysisError.correction; | |
| 213 } | |
| 214 return result; | |
| 215 } | |
| 216 | |
| 196 /** | 217 /** |
| 197 * Send the given [notification] to the client. | 218 * Send the given [notification] to the client. |
| 198 */ | 219 */ |
| 199 void sendNotification(Notification notification) { | 220 void sendNotification(Notification notification) { |
| 200 channel.sendNotification(notification); | 221 channel.sendNotification(notification); |
| 201 } | 222 } |
| 202 | 223 |
| 203 void _scheduleTask() { | 224 void _scheduleTask() { |
| 204 new Future(performTask).catchError((ex, st) { | 225 new Future(performTask).catchError((ex, st) { |
| 205 AnalysisEngine.instance.logger.logError("${ex}\n${st}"); | 226 AnalysisEngine.instance.logger.logError("${ex}\n${st}"); |
| 206 }); | 227 }); |
| 207 } | 228 } |
| 208 } | 229 } |
| OLD | NEW |