| 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'; | |
| 8 import 'package:analysis_server/src/analysis_server.dart'; | 7 import 'package:analysis_server/src/analysis_server.dart'; |
| 9 import 'package:analysis_server/src/computer/computer_highlights.dart'; | 8 import 'package:analysis_server/src/computer/computer_highlights.dart'; |
| 10 import 'package:analysis_server/src/computer/computer_navigation.dart'; | 9 import 'package:analysis_server/src/computer/computer_navigation.dart'; |
| 11 import 'package:analysis_server/src/computer/computer_outline.dart'; | 10 import 'package:analysis_server/src/computer/computer_outline.dart'; |
| 12 import 'package:analysis_server/src/constants.dart'; | 11 import 'package:analysis_server/src/constants.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'; |
| 18 import 'package:analyzer/src/generated/index.dart'; |
| 17 import 'package:analyzer/src/generated/java_core.dart'; | 19 import 'package:analyzer/src/generated/java_core.dart'; |
| 18 import 'package:analyzer/src/generated/source.dart'; | 20 import 'package:analyzer/src/generated/source.dart'; |
| 19 | 21 |
| 20 | 22 |
| 23 Map<String, Object> errorToJson(AnalysisError analysisError) { |
| 24 // TODO(paulberry): move this function into the AnalysisError class. |
| 25 ErrorCode errorCode = analysisError.errorCode; |
| 26 Map<String, Object> result = { |
| 27 FILE: analysisError.source.fullName, |
| 28 // TODO(scheglov) add Enum.fullName ? |
| 29 ERROR_CODE: '${errorCode.runtimeType}.${(errorCode as Enum).name}', |
| 30 OFFSET: analysisError.offset, |
| 31 LENGTH: analysisError.length, |
| 32 MESSAGE: analysisError.message |
| 33 }; |
| 34 if (analysisError.correction != null) { |
| 35 result[CORRECTION] = analysisError.correction; |
| 36 } |
| 37 return result; |
| 38 } |
| 39 |
| 40 |
| 41 void sendAnalysisNotificationErrors(AnalysisServer server, String file, |
| 42 List<AnalysisError> errors) { |
| 43 Notification notification = new Notification(ANALYSIS_ERRORS); |
| 44 notification.setParameter(FILE, file); |
| 45 notification.setParameter(ERRORS, errors.map(errorToJson).toList()); |
| 46 server.sendNotification(notification); |
| 47 } |
| 48 |
| 49 |
| 50 void sendAnalysisNotificationHighlights(AnalysisServer server, String file, |
| 51 CompilationUnit dartUnit) { |
| 52 Notification notification = new Notification(ANALYSIS_HIGHLIGHTS); |
| 53 notification.setParameter(FILE, file); |
| 54 notification.setParameter(REGIONS, new DartUnitHighlightsComputer( |
| 55 dartUnit).compute()); |
| 56 server.sendNotification(notification); |
| 57 } |
| 58 |
| 59 |
| 60 void sendAnalysisNotificationNavigation(AnalysisServer server, String file, |
| 61 CompilationUnit dartUnit) { |
| 62 Notification notification = new Notification(ANALYSIS_NAVIGATION); |
| 63 notification.setParameter(FILE, file); |
| 64 notification.setParameter(REGIONS, new DartUnitNavigationComputer( |
| 65 dartUnit).compute()); |
| 66 server.sendNotification(notification); |
| 67 } |
| 68 |
| 69 |
| 70 void sendAnalysisNotificationOutline(AnalysisServer server, String file, |
| 71 CompilationUnit dartUnit) { |
| 72 Notification notification = new Notification(ANALYSIS_OUTLINE); |
| 73 notification.setParameter(FILE, file); |
| 74 notification.setParameter(OUTLINE, new DartUnitOutlineComputer( |
| 75 dartUnit).compute()); |
| 76 server.sendNotification(notification); |
| 77 } |
| 78 |
| 79 |
| 21 /** | 80 /** |
| 22 * Instances of [PerformAnalysisOperation] perform a single analysis task. | 81 * Instances of [PerformAnalysisOperation] perform a single analysis task. |
| 23 */ | 82 */ |
| 24 class PerformAnalysisOperation extends ServerOperation { | 83 class PerformAnalysisOperation extends ServerOperation { |
| 25 final AnalysisContext context; | 84 final AnalysisContext context; |
| 26 final bool isContinue; | 85 final bool isContinue; |
| 27 | 86 |
| 28 PerformAnalysisOperation(this.context, this.isContinue); | 87 PerformAnalysisOperation(this.context, this.isContinue); |
| 29 | 88 |
| 30 @override | 89 @override |
| (...skipping 14 matching lines...) Expand all Loading... |
| 45 // | 104 // |
| 46 // AnalysisResult result = context.performAnalysisTask((taskDescription) { | 105 // AnalysisResult result = context.performAnalysisTask((taskDescription) { |
| 47 // sendStatusNotification(context.toString(), taskDescription); | 106 // sendStatusNotification(context.toString(), taskDescription); |
| 48 // }); | 107 // }); |
| 49 // prepare results | 108 // prepare results |
| 50 AnalysisResult result = context.performAnalysisTask(); | 109 AnalysisResult result = context.performAnalysisTask(); |
| 51 List<ChangeNotice> notices = result.changeNotices; | 110 List<ChangeNotice> notices = result.changeNotices; |
| 52 if (notices == null) { | 111 if (notices == null) { |
| 53 return; | 112 return; |
| 54 } | 113 } |
| 55 // TODO(scheglov) remember known sources | 114 // process results |
| 56 // TODO(scheglov) index units | |
| 57 // TODO(scheglov) schedule notifications | |
| 58 sendNotices(server, notices); | 115 sendNotices(server, notices); |
| 116 updateIndex(server.index, notices); |
| 59 // continue analysis | 117 // continue analysis |
| 60 server.addOperation(new PerformAnalysisOperation(context, true)); | 118 server.addOperation(new PerformAnalysisOperation(context, true)); |
| 61 } | 119 } |
| 62 | 120 |
| 63 /** | 121 /** |
| 64 * Send the information in the given list of notices back to the client. | 122 * Send the information in the given list of notices back to the client. |
| 65 */ | 123 */ |
| 66 void sendNotices(AnalysisServer server, List<ChangeNotice> notices) { | 124 void sendNotices(AnalysisServer server, List<ChangeNotice> notices) { |
| 67 for (int i = 0; i < notices.length; i++) { | 125 for (int i = 0; i < notices.length; i++) { |
| 68 ChangeNotice notice = notices[i]; | 126 ChangeNotice notice = notices[i]; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 79 } | 137 } |
| 80 if (server.hasAnalysisSubscription(AnalysisService.OUTLINE, file)) { | 138 if (server.hasAnalysisSubscription(AnalysisService.OUTLINE, file)) { |
| 81 sendAnalysisNotificationOutline(server, file, dartUnit); | 139 sendAnalysisNotificationOutline(server, file, dartUnit); |
| 82 } | 140 } |
| 83 } | 141 } |
| 84 if (!source.isInSystemLibrary) { | 142 if (!source.isInSystemLibrary) { |
| 85 sendAnalysisNotificationErrors(server, file, notice.errors); | 143 sendAnalysisNotificationErrors(server, file, notice.errors); |
| 86 } | 144 } |
| 87 } | 145 } |
| 88 } | 146 } |
| 147 |
| 148 void updateIndex(Index index, List<ChangeNotice> notices) { |
| 149 if (index == null) { |
| 150 return; |
| 151 } |
| 152 for (ChangeNotice notice in notices) { |
| 153 // Dart |
| 154 { |
| 155 CompilationUnit dartUnit = notice.compilationUnit; |
| 156 if (dartUnit != null) { |
| 157 index.indexUnit(context, dartUnit); |
| 158 } |
| 159 } |
| 160 // HTML |
| 161 { |
| 162 HtmlUnit htmlUnit = notice.htmlUnit; |
| 163 if (htmlUnit != null) { |
| 164 index.indexHtmlUnit(context, htmlUnit); |
| 165 } |
| 166 } |
| 167 } |
| 168 } |
| 89 } | 169 } |
| 90 | |
| 91 | |
| 92 void sendAnalysisNotificationErrors(AnalysisServer server, | |
| 93 String file, List<AnalysisError> errors) { | |
| 94 Notification notification = new Notification(ANALYSIS_ERRORS); | |
| 95 notification.setParameter(FILE, file); | |
| 96 notification.setParameter(ERRORS, errors.map(errorToJson).toList()); | |
| 97 server.sendNotification(notification); | |
| 98 } | |
| 99 | |
| 100 | |
| 101 void sendAnalysisNotificationHighlights(AnalysisServer server, | |
| 102 String file, CompilationUnit dartUnit) { | |
| 103 Notification notification = new Notification(ANALYSIS_HIGHLIGHTS); | |
| 104 notification.setParameter(FILE, file); | |
| 105 notification.setParameter( | |
| 106 REGIONS, | |
| 107 new DartUnitHighlightsComputer(dartUnit).compute()); | |
| 108 server.sendNotification(notification); | |
| 109 } | |
| 110 | |
| 111 | |
| 112 void sendAnalysisNotificationNavigation(AnalysisServer server, | |
| 113 String file, CompilationUnit dartUnit) { | |
| 114 Notification notification = new Notification(ANALYSIS_NAVIGATION); | |
| 115 notification.setParameter(FILE, file); | |
| 116 notification.setParameter( | |
| 117 REGIONS, | |
| 118 new DartUnitNavigationComputer(dartUnit).compute()); | |
| 119 server.sendNotification(notification); | |
| 120 } | |
| 121 | |
| 122 | |
| 123 void sendAnalysisNotificationOutline(AnalysisServer server, | |
| 124 String file, CompilationUnit dartUnit) { | |
| 125 Notification notification = new Notification(ANALYSIS_OUTLINE); | |
| 126 notification.setParameter(FILE, file); | |
| 127 notification.setParameter( | |
| 128 OUTLINE, | |
| 129 new DartUnitOutlineComputer(dartUnit).compute()); | |
| 130 server.sendNotification(notification); | |
| 131 } | |
| 132 | |
| 133 | |
| 134 Map<String, Object> errorToJson(AnalysisError analysisError) { | |
| 135 // TODO(paulberry): move this function into the AnalysisError class. | |
| 136 ErrorCode errorCode = analysisError.errorCode; | |
| 137 Map<String, Object> result = { | |
| 138 'file': analysisError.source.fullName, | |
| 139 // TODO(scheglov) add Enum.fullName ? | |
| 140 'errorCode': '${errorCode.runtimeType}.${(errorCode as Enum).name}', | |
| 141 'offset': analysisError.offset, | |
| 142 'length': analysisError.length, | |
| 143 'message': analysisError.message | |
| 144 }; | |
| 145 if (analysisError.correction != null) { | |
| 146 result['correction'] = analysisError.correction; | |
| 147 } | |
| 148 return result; | |
| 149 } | |
| OLD | NEW |