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_plugin] Running build_runner does not invoke analysis.updateContent with the newly generated files in VScode #54113

Open
rrousselGit opened this issue Nov 21, 2023 · 9 comments
Labels
analyzer-plugin 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

@rrousselGit
Copy link

Hello!

It appears that when generated files are generated using build_runner, analyzer_plugins do not receive a analysis.updateContent matching the generation.

Steps to reproduce:

  • open a project using build_runner and an analyzer_plugin
  • run code-generation once
  • delete a .g.dart (this will correctly invoke (analysis.updateContent with {type: remove})
  • run build_runner build -d
  • The generated .g.dart file will be re-created. But no analysis.updateContent with {type: add} will be sent

This means that subsequent getFixes/getsAssists behave as if code-generation did not happen.

Here's a video showcasing the problem.

  • First, I deleted dependencies.g.dart. This correctly updates lints due to missing generated files.
    We see in the bottom of the screen at that point that an updateContent was sent, with the content of the generated file.
  • Then, I ran dart run build_runner build -d.
    The dependencies.g.dart reappeared. But as you can see in the logs, no updateContent request was sent. So the IDE behaves as if the generated file is still missing.
  • Opening the generated file fixes the issue as it appears to forcibly call updateContent.
Screen.Recording.2023-11-21.at.11.47.16.mov
@rrousselGit
Copy link
Author

It appears that instead of deleting the .g.dart in the IDE, we call mv dependencies.g.dart backup.dart, then the {type: remove} event isn't sent either.

It may be that for all file changes triggered by the terminal, analyzer_plugin isn't notified.

@mraleph mraleph added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Nov 21, 2023
@bwilkerson
Copy link
Member

Definitely something we will need to get right in the new plugin implementation.

@srawlins

@scheglov scheglov added P2 A bug or feature request we're likely to work on analyzer-plugin labels Nov 21, 2023
@rrousselGit
Copy link
Author

Definitely something we will need to get right in the new plugin implementation.

Is there a new implementation in progress?

@bwilkerson
Copy link
Member

We're in the design phase, and once we have a design we can make a decision about whether we will implement it.

@rrousselGit
Copy link
Author

Are you aware of a possible workaround to this issue?
It's quite inconvenient for my users, as it causes confusing false positives/negatives in the IDE. I don't mind having to fix it on my end, but I'm just not sure how to get started with that.

@bwilkerson
Copy link
Member

Assuming that the server is already watching the files in the directory that build_runner writes to, the fix would be to make sure that those changes are passed along to the plugins.

As for a workaround, that would probably be for each plugin to create their own watcher on that directory and tell the AnalysisContext when the files have been changed. It isn't clear to me that the workaround would be any less work than the fix, though.

@rrousselGit
Copy link
Author

I'd love to fix it in the SDK directly. But I'm not sure where to even look at. Do you maybe have any tips on how to get started here?

@bwilkerson
Copy link
Member

The analysis.handleWatchEvents request is sent to the plugins from PluginManager.broadcastWatchEvent

I don't know how much that helps, though.

Note that our use of the watcher package is wrapped so that we can use it from the ResourceProvider. That allows us to write in-memory tests that simulate the behavior of the watcher package without having to actually modify the disk. It might make it easier to debug the issue.

@rrousselGit
Copy link
Author

About this, is there a document detailing how to use the local clone of analyzer_server in my IDE?

I have tests running and was looking into forking test_concurrentContextRebuilds to debug this. But so far I'm struggling to write a test for this, and would likely need a debugger first.

@srawlins srawlins added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-plugin 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

5 participants