@@ -49,11 +49,15 @@ class ResolverImpl implements Resolver {
49
49
/// Completer for wrapping up the current phase.
50
50
Completer _currentPhaseComplete;
51
51
52
+ /// Whether or not we are using a shared sources cache.
53
+ final bool _usingSharedSources;
54
+
52
55
/// Creates a resolver with a given [sdk] implementation for resolving
53
56
/// `dart:*` imports.
54
57
ResolverImpl (DartSdk sdk, DartUriResolver dartUriResolver,
55
58
{AnalysisOptions options, Map <AssetId , AssetBasedSource > sources})
56
- : sources = sources ?? < AssetId , AssetBasedSource > {} {
59
+ : _usingSharedSources = sources != null ,
60
+ sources = sources ?? < AssetId , AssetBasedSource > {} {
57
61
if (options == null ) {
58
62
options = new AnalysisOptionsImpl ()
59
63
..cacheSize = 256 // # of sources to cache ASTs for.
@@ -144,12 +148,17 @@ class ResolverImpl implements Resolver {
144
148
return visiting.future.then ((_) {
145
149
var changeSet = new ChangeSet ();
146
150
toUpdate.forEach ((pending) => pending.apply (changeSet));
147
- var unreachableAssets =
148
- sources.keys.toSet ().difference (visited).map ((id) => sources[id]);
149
- for (var unreachable in unreachableAssets) {
150
- changeSet.removedSource (unreachable);
151
- unreachable.updateContents (null );
152
- sources.remove (unreachable.assetId);
151
+
152
+ // If we aren't using shared sources, then remove from the cache any
153
+ // sources which are no longer reachable.
154
+ if (! _usingSharedSources) {
155
+ var unreachableAssets =
156
+ sources.keys.toSet ().difference (visited).map ((id) => sources[id]);
157
+ for (var unreachable in unreachableAssets) {
158
+ changeSet.removedSource (unreachable);
159
+ unreachable.updateContents (null );
160
+ sources.remove (unreachable.assetId);
161
+ }
153
162
}
154
163
155
164
// Update the analyzer context with the latest sources
0 commit comments