Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyzer: deleting a file changes query results #50688

Open
jensjoha opened this issue Dec 12, 2022 · 2 comments
Open

Analyzer: deleting a file changes query results #50688

jensjoha opened this issue Dec 12, 2022 · 2 comments
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@jensjoha
Copy link
Contributor

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

Reproduction (example):

  • Open pkg/_fe_analyzer_shared in an editor.
  • Open the file lib/src/parser/listener.dart.
  • On class Listener issue a "Find all implementations" query.
  • This should give 19 results in 16 files, among them results from front_end and analyzer.
  • Create a file and delete it again. This might have to be done from the terminal as deleting a file via VSCode for instance seems to generate a "changed" event instead of a "deleted" event. This command works in Linux at least: touch pkg/_fe_analyzer_shared/lib/x.dart ; sleep 3; rm pkg/_fe_analyzer_shared/lib/x.dart
  • On class Listener issue a "Find all implementations" query again.
  • This now gives 9 results in 6 files, all in _fe_analyzer_shared.

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

@jensjoha jensjoha added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Dec 12, 2022
@bwilkerson bwilkerson added P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Dec 13, 2022
@bwilkerson
Copy link
Member

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

@jensjoha
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants