Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(848)

Unified Diff: pkg/analysis_server/lib/src/operation/operation_analysis.dart

Issue 311653002: Extract analysis/notifications into a separate operation/file. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Tweak for the test method name. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/lib/src/operation/operation_analysis.dart
diff --git a/pkg/analysis_server/lib/src/operation/operation_analysis.dart b/pkg/analysis_server/lib/src/operation/operation_analysis.dart
new file mode 100644
index 0000000000000000000000000000000000000000..ceac59de6167675b5e4a24c2f712df5ee646b64e
--- /dev/null
+++ b/pkg/analysis_server/lib/src/operation/operation_analysis.dart
@@ -0,0 +1,116 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library operation.analysis;
+
+import 'package:analysis_server/src/operation/operation.dart';
+import 'package:analysis_server/src/analysis_server.dart';
+import 'package:analysis_server/src/computers.dart';
+import 'package:analysis_server/src/constants.dart';
+import 'package:analysis_server/src/protocol.dart';
+import 'package:analyzer/src/generated/ast.dart';
+import 'package:analyzer/src/generated/engine.dart';
+import 'package:analyzer/src/generated/error.dart';
+import 'package:analyzer/src/generated/java_core.dart';
+import 'package:analyzer/src/generated/source.dart';
+
+
+/**
+ * Instances of [PerformAnalysisOperation] perform a single analysis task.
+ */
+class PerformAnalysisOperation extends ServerOperation {
+ final AnalysisContext context;
+ final bool isContinue;
+
+ PerformAnalysisOperation(this.context, this.isContinue);
+
+ @override
+ ServerOperationPriority get priority {
+ if (isContinue) {
+ return ServerOperationPriority.ANALYSIS_CONTINUE;
+ } else {
+ return ServerOperationPriority.ANALYSIS;
+ }
+ }
+
+ @override
+ void perform(AnalysisServer server) {
+ //
+ // TODO(brianwilkerson) Add an optional function-valued parameter to
+ // performAnalysisTask that will be called when the task has been computed
+ // but before it is performed and send notification in the function:
+ //
+ // AnalysisResult result = context.performAnalysisTask((taskDescription) {
+ // sendStatusNotification(context.toString(), taskDescription);
+ // });
+ // prepare results
+ AnalysisResult result = context.performAnalysisTask();
+ List<ChangeNotice> notices = result.changeNotices;
+ if (notices == null) {
+ return;
+ }
+ // TODO(scheglov) remember known sources
+ // TODO(scheglov) index units
+ // TODO(scheglov) schedule notifications
+ sendNotices(server, notices);
+ // continue analysis
+ server.addOperation(new PerformAnalysisOperation(context, true));
+ }
+
+ /**
+ * Send the information in the given list of notices back to the client.
+ */
+ void sendNotices(AnalysisServer server, List<ChangeNotice> notices) {
+ for (int i = 0; i < notices.length; i++) {
+ ChangeNotice notice = notices[i];
+ Source source = notice.source;
+ CompilationUnit dartUnit = notice.compilationUnit;
+ // TODO(scheglov) use default subscriptions
+ String file = source.fullName;
+ if (dartUnit != null) {
+ if (server.hasAnalysisSubscription(AnalysisService.HIGHLIGHTS, file)) {
+ sendAnalysisNotificationHighlights(server, file, dartUnit);
+ }
+ }
+ if (!source.isInSystemLibrary) {
+ sendAnalysisNotificationErrors(server, file, notice.errors);
+ }
+ }
+ }
+}
+
+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 :-)
+ String file, List<AnalysisError> errors) {
+ Notification notification = new Notification(NOTIFICATION_ERRORS);
+ notification.setParameter(FILE, file);
+ notification.setParameter(ERRORS, errors.map(errorToJson).toList());
+ server.sendNotification(notification);
+}
+
+void sendAnalysisNotificationHighlights(AnalysisServer server,
+ String file, CompilationUnit dartUnit) {
+ Notification notification = new Notification(NOTIFICATION_HIGHLIGHTS);
+ notification.setParameter(FILE, file);
+ notification.setParameter(
+ REGIONS,
+ new DartUnitHighlightsComputer(dartUnit).compute());
+ server.sendNotification(notification);
+}
+
+Map<String, Object> errorToJson(AnalysisError analysisError) {
+ // TODO(paulberry): move this function into the AnalysisError class.
+ ErrorCode errorCode = analysisError.errorCode;
+ Map<String, Object> result = {
+ 'file': analysisError.source.fullName,
+ // TODO(scheglov) add Enum.fullName ?
+ 'errorCode': '${errorCode.runtimeType}.${(errorCode as Enum).name}',
+ 'offset': analysisError.offset,
+ 'length': analysisError.length,
+ 'message': analysisError.message
+ };
+ if (analysisError.correction != null) {
+ result['correction'] = analysisError.correction;
+ }
+ return result;
+}

Powered by Google App Engine
This is Rietveld 408576698