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

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

Issue 1180843011: recompute package map when input file changes (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge Created 5 years, 6 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/test/context_manager_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « no previous file | pkg/analysis_server/test/context_manager_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698