@@ -116,11 +116,11 @@ class FileResolver {
116116 LibraryContext ? libraryContext;
117117
118118 /// 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]
120120 /// to release the cache items and is then cleared.
121121 final Set <String > removedCacheKeys = {};
122122
123- /// The cache of file results, cleared on [changeFile ] .
123+ /// The cache of file results, cleared on [changeFiles ] .
124124 ///
125125 /// It is used to allow assists and fixes without resolving the same file
126126 /// multiple times, as we compute more than one assist, or fixes when there
@@ -158,29 +158,43 @@ class FileResolver {
158158 /// Update the resolver to reflect the fact that the file with the given
159159 /// [path] was changed. We need to make sure that when this file, of any file
160160 /// 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
162162 /// items, used in [releaseAndClearRemovedIds] to release the cache items.
163+ /// TODO(scheglov) Remove [releaseKeys] when removing [changeFile] .
164+ @Deprecated ('Use changeFiles() instead' )
163165 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 }) {
164174 if (fsState == null ) {
165175 return ;
166176 }
167177
168178 // Forget all results, anything is potentially affected.
169179 cachedResults.clear ();
170180
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+ }
174186
175187 // Schedule disposing references to cached unlinked data.
176- for (var removedFile in removedFiles) {
188+ for (final removedFile in removedFiles) {
177189 removedCacheKeys.add (removedFile.unlinkedKey);
178190 }
179191
180192 // Remove libraries represented by removed files.
181193 // 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 ();
184198 }
185199 }
186200
@@ -445,12 +459,14 @@ class FileResolver {
445459 /// Remove cached [FileState] 's that were not used in the current analysis
446460 /// session. The list of files analyzed is used to compute the set of unused
447461 /// [FileState] 's. Adds the cache id's for the removed [FileState] 's to
448- /// [removedCacheIds ] .
462+ /// [removedCacheKeys ] .
449463 void removeFilesNotNecessaryForAnalysisOf (List <String > files) {
450464 var removedFiles = fsState! .removeUnusedFiles (files);
451465 for (var removedFile in removedFiles) {
452466 removedCacheKeys.add (removedFile.unlinkedKey);
453467 }
468+ libraryContext? .remove (removedFiles, removedCacheKeys);
469+ releaseAndClearRemovedIds ();
454470 }
455471
456472 /// The [completionLine] and [completionColumn] are zero based.
0 commit comments