Index: pkg/analysis_server/lib/src/context_manager.dart |
diff --git a/pkg/analysis_server/lib/src/context_manager.dart b/pkg/analysis_server/lib/src/context_manager.dart |
index bfa8cb6fbd0c7fd383aefbde12a7d6ab2d3be71c..c4c7e1f71d0676af54689de14f06b54f66b35da4 100644 |
--- a/pkg/analysis_server/lib/src/context_manager.dart |
+++ b/pkg/analysis_server/lib/src/context_manager.dart |
@@ -387,11 +387,22 @@ abstract class ContextManager { |
} |
/** |
+ * Cancel all dependency subscriptions for the given context. |
+ */ |
+ void _cancelDependencySubscriptions(_ContextInfo info) { |
+ for (StreamSubscription<WatchEvent> s in info.dependencySubscriptions) { |
+ s.cancel(); |
+ } |
+ info.dependencySubscriptions.clear(); |
+ } |
+ |
+ /** |
* Compute the appropriate package URI resolver for [folder], and store |
* dependency information in [info]. Return `null` if no package map can |
* be computed. |
*/ |
UriResolver _computePackageUriResolver(Folder folder, _ContextInfo info) { |
+ _cancelDependencySubscriptions(info); |
if (info.packageRoot != null) { |
info.packageMapInfo = null; |
JavaFile packagesDir = new JavaFile(info.packageRoot); |
@@ -425,6 +436,19 @@ abstract class ContextManager { |
_packageMapProvider.computePackageMap(folder, info.packageMapInfo); |
}); |
endComputePackageMap(); |
+ for (String dependencyPath in packageMapInfo.dependencies) { |
+ Resource resource = resourceProvider.getResource(dependencyPath); |
+ if (resource is File) { |
+ info.dependencySubscriptions.add(resource.changes |
+ .listen((WatchEvent event) { |
+ if (info.packageMapInfo != null && |
+ info.packageMapInfo.isChangedDependency( |
+ dependencyPath, resourceProvider)) { |
+ _recomputePackageUriResolver(info); |
+ } |
+ })); |
+ } |
+ } |
info.packageMapInfo = packageMapInfo; |
if (packageMapInfo.packageMap == null) { |
return null; |
@@ -513,7 +537,9 @@ abstract class ContextManager { |
* Clean up and destroy the context associated with the given folder. |
*/ |
void _destroyContext(Folder folder) { |
- _contexts[folder].changeSubscription.cancel(); |
+ _ContextInfo info = _contexts[folder]; |
+ info.changeSubscription.cancel(); |
+ _cancelDependencySubscriptions(info); |
removeContext(folder); |
_contexts.remove(folder); |
} |
@@ -749,6 +775,13 @@ class _ContextInfo { |
StreamSubscription<WatchEvent> changeSubscription; |
/** |
+ * Stream subscriptions we are using to watch the files |
+ * used to determine the package map. |
+ */ |
+ final List<StreamSubscription<WatchEvent>> dependencySubscriptions = |
+ <StreamSubscription<WatchEvent>>[]; |
+ |
+ /** |
* The analysis context that was created for the [folder]. |
*/ |
AnalysisContext context; |