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

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

Issue 1919343002: Watch analysis roots separately. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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/socket_server.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/single_context_manager.dart
diff --git a/pkg/analysis_server/lib/src/single_context_manager.dart b/pkg/analysis_server/lib/src/single_context_manager.dart
index fc0704b90d0eb9ef4498fc5ad1a99c126dc59d2d..bdc3a6743994380ec3bb4d74baed505a8b019c58 100644
--- a/pkg/analysis_server/lib/src/single_context_manager.dart
+++ b/pkg/analysis_server/lib/src/single_context_manager.dart
@@ -95,9 +95,10 @@ class SingleContextManager implements ContextManager {
Folder contextFolder;
/**
- * The current [contextFolder] watch subscription.
+ * The current watch subscriptions.
*/
- StreamSubscription<WatchEvent> watchSubscription;
+ Map<String, StreamSubscription<WatchEvent>> watchSubscriptions =
+ new Map<String, StreamSubscription<WatchEvent>>();
/**
* The [packageResolverProvider] must not be `null`.
@@ -150,10 +151,7 @@ class SingleContextManager implements ContextManager {
context.dispose();
context = null;
contextFolder = null;
- if (watchSubscription != null) {
- watchSubscription.cancel();
- watchSubscription = null;
- }
+ _cancelCurrentWatchSubscriptions();
setRoots(includedPaths, excludedPaths, packageRoots);
}
}
@@ -174,13 +172,29 @@ class SingleContextManager implements ContextManager {
callbacks.moveContext(this.contextFolder, contextFolder);
}
this.contextFolder = contextFolder;
- // Start new watcher and cancel the old one.
- StreamSubscription<WatchEvent> watchSubscription =
- this.contextFolder.changes.listen(_handleWatchEvent);
- this.watchSubscription?.cancel();
- this.watchSubscription = watchSubscription;
}
}
+ // Start new watchers and cancel old ones.
+ {
+ Map<String, StreamSubscription<WatchEvent>> newSubscriptions =
+ new Map<String, StreamSubscription<WatchEvent>>();
+ for (String includedPath in includedPaths) {
+ Resource resource = resourceProvider.getResource(includedPath);
+ if (resource is Folder) {
+ // Extract the existing subscription or create a new one.
+ StreamSubscription<WatchEvent> subscription =
+ watchSubscriptions.remove(includedPath);
+ if (subscription == null) {
+ subscription = resource.changes.listen(_handleWatchEvent);
+ }
+ // Remember the subscription.
+ newSubscriptions[includedPath] = subscription;
+ }
+ _cancelCurrentWatchSubscriptions();
+ this.watchSubscriptions = newSubscriptions;
+ }
+ }
+ // Create or update the analysis context.
if (context == null) {
UriResolver packageResolver = packageResolverProvider();
context = callbacks.addContext(contextFolder, new AnalysisOptionsImpl(),
@@ -242,6 +256,14 @@ class SingleContextManager implements ContextManager {
return changeSet;
}
+ void _cancelCurrentWatchSubscriptions() {
+ for (StreamSubscription<WatchEvent> subscription
+ in watchSubscriptions.values) {
+ subscription.cancel();
+ }
+ watchSubscriptions.clear();
+ }
+
String _commonPrefix(List<String> paths) {
if (paths.isEmpty) {
return '';
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/socket_server.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698