Build Server Protocol in sbt

I don’t know if this the right place to put this, but one thing I’ve wondered for a while, is if it would be possible to do an incremental build and and a build from scratch in parallel at the same time. I’m sure these days most developers have got idle cores sitting around nearly all of the time.

The compile finished notification is required for Metals to be able to properly restart the presentation compiler (which influences the correctness of completions among other things)

I have tried to reproduce the limitation you are mentioning but without success. Maybe the json-rpc response of the buildTarget/compile do restart the presentation compiler.

Do you have in mind a scenario in which the completion would not be correct?

The relevant code in Metals is here


Here’s an example scenario where you may be able to reproduce an issue without task finish notifications.

Step 1. Trigger completion in B.scala, which is in a different project than A.scala (for example main and test)

// src/main/scala/a/A.scala
package a
object A {
  def foo: Int = 42
}
// src/test/scala/b/B.scala
package b
object B {
  def bar = a.A.foo // completion here shows type Int
}

Step 2, save the following diff, let the compilation succeed

// src/main/scala/a/A.scala
package a
object A {
-  def foo: Int = 42
+ def foo: String = ""
}

Step 3, trigger completion in B.scala again. It may still show Int when it should show the updated String signature. It’s important that B.scala is in a different project than A.scala because otherwise there’s a chance that the presentation compiler may already have updated the signature for a.A.foo because Metals reuses the compiler instance within the same project.

I’m not 100% sure this scenario reproduces the issue, but in general Metals needs to compile finished notification to tell the presentation compiler to load fresh symbols from the classpath. Otherwise users risk seeing stale signatures in completions, parameter hints, type at point, etc.

4 Likes

Thank you Olaf for the detailed explanation! It behaves exactly the way you described.

image

Do you mean that you’re able to reproduce the issue or the completions work as expected (show the new String signature)?

Hello everyone,

You will find a detailed status of the BSP implementation in sbt in this post.

The implemented endpoints are:

  • build/initialize
  • workspace/buildTargets
  • buildTarget/sources
  • buildTarget/dependencySources
  • buildTarget/scalacOptions
  • buildTarget/compile

The compiler diagnostic notifications, as well as the compilation taskStart and taskFinish notifications are also implemented.

8 Likes