scalacenter / bloop

Bloop is a build server and CLI tool to compile, test and run Scala fast from any editor or build tool.
https://scalacenter.github.io/bloop/
Apache License 2.0
905 stars 202 forks source link

Implement build target change notifications #684

Open jvican opened 6 years ago

jvican commented 6 years ago

Build target notifications are a BSP mechanism to notify the client the server has updated one of its project models and it has to update it accordingly. For example, whenever a new dependency is added to a project in a build tool, the client needs to know about it to index it and can get the notifications to start that process as soon as it's known by the BSP server. It is IMO one of the most importants features in the BSP protocol as it heavily improves the communication between client and server and allows instant and incremental reloads.

Bloop has to provide these build target notifications. This is a ticket to register my thoughts on how we can implement them in our current architecture.

I propose that whenever a BSP session is started, we start a task a long-running task that would file watch on all the JSON configuration files under the configuration directory (typically .bloop). The idea is that this talk will have a reference to the client so that it can push notifications on file change.

As we don't want to bother the client when a file change happens and doesn't modify anything, we should use all the machinery we have in Build.checkForChange to only update those configuration files that really changed (checkForChange hashes the contents to figure that out):

https://github.com/scalacenter/bloop/blob/master/frontend/src/main/scala/bloop/engine/Build.scala#L20-L62

After we recycle some of this logic, we should be in a solid position to provide build target change notifications reliably. There is however one missing piece: we need to properly cancel the file watcher whenever there has been a fatal error in the connection or the connection has ended.

nafg commented 5 years ago

Does this affect if the CLI watch mode would watch build config files?

jvican commented 5 years ago

It could make it easier, but it's not planned (for now) to make the CLI watch build configuration files.