Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library operation.analysis; | |
| 6 | |
| 7 import 'package:analysis_server/src/operation/operation.dart'; | |
| 8 import 'package:analysis_server/src/analysis_server.dart'; | |
| 9 import 'package:analysis_server/src/computers.dart'; | |
| 10 import 'package:analysis_server/src/constants.dart'; | |
| 11 import 'package:analysis_server/src/protocol.dart'; | |
| 12 import 'package:analyzer/src/generated/ast.dart'; | |
| 13 import 'package:analyzer/src/generated/engine.dart'; | |
| 14 import 'package:analyzer/src/generated/error.dart'; | |
| 15 import 'package:analyzer/src/generated/java_core.dart'; | |
| 16 import 'package:analyzer/src/generated/source.dart'; | |
| 17 | |
| 18 | |
| 19 /** | |
| 20 * Instances of [PerformAnalysisOperation] perform a single analysis task. | |
| 21 */ | |
| 22 class PerformAnalysisOperation extends ServerOperation { | |
| 23 final AnalysisContext context; | |
| 24 final bool isContinue; | |
| 25 | |
| 26 PerformAnalysisOperation(this.context, this.isContinue); | |
| 27 | |
| 28 @override | |
| 29 ServerOperationPriority get priority { | |
| 30 if (isContinue) { | |
| 31 return ServerOperationPriority.ANALYSIS_CONTINUE; | |
| 32 } else { | |
| 33 return ServerOperationPriority.ANALYSIS; | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 @override | |
| 38 void perform(AnalysisServer server) { | |
| 39 // | |
| 40 // TODO(brianwilkerson) Add an optional function-valued parameter to | |
| 41 // performAnalysisTask that will be called when the task has been computed | |
| 42 // but before it is performed and send notification in the function: | |
| 43 // | |
| 44 // AnalysisResult result = context.performAnalysisTask((taskDescription) { | |
| 45 // sendStatusNotification(context.toString(), taskDescription); | |
| 46 // }); | |
| 47 // prepare results | |
| 48 AnalysisResult result = context.performAnalysisTask(); | |
| 49 List<ChangeNotice> notices = result.changeNotices; | |
| 50 if (notices == null) { | |
| 51 return; | |
| 52 } | |
| 53 // TODO(scheglov) remember known sources | |
| 54 // TODO(scheglov) index units | |
| 55 // TODO(scheglov) schedule notifications | |
| 56 sendNotices(server, notices); | |
| 57 // continue analysis | |
| 58 server.addOperation(new PerformAnalysisOperation(context, true)); | |
| 59 } | |
| 60 | |
| 61 /** | |
| 62 * Send the information in the given list of notices back to the client. | |
| 63 */ | |
| 64 void sendNotices(AnalysisServer server, List<ChangeNotice> notices) { | |
| 65 for (int i = 0; i < notices.length; i++) { | |
| 66 ChangeNotice notice = notices[i]; | |
| 67 Source source = notice.source; | |
| 68 CompilationUnit dartUnit = notice.compilationUnit; | |
| 69 // TODO(scheglov) use default subscriptions | |
| 70 String file = source.fullName; | |
| 71 if (dartUnit != null) { | |
| 72 if (server.hasAnalysisSubscription(AnalysisService.HIGHLIGHTS, file)) { | |
| 73 sendAnalysisNotificationHighlights(server, file, dartUnit); | |
| 74 } | |
| 75 } | |
| 76 if (!source.isInSystemLibrary) { | |
| 77 sendAnalysisNotificationErrors(server, file, notice.errors); | |
| 78 } | |
| 79 } | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 void sendAnalysisNotificationErrors(AnalysisServer server, | |
|
Brian Wilkerson
2014/06/02 20:12:58
Have I ever told you how much I dislike top-level
scheglov
2014/06/02 20:38:09
Yes, you have :-)
| |
| 84 String file, List<AnalysisError> errors) { | |
| 85 Notification notification = new Notification(NOTIFICATION_ERRORS); | |
| 86 notification.setParameter(FILE, file); | |
| 87 notification.setParameter(ERRORS, errors.map(errorToJson).toList()); | |
| 88 server.sendNotification(notification); | |
| 89 } | |
| 90 | |
| 91 void sendAnalysisNotificationHighlights(AnalysisServer server, | |
| 92 String file, CompilationUnit dartUnit) { | |
| 93 Notification notification = new Notification(NOTIFICATION_HIGHLIGHTS); | |
| 94 notification.setParameter(FILE, file); | |
| 95 notification.setParameter( | |
| 96 REGIONS, | |
| 97 new DartUnitHighlightsComputer(dartUnit).compute()); | |
| 98 server.sendNotification(notification); | |
| 99 } | |
| 100 | |
| 101 Map<String, Object> errorToJson(AnalysisError analysisError) { | |
| 102 // TODO(paulberry): move this function into the AnalysisError class. | |
| 103 ErrorCode errorCode = analysisError.errorCode; | |
| 104 Map<String, Object> result = { | |
| 105 'file': analysisError.source.fullName, | |
| 106 // TODO(scheglov) add Enum.fullName ? | |
| 107 'errorCode': '${errorCode.runtimeType}.${(errorCode as Enum).name}', | |
| 108 'offset': analysisError.offset, | |
| 109 'length': analysisError.length, | |
| 110 'message': analysisError.message | |
| 111 }; | |
| 112 if (analysisError.correction != null) { | |
| 113 result['correction'] = analysisError.correction; | |
| 114 } | |
| 115 return result; | |
| 116 } | |
| OLD | NEW |