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

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

Issue 1783503004: Listen for context add/remove and unit invalidation to update the index. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/server/driver.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 3d2bab7dc496d347567a09c169792e47f2604f93..6abe0439ddd9c6b2ca57cd503b31e38e5a1141a6 100644
--- a/pkg/analysis_server/lib/src/analysis_server.dart
+++ b/pkg/analysis_server/lib/src/analysis_server.dart
@@ -39,6 +39,7 @@ import 'package:analyzer/src/generated/source_io.dart';
import 'package:analyzer/src/generated/utilities_general.dart';
import 'package:analyzer/src/task/dart.dart';
import 'package:analyzer/src/util/glob.dart';
+import 'package:analyzer/task/dart.dart';
import 'package:plugin/plugin.dart';
typedef void OptionUpdater(AnalysisOptionsImpl options);
@@ -83,7 +84,7 @@ class AnalysisServer {
* a 1 millisecond delay so that the VM and dart:io can deliver content
* to stdin. This should be removed once the underlying problem is fixed.
*/
- static int performOperationDelayFreqency = 25;
+ static int performOperationDelayFrequency = 25;
/**
* The options of this server instance.
@@ -354,6 +355,7 @@ class AnalysisServer {
_performance = performanceAfterStartup;
});
});
+ _setupIndexInvalidation();
Notification notification =
new ServerConnectedParams(VERSION).toNotification();
channel.sendNotification(notification);
@@ -675,23 +677,6 @@ class AnalysisServer {
return context.getErrors(source);
}
-// TODO(brianwilkerson) Add the following method after 'prioritySources' has
-// been added to InternalAnalysisContext.
-// /**
-// * Return a list containing the full names of all of the sources that are
-// * priority sources.
-// */
-// List<String> getPriorityFiles() {
-// List<String> priorityFiles = new List<String>();
-// folderMap.values.forEach((ContextDirectory directory) {
-// InternalAnalysisContext context = directory.context;
-// context.prioritySources.forEach((Source source) {
-// priorityFiles.add(source.fullName);
-// });
-// });
-// return priorityFiles;
-// }
-
/**
* Returns resolved [AstNode]s at the given [offset] of the given [file].
*
@@ -709,6 +694,23 @@ class AnalysisServer {
return nodes;
}
+// TODO(brianwilkerson) Add the following method after 'prioritySources' has
+// been added to InternalAnalysisContext.
+// /**
+// * Return a list containing the full names of all of the sources that are
+// * priority sources.
+// */
+// List<String> getPriorityFiles() {
+// List<String> priorityFiles = new List<String>();
+// folderMap.values.forEach((ContextDirectory directory) {
+// InternalAnalysisContext context = directory.context;
+// context.prioritySources.forEach((Source source) {
+// priorityFiles.add(source.fullName);
+// });
+// });
+// return priorityFiles;
+// }
+
/**
* Returns resolved [CompilationUnit]s of the Dart file with the given [path].
*
@@ -1452,14 +1454,42 @@ class AnalysisServer {
*/
int now = new DateTime.now().millisecondsSinceEpoch;
if (now > _nextPerformOperationDelayTime &&
- performOperationDelayFreqency > 0) {
- _nextPerformOperationDelayTime = now + performOperationDelayFreqency;
+ performOperationDelayFrequency > 0) {
+ _nextPerformOperationDelayTime = now + performOperationDelayFrequency;
new Future.delayed(new Duration(milliseconds: 1), performOperation);
} else {
new Future(performOperation);
}
performOperationPending = true;
}
+
+ /**
+ * Listen for context events and invalidate index.
+ *
+ * It is possible that this method will do more in the future, e.g. listening
+ * for summary information and linking pre-indexed packages into the index,
+ * but for now we only invalidate project specific index information.
+ */
+ void _setupIndexInvalidation() {
+ if (index2 == null) {
+ return;
+ }
+ onContextsChanged.listen((ContextsChangedEvent event) {
+ for (AnalysisContext context in event.added) {
+ context
+ .onResultChanged(RESOLVED_UNIT)
+ .listen((ResultChangedEvent event) {
+ if (event.wasInvalidated) {
+ LibrarySpecificUnit target = event.target;
+ index2.removeUnit(event.context, target.library, target.unit);
+ }
+ });
+ }
+ for (AnalysisContext context in event.removed) {
+ index2.removeContext(context);
+ }
+ });
+ }
}
class AnalysisServerOptions {
@@ -1662,7 +1692,7 @@ class ServerPerformance {
int slowRequestCount = 0;
/**
- * Log performation information about the given request.
+ * Log performance information about the given request.
*/
void logRequest(Request request) {
++requestCount;
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/server/driver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698