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

Unified Diff: pkg/analyzer/lib/src/context/context.dart

Issue 1776023002: Add AnalysisContext.onResultInvalidated(descriptor). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Update Analysis Server. 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
Index: pkg/analyzer/lib/src/context/context.dart
diff --git a/pkg/analyzer/lib/src/context/context.dart b/pkg/analyzer/lib/src/context/context.dart
index def719f33a6b86f433cc2600274ea11f8b930b00..2c4ef437f19fd6030062f1e5cc2cd5326aa749c9 100644
--- a/pkg/analyzer/lib/src/context/context.dart
+++ b/pkg/analyzer/lib/src/context/context.dart
@@ -194,6 +194,13 @@ class AnalysisContextImpl implements InternalAnalysisContext {
ResultProvider resultProvider;
/**
+ * The map of [ResultChangedEvent] controllers.
+ */
+ final Map<ResultDescriptor, StreamController<ResultChangedEvent>>
+ _resultChangedControllers =
+ <ResultDescriptor, StreamController<ResultChangedEvent>>{};
+
+ /**
* The most recently incrementally resolved source, or `null` when it was
* already validated, or the most recent change was not incrementally resolved.
*/
@@ -682,10 +689,19 @@ class AnalysisContextImpl implements InternalAnalysisContext {
if (sdk == null) {
return new AnalysisCache(<CachePartition>[_privatePartition]);
}
- return new AnalysisCache(<CachePartition>[
+ AnalysisCache cache = new AnalysisCache(<CachePartition>[
AnalysisEngine.instance.partitionManager.forSdk(sdk),
_privatePartition
]);
+ cache.onResultInvalidated.listen((InvalidatedResult event) {
+ StreamController<ResultChangedEvent> controller =
+ _resultChangedControllers[event.descriptor];
+ if (controller != null) {
+ controller.add(new ResultChangedEvent(
+ this, event.entry.target, event.descriptor, event.value, false));
+ }
+ });
+ return cache;
}
/**
@@ -1099,8 +1115,24 @@ class AnalysisContextImpl implements InternalAnalysisContext {
}
@override
+ Stream<ResultChangedEvent> onResultChanged(ResultDescriptor descriptor) {
+ driver.onResultComputed(descriptor).listen((ResultChangedEvent event) {
+ _resultChangedControllers[descriptor]?.add(event);
+ });
+ return _resultChangedControllers.putIfAbsent(descriptor, () {
+ return new StreamController<ResultChangedEvent>.broadcast(sync: true);
+ }).stream;
+ }
+
+ @override
+ @deprecated
Stream<ComputedResult> onResultComputed(ResultDescriptor descriptor) {
- return driver.onResultComputed(descriptor);
+ return onResultChanged(descriptor)
+ .where((event) => event.wasComputed)
+ .map((event) {
+ return new ComputedResult(
+ event.context, event.descriptor, event.target, event.value);
+ });
}
@override

Powered by Google App Engine
This is Rietveld 408576698