| 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/analysis_server.dart'; | 7 import 'package:analysis_server/src/analysis_server.dart'; |
| 8 import 'package:analysis_server/src/computer/computer_highlights.dart'; | 8 import 'package:analysis_server/src/computer/computer_highlights.dart'; |
| 9 import 'package:analysis_server/src/computer/computer_navigation.dart'; | 9 import 'package:analysis_server/src/computer/computer_navigation.dart'; |
| 10 import 'package:analysis_server/src/computer/computer_outline.dart'; | 10 import 'package:analysis_server/src/computer/computer_outline.dart'; |
| 11 import 'package:analysis_server/src/constants.dart'; | 11 import 'package:analysis_server/src/constants.dart'; |
| 12 import 'package:analysis_server/src/operation/operation.dart'; | 12 import 'package:analysis_server/src/operation/operation.dart'; |
| 13 import 'package:analysis_server/src/protocol.dart'; | 13 import 'package:analysis_server/src/protocol.dart'; |
| 14 import 'package:analyzer/src/generated/ast.dart'; | 14 import 'package:analyzer/src/generated/ast.dart'; |
| 15 import 'package:analyzer/src/generated/engine.dart'; | 15 import 'package:analyzer/src/generated/engine.dart'; |
| 16 import 'package:analyzer/src/generated/error.dart'; | 16 import 'package:analyzer/src/generated/error.dart'; |
| 17 import 'package:analyzer/src/generated/html.dart'; | 17 import 'package:analyzer/src/generated/html.dart'; |
| 18 import 'package:analyzer/src/generated/index.dart'; | 18 import 'package:analyzer/src/generated/index.dart'; |
| 19 import 'package:analyzer/src/generated/java_core.dart'; | 19 import 'package:analyzer/src/generated/java_core.dart'; |
| 20 import 'package:analyzer/src/generated/source.dart'; | 20 import 'package:analyzer/src/generated/source.dart'; |
| 21 | 21 |
| 22 | 22 |
| 23 Map<String, Object> errorToJson(AnalysisError analysisError) { | 23 Map<String, Object> errorToJson(LineInfo lineInfo, AnalysisError analysisError) |
| 24 // TODO(paulberry): move this function into the AnalysisError class. | 24 { |
| 25 ErrorCode errorCode = analysisError.errorCode; | 25 ErrorCode errorCode = analysisError.errorCode; |
| 26 // prepare location |
| 27 int offset = analysisError.offset; |
| 28 Map<String, Object> location = { |
| 29 FILE: analysisError.source.fullName, |
| 30 OFFSET: offset, |
| 31 LENGTH: analysisError.length |
| 32 }; |
| 33 if (lineInfo != null) { |
| 34 LineInfo_Location lineLocation = lineInfo.getLocation(offset); |
| 35 if (lineLocation != null) { |
| 36 location[START_LINE] = lineLocation.lineNumber; |
| 37 location[START_COLUMN] = lineLocation.columnNumber; |
| 38 } |
| 39 } |
| 40 // fill JSON |
| 26 Map<String, Object> result = { | 41 Map<String, Object> result = { |
| 27 FILE: analysisError.source.fullName, | |
| 28 // TODO(scheglov) add Enum.fullName ? | 42 // TODO(scheglov) add Enum.fullName ? |
| 29 ERROR_CODE: '${errorCode.runtimeType}.${(errorCode as Enum).name}', | 43 ERROR_CODE: '${errorCode.runtimeType}.${(errorCode as Enum).name}', |
| 30 OFFSET: analysisError.offset, | 44 SEVERITY: errorCode.errorSeverity.name, |
| 31 LENGTH: analysisError.length, | 45 TYPE: errorCode.type.name, |
| 46 LOCATION: location, |
| 32 MESSAGE: analysisError.message | 47 MESSAGE: analysisError.message |
| 33 }; | 48 }; |
| 34 if (analysisError.correction != null) { | 49 if (analysisError.correction != null) { |
| 35 result[CORRECTION] = analysisError.correction; | 50 result[CORRECTION] = analysisError.correction; |
| 36 } | 51 } |
| 37 return result; | 52 return result; |
| 38 } | 53 } |
| 39 | 54 |
| 40 | 55 |
| 41 void sendAnalysisNotificationErrors(AnalysisServer server, String file, | 56 void sendAnalysisNotificationErrors(AnalysisServer server, String file, |
| 42 List<AnalysisError> errors) { | 57 LineInfo lineInfo, List<AnalysisError> errors) { |
| 43 Notification notification = new Notification(ANALYSIS_ERRORS); | 58 Notification notification = new Notification(ANALYSIS_ERRORS); |
| 44 notification.setParameter(FILE, file); | 59 notification.setParameter(FILE, file); |
| 45 notification.setParameter(ERRORS, errors.map(errorToJson).toList()); | 60 notification.setParameter(ERRORS, errors.map((error) { |
| 61 return errorToJson(lineInfo, error); |
| 62 }).toList()); |
| 46 server.sendNotification(notification); | 63 server.sendNotification(notification); |
| 47 } | 64 } |
| 48 | 65 |
| 49 | 66 |
| 50 void sendAnalysisNotificationHighlights(AnalysisServer server, String file, | 67 void sendAnalysisNotificationHighlights(AnalysisServer server, String file, |
| 51 CompilationUnit dartUnit) { | 68 CompilationUnit dartUnit) { |
| 52 Notification notification = new Notification(ANALYSIS_HIGHLIGHTS); | 69 Notification notification = new Notification(ANALYSIS_HIGHLIGHTS); |
| 53 notification.setParameter(FILE, file); | 70 notification.setParameter(FILE, file); |
| 54 notification.setParameter(REGIONS, new DartUnitHighlightsComputer( | 71 notification.setParameter(REGIONS, new DartUnitHighlightsComputer( |
| 55 dartUnit).compute()); | 72 dartUnit).compute()); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 server.addOperation(new PerformAnalysisOperation(context, true)); | 135 server.addOperation(new PerformAnalysisOperation(context, true)); |
| 119 } | 136 } |
| 120 | 137 |
| 121 /** | 138 /** |
| 122 * Send the information in the given list of notices back to the client. | 139 * Send the information in the given list of notices back to the client. |
| 123 */ | 140 */ |
| 124 void sendNotices(AnalysisServer server, List<ChangeNotice> notices) { | 141 void sendNotices(AnalysisServer server, List<ChangeNotice> notices) { |
| 125 for (int i = 0; i < notices.length; i++) { | 142 for (int i = 0; i < notices.length; i++) { |
| 126 ChangeNotice notice = notices[i]; | 143 ChangeNotice notice = notices[i]; |
| 127 Source source = notice.source; | 144 Source source = notice.source; |
| 145 String file = source.fullName; |
| 146 // Dart |
| 128 CompilationUnit dartUnit = notice.compilationUnit; | 147 CompilationUnit dartUnit = notice.compilationUnit; |
| 129 // TODO(scheglov) use default subscriptions | |
| 130 String file = source.fullName; | |
| 131 if (dartUnit != null) { | 148 if (dartUnit != null) { |
| 132 if (server.hasAnalysisSubscription(AnalysisService.HIGHLIGHTS, file)) { | 149 if (server.hasAnalysisSubscription(AnalysisService.HIGHLIGHTS, file)) { |
| 133 sendAnalysisNotificationHighlights(server, file, dartUnit); | 150 sendAnalysisNotificationHighlights(server, file, dartUnit); |
| 134 } | 151 } |
| 135 if (server.hasAnalysisSubscription(AnalysisService.NAVIGATION, file)) { | 152 if (server.hasAnalysisSubscription(AnalysisService.NAVIGATION, file)) { |
| 136 sendAnalysisNotificationNavigation(server, file, dartUnit); | 153 sendAnalysisNotificationNavigation(server, file, dartUnit); |
| 137 } | 154 } |
| 138 if (server.hasAnalysisSubscription(AnalysisService.OUTLINE, file)) { | 155 if (server.hasAnalysisSubscription(AnalysisService.OUTLINE, file)) { |
| 139 sendAnalysisNotificationOutline(server, file, dartUnit); | 156 sendAnalysisNotificationOutline(server, file, dartUnit); |
| 140 } | 157 } |
| 141 } | 158 } |
| 159 // TODO(scheglov) use default subscriptions |
| 142 if (!source.isInSystemLibrary) { | 160 if (!source.isInSystemLibrary) { |
| 143 sendAnalysisNotificationErrors(server, file, notice.errors); | 161 sendAnalysisNotificationErrors(server, file, notice.lineInfo, |
| 162 notice.errors); |
| 144 } | 163 } |
| 145 } | 164 } |
| 146 } | 165 } |
| 147 | 166 |
| 148 void updateIndex(Index index, List<ChangeNotice> notices) { | 167 void updateIndex(Index index, List<ChangeNotice> notices) { |
| 149 if (index == null) { | 168 if (index == null) { |
| 150 return; | 169 return; |
| 151 } | 170 } |
| 152 for (ChangeNotice notice in notices) { | 171 for (ChangeNotice notice in notices) { |
| 153 // Dart | 172 // Dart |
| 154 { | 173 { |
| 155 CompilationUnit dartUnit = notice.compilationUnit; | 174 CompilationUnit dartUnit = notice.compilationUnit; |
| 156 if (dartUnit != null) { | 175 if (dartUnit != null) { |
| 157 index.indexUnit(context, dartUnit); | 176 index.indexUnit(context, dartUnit); |
| 158 } | 177 } |
| 159 } | 178 } |
| 160 // HTML | 179 // HTML |
| 161 { | 180 { |
| 162 HtmlUnit htmlUnit = notice.htmlUnit; | 181 HtmlUnit htmlUnit = notice.htmlUnit; |
| 163 if (htmlUnit != null) { | 182 if (htmlUnit != null) { |
| 164 index.indexHtmlUnit(context, htmlUnit); | 183 index.indexHtmlUnit(context, htmlUnit); |
| 165 } | 184 } |
| 166 } | 185 } |
| 167 } | 186 } |
| 168 } | 187 } |
| 169 } | 188 } |
| OLD | NEW |