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

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

Issue 307533004: Send 'notification.errors' for all non-SDK files. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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/analysis_server.dart
diff --git a/pkg/analysis_server/lib/src/analysis_server.dart b/pkg/analysis_server/lib/src/analysis_server.dart
index 9ede7e812a2ebf9c02709d1e9bbdb4ecf77af295..c4dec1d8ca07cb3b1dbf73dd8fdc9149f9ae8179 100644
--- a/pkg/analysis_server/lib/src/analysis_server.dart
+++ b/pkg/analysis_server/lib/src/analysis_server.dart
@@ -8,6 +8,7 @@ import 'dart:async';
import 'package:analysis_server/src/analysis_logger.dart';
import 'package:analysis_server/src/channel.dart';
+import 'package:analysis_server/src/domain_analysis.dart';
import 'package:analysis_server/src/protocol.dart';
import 'package:analysis_server/src/resource.dart';
import 'package:analyzer/src/generated/ast.dart';
@@ -18,30 +19,27 @@ import 'package:analyzer/src/generated/sdk.dart';
import 'package:analyzer/src/generated/sdk_io.dart';
import 'package:analyzer/src/generated/source_io.dart';
+
+/**
+ * An instance of [DirectoryBasedDartSdk] that is shared between
+ * [AnalysisServer] instances to improve performance.
+ */
+final DirectoryBasedDartSdk SHARED_SDK = DirectoryBasedDartSdk.defaultSdk;
+
/**
* Instances of the class [AnalysisServer] implement a server that listens on a
* [CommunicationChannel] for analysis requests and process them.
*/
class AnalysisServer {
/**
- * The name of the notification of new errors associated with a source.
- */
- static const String ERROR_NOTIFICATION_NAME = 'context.errors';
-
- /**
- * The name of the contextId parameter.
- */
- static const String CONTEXT_ID_PARAM = 'contextId';
-
- /**
* The name of the parameter whose value is a list of errors.
*/
static const String ERRORS_PARAM = 'errors';
/**
- * The name of the parameter whose value is a source.
+ * The name of the parameter whose value is a file path.
*/
- static const String SOURCE_PARAM = 'source';
+ static const String FILE_PARAM = 'file';
/**
* The event name of the connected notification.
@@ -86,7 +84,7 @@ class AnalysisServer {
/**
* The current default [DartSdk].
*/
- DartSdk defaultSdk = DirectoryBasedDartSdk.defaultSdk;
+ DartSdk defaultSdk = SHARED_SDK;
Brian Wilkerson 2014/05/28 14:25:21 For discussion: I'm not sure this is the behavior
scheglov 2014/05/28 15:46:37 I agree. This API is just not implemented yet.
/**
* A table mapping [Folder]s to the [PubFolder]s associated with them.
@@ -215,27 +213,28 @@ class AnalysisServer {
_scheduleTask();
}
}
- // TODO(scheglov) implement for [PubFolder]
-// if (notices != null) {
-// sendNotices(contextId, notices);
-// }
+ if (notices != null) {
+ sendNotices(notices);
+ }
}
- // TODO(scheglov) rewrite for the new API.
-// /**
-// * Send the information in the given list of notices back to the client.
-// */
-// void sendNotices(String contextId, List<ChangeNotice> notices) {
-// for (int i = 0; i < notices.length; i++) {
-// ChangeNotice notice = notices[i];
-// Notification notification = new Notification(ERROR_NOTIFICATION_NAME);
-// notification.setParameter(CONTEXT_ID_PARAM, contextId);
-// notification.setParameter(SOURCE_PARAM, notice.source.encoding);
-// notification.setParameter(ERRORS_PARAM, notice.errors.map(
-// errorToJson).toList());
-// sendNotification(notification);
-// }
-// }
+ /**
+ * Send the information in the given list of notices back to the client.
+ */
+ void sendNotices(List<ChangeNotice> notices) {
+ for (int i = 0; i < notices.length; i++) {
+ ChangeNotice notice = notices[i];
+ Source source = notice.source;
+ // send "analysis.errors" notification
+ // TODO(scheglov) use subscriptions to determine if we should do this
+ if (!source.isInSystemLibrary) {
+ Notification notification = new Notification(AnalysisDomainHandler.ERRORS_NOTIFICATION);
+ notification.setParameter(FILE_PARAM, source.fullName);
+ notification.setParameter(ERRORS_PARAM, notice.errors.map(errorToJson).toList());
+ sendNotification(notification);
+ }
+ }
+ }
/**
* Implementation for `server.setAnalysisRoots`.
@@ -327,15 +326,20 @@ class AnalysisServer {
return context.getResolvedCompilationUnit2(unitSource, librarySources[0]);
}
+ /**
+ * Return `true` if all tasks are finished in this [AnalysisServer].
+ */
+ bool test_areTasksFinished() {
+ return contextWorkQueue.isEmpty;
+ }
+
static Map<String, Object> errorToJson(AnalysisError analysisError) {
// TODO(paulberry): move this function into the AnalysisError class.
-
- // TODO(paulberry): we really shouldn't be exposing errorCode.ordinal
- // outside the analyzer, since the ordinal numbers change whenever we
- // regenerate the analysis engine.
+ ErrorCode errorCode = analysisError.errorCode;
Map<String, Object> result = {
- 'source': analysisError.source.encoding,
- 'errorCode': (analysisError.errorCode as Enum).ordinal,
+ 'file': analysisError.source.fullName,
Brian Wilkerson 2014/05/28 14:25:21 These strings should be constants.
scheglov 2014/05/28 15:46:37 Will extract them in a separate CL.
+ // TODO(scheglov) add Enum.fullName ?
+ 'errorCode': '${errorCode.runtimeType}.${(errorCode as Enum).name}',
'offset': analysisError.offset,
'length': analysisError.length,
'message': analysisError.message
« no previous file with comments | « no previous file | pkg/analysis_server/test/analysis_server_test.dart » ('j') | pkg/analysis_server/test/domain_analysis_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698