dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.09k stars 1.56k forks source link

Analyzer: deleting a file changes query results #50688

Open jensjoha opened 1 year ago

jensjoha commented 1 year ago

TL;DR Deleting a file can cause "find all implementations" query to reduce the number of results (and probably other stuff too).

Reproduction (example):

What happens is, that on the initial "Find all implementations" query a discoverAvailableFiles task is created which basically "discovers" all files in all paths mentioned in the packages file. This is why it finds results in analyzer and front_end. When deleting a file it clears "everything" (removeFile -> _clearFiles in file_state.dart) among it the previously discovered extra files. Issuing the "Find all implementations" query again the discoverAvailableFiles will not do anything as it's already completed, there will thus not be any extra files to search.

/cc @bwilkerson @scheglov

bwilkerson commented 1 year ago

@scheglov Sounds like we need to forget that we've run discoverAvailableFiles so that it will run again.

jensjoha commented 1 year ago

That would probably be one way to go, but wouldn't it make more sense to not throw everything away? For instance, wouldn't it be possible to for instance just refresh the deleted file instead? (the signature created has both content and a bool exists so I'm assuming that's supported). Or even better, invalidate as-if it had been updated, then remove it from whatever maps it's in. Having to actually run discover available files again isn't exactly free.