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.28k stars 1.59k forks source link

ServerPlugin hook for added files vs changed files, find drivers that care #29622

Open MichaelRFairhurst opened 7 years ago

MichaelRFairhurst commented 7 years ago

I'm filling in

  void contentChanged(String path);

Might be nice if I got the driver that cared, and a differentiation between add and change events.

Ultimately I'll be doing, like

  void contentChanged(String path, AngularDriver driver) => driver.contentChanged(path);
  void fileAdded(String path, AngularDriver driver) => driver.fileAdded(path);

maybe these could be made part of the AnalysisDriverGeneric interface, so I don't even have to write it?

bwilkerson commented 7 years ago

Yeah, I debated about that part of the implementation. Currently, contentChanged is only invoked when there is a watch event of type MODIFY or when an overlay is added, changed or removed. I was thinking about having separate methods for when files are added or removed, but haven't implemented them yet. (There are to-do comments for them.)

Your idea of passing in a driver is an interesting one. I think, though, that it makes the assumption that plugins will only ever analyze a file in a single driver, and I'm not sure that's valid given dependency overrides. (I routinely have 'analyzer' and 'analysis_server' open and changes I make to 'analyzer' force server to re-analyze part of 'analysis_server'.)

... maybe these could be made part of the AnalysisDriverGeneric interface ...

Yeah, I'm not sure what we want that interface to look like. I guess we'll just have to figure it out as we go along. If the base plugin class were to invoke a contentChanged method on the driver, then it would probably have to notify every driver of every change just in case. Not sure whether it either saves the plugin author any effort or improves performance.