@@ -116,11 +116,11 @@ class FileResolver {
116
116
LibraryContext ? libraryContext;
117
117
118
118
/// List of keys for cache elements that are invalidated. Track elements that
119
- /// are invalidated during [changeFile ] . Used in [releaseAndClearRemovedIds]
119
+ /// are invalidated during [changeFiles ] . Used in [releaseAndClearRemovedIds]
120
120
/// to release the cache items and is then cleared.
121
121
final Set <String > removedCacheKeys = {};
122
122
123
- /// The cache of file results, cleared on [changeFile ] .
123
+ /// The cache of file results, cleared on [changeFiles ] .
124
124
///
125
125
/// It is used to allow assists and fixes without resolving the same file
126
126
/// multiple times, as we compute more than one assist, or fixes when there
@@ -158,29 +158,43 @@ class FileResolver {
158
158
/// Update the resolver to reflect the fact that the file with the given
159
159
/// [path] was changed. We need to make sure that when this file, of any file
160
160
/// that directly or indirectly referenced it, is resolved, we used the new
161
- /// state of the file. Updates [removedCacheIds ] with the ids of the invalidated
161
+ /// state of the file. Updates [removedCacheKeys ] with the ids of the invalidated
162
162
/// items, used in [releaseAndClearRemovedIds] to release the cache items.
163
+ /// TODO(scheglov) Remove [releaseKeys] when removing [changeFile] .
164
+ @Deprecated ('Use changeFiles() instead' )
163
165
void changeFile (String path) {
166
+ changeFiles ([path], releaseKeys: false );
167
+ }
168
+
169
+ /// Update the resolver to reflect the fact that the files with the given
170
+ /// [paths] were changed. For each specified file we need to make sure that
171
+ /// when the file, of any file that directly or indirectly referenced it,
172
+ /// is resolved, we use the new state of the file.
173
+ void changeFiles (List <String > paths, {bool releaseKeys = true }) {
164
174
if (fsState == null ) {
165
175
return ;
166
176
}
167
177
168
178
// Forget all results, anything is potentially affected.
169
179
cachedResults.clear ();
170
180
171
- // Remove this file and all files that transitively depend on it.
172
- var removedFiles = < FileState > [];
173
- fsState! .changeFile (path, removedFiles);
181
+ // Remove the specified files and files that transitively depend on it.
182
+ final removedFiles = < FileState > [];
183
+ for (final path in paths) {
184
+ fsState! .changeFile (path, removedFiles);
185
+ }
174
186
175
187
// Schedule disposing references to cached unlinked data.
176
- for (var removedFile in removedFiles) {
188
+ for (final removedFile in removedFiles) {
177
189
removedCacheKeys.add (removedFile.unlinkedKey);
178
190
}
179
191
180
192
// Remove libraries represented by removed files.
181
193
// If we need these libraries later, we will relink and reattach them.
182
- if (libraryContext != null ) {
183
- libraryContext! .remove (removedFiles, removedCacheKeys);
194
+ libraryContext? .remove (removedFiles, removedCacheKeys);
195
+
196
+ if (releaseKeys) {
197
+ releaseAndClearRemovedIds ();
184
198
}
185
199
}
186
200
@@ -445,12 +459,14 @@ class FileResolver {
445
459
/// Remove cached [FileState] 's that were not used in the current analysis
446
460
/// session. The list of files analyzed is used to compute the set of unused
447
461
/// [FileState] 's. Adds the cache id's for the removed [FileState] 's to
448
- /// [removedCacheIds ] .
462
+ /// [removedCacheKeys ] .
449
463
void removeFilesNotNecessaryForAnalysisOf (List <String > files) {
450
464
var removedFiles = fsState! .removeUnusedFiles (files);
451
465
for (var removedFile in removedFiles) {
452
466
removedCacheKeys.add (removedFile.unlinkedKey);
453
467
}
468
+ libraryContext? .remove (removedFiles, removedCacheKeys);
469
+ releaseAndClearRemovedIds ();
454
470
}
455
471
456
472
/// The [completionLine] and [completionColumn] are zero based.
0 commit comments