| 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 operation.analysis; | 5 library operation.analysis; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/operation/operation.dart'; | 7 import 'package:analysis_server/src/operation/operation.dart'; |
| 8 import 'package:analysis_server/src/analysis_server.dart'; | 8 import 'package:analysis_server/src/analysis_server.dart'; |
| 9 import 'package:analysis_server/src/computers.dart'; | 9 import 'package:analysis_server/src/computers.dart'; |
| 10 import 'package:analysis_server/src/constants.dart'; | 10 import 'package:analysis_server/src/constants.dart'; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 for (int i = 0; i < notices.length; i++) { | 65 for (int i = 0; i < notices.length; i++) { |
| 66 ChangeNotice notice = notices[i]; | 66 ChangeNotice notice = notices[i]; |
| 67 Source source = notice.source; | 67 Source source = notice.source; |
| 68 CompilationUnit dartUnit = notice.compilationUnit; | 68 CompilationUnit dartUnit = notice.compilationUnit; |
| 69 // TODO(scheglov) use default subscriptions | 69 // TODO(scheglov) use default subscriptions |
| 70 String file = source.fullName; | 70 String file = source.fullName; |
| 71 if (dartUnit != null) { | 71 if (dartUnit != null) { |
| 72 if (server.hasAnalysisSubscription(AnalysisService.HIGHLIGHTS, file)) { | 72 if (server.hasAnalysisSubscription(AnalysisService.HIGHLIGHTS, file)) { |
| 73 sendAnalysisNotificationHighlights(server, file, dartUnit); | 73 sendAnalysisNotificationHighlights(server, file, dartUnit); |
| 74 } | 74 } |
| 75 if (server.hasAnalysisSubscription(AnalysisService.NAVIGATION, file)) { |
| 76 sendAnalysisNotificationNavigation(server, file, dartUnit); |
| 77 } |
| 75 } | 78 } |
| 76 if (!source.isInSystemLibrary) { | 79 if (!source.isInSystemLibrary) { |
| 77 sendAnalysisNotificationErrors(server, file, notice.errors); | 80 sendAnalysisNotificationErrors(server, file, notice.errors); |
| 78 } | 81 } |
| 79 } | 82 } |
| 80 } | 83 } |
| 81 } | 84 } |
| 82 | 85 |
| 83 void sendAnalysisNotificationErrors(AnalysisServer server, | 86 void sendAnalysisNotificationErrors(AnalysisServer server, |
| 84 String file, List<AnalysisError> errors) { | 87 String file, List<AnalysisError> errors) { |
| 85 Notification notification = new Notification(NOTIFICATION_ERRORS); | 88 Notification notification = new Notification(NOTIFICATION_ERRORS); |
| 86 notification.setParameter(FILE, file); | 89 notification.setParameter(FILE, file); |
| 87 notification.setParameter(ERRORS, errors.map(errorToJson).toList()); | 90 notification.setParameter(ERRORS, errors.map(errorToJson).toList()); |
| 88 server.sendNotification(notification); | 91 server.sendNotification(notification); |
| 89 } | 92 } |
| 90 | 93 |
| 91 void sendAnalysisNotificationHighlights(AnalysisServer server, | 94 void sendAnalysisNotificationHighlights(AnalysisServer server, |
| 92 String file, CompilationUnit dartUnit) { | 95 String file, CompilationUnit dartUnit) { |
| 93 Notification notification = new Notification(NOTIFICATION_HIGHLIGHTS); | 96 Notification notification = new Notification(NOTIFICATION_HIGHLIGHTS); |
| 94 notification.setParameter(FILE, file); | 97 notification.setParameter(FILE, file); |
| 95 notification.setParameter( | 98 notification.setParameter( |
| 96 REGIONS, | 99 REGIONS, |
| 97 new DartUnitHighlightsComputer(dartUnit).compute()); | 100 new DartUnitHighlightsComputer(dartUnit).compute()); |
| 98 server.sendNotification(notification); | 101 server.sendNotification(notification); |
| 99 } | 102 } |
| 100 | 103 |
| 104 void sendAnalysisNotificationNavigation(AnalysisServer server, |
| 105 String file, CompilationUnit dartUnit) { |
| 106 Notification notification = new Notification(NOTIFICATION_NAVIGATION); |
| 107 notification.setParameter(FILE, file); |
| 108 notification.setParameter( |
| 109 REGIONS, |
| 110 new DartUnitNavigationComputer(dartUnit).compute()); |
| 111 server.sendNotification(notification); |
| 112 } |
| 113 |
| 101 Map<String, Object> errorToJson(AnalysisError analysisError) { | 114 Map<String, Object> errorToJson(AnalysisError analysisError) { |
| 102 // TODO(paulberry): move this function into the AnalysisError class. | 115 // TODO(paulberry): move this function into the AnalysisError class. |
| 103 ErrorCode errorCode = analysisError.errorCode; | 116 ErrorCode errorCode = analysisError.errorCode; |
| 104 Map<String, Object> result = { | 117 Map<String, Object> result = { |
| 105 'file': analysisError.source.fullName, | 118 'file': analysisError.source.fullName, |
| 106 // TODO(scheglov) add Enum.fullName ? | 119 // TODO(scheglov) add Enum.fullName ? |
| 107 'errorCode': '${errorCode.runtimeType}.${(errorCode as Enum).name}', | 120 'errorCode': '${errorCode.runtimeType}.${(errorCode as Enum).name}', |
| 108 'offset': analysisError.offset, | 121 'offset': analysisError.offset, |
| 109 'length': analysisError.length, | 122 'length': analysisError.length, |
| 110 'message': analysisError.message | 123 'message': analysisError.message |
| 111 }; | 124 }; |
| 112 if (analysisError.correction != null) { | 125 if (analysisError.correction != null) { |
| 113 result['correction'] = analysisError.correction; | 126 result['correction'] = analysisError.correction; |
| 114 } | 127 } |
| 115 return result; | 128 return result; |
| 116 } | 129 } |
| OLD | NEW |