You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If using Metals 0.9.7 in a project for the first time that is using sbt >= 1.4.1, you may have experienced some odd behavior when opening your project for the first time. I'd like to take a moment and explain what was actually happening so you may be able to identify that you were hitting on this or just to give someone a better understanding of what goes on when you first open Metals in a project. This issue could cause you to see messages in your logs explaining that you Build Server Connection failed even though some functionality was working, can cuase you to continuously see Connecting to sbt messages, or other odd scenarios like a different jvm version being picked up than what Metals shows in your logs, and then seeing a failure about it.
.bsp/sbt.json
What is this file? If you have a project using sbt >= 1.4.0 and you have ran almost any sbt commands on it, you'll see that a .bsp/ directory has been created. You'll want to make sure to include this in your .gitignore as it's specific to your machine. sbt creates this directory and puts a .bsp/sbt.json file in it. This file is used for Build Server Discovery which allows Metals to get the BspConnectionDetails it needs to make a BSP connection with any build server that creates an entry in .bsp/.
Build server default and the overlooked scenario
In Metals, as we outlined in this blogpost defaults to Bloop as a build server. The intent is that if no explicit choice was made to use sbt BSP, you're given Bloop to use. The two ways that a user can make an explicit choice is by using the generate-bsp-config command or bsp-switch command and choosing sbt.
Now, the overlooked scenario was that when Metals doesn't see a .bloop/ directory, it defaults to looking in .bsp/ for an server to connect to. So As you can imagine, in a fresh project that has yet to have a .bloop/ created, but does have a .bsp/sbt.json file, it causes problems when you open a project for the first time. Mainly because Metals will immediately start to try and create a BSP connection with sbt while also showing you a message to either choose your build tool or import you build. Here is an example below that should be able to happen:
You can see the Connecting to sbt message in the status bar, but Metals is also detecting that you're in a workspace that has a build.sbt and a build.sc file. So while it's still trying to figure out what build tool you're using, it's also trying to connect to sbt. So if I would then choose sbt and then followed by an Import Build, it would also try to make a connection to Bloop.
Great, how do I fix it?
So if you're experiencing something like this, feel free to comment in here and we can try to help see if you're really hitting on this or something else. There are two ways to avoid this issue:
Make sure to open the project in your editor before a .bsp/sbt.json file is created. This will create your .bloop/ directory and then from there onward you'll have no issue.
Use the latest Metals snapshot which includes a fix that no matter what, you will be defaulted to Bloop even if no .bloop/ exists and a .bsp/sbt.json file exists.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Description of the problem
If using Metals 0.9.7 in a project for the first time that is using sbt >= 1.4.1, you may have experienced some odd behavior when opening your project for the first time. I'd like to take a moment and explain what was actually happening so you may be able to identify that you were hitting on this or just to give someone a better understanding of what goes on when you first open Metals in a project. This issue could cause you to see messages in your logs explaining that you Build Server Connection failed even though some functionality was working, can cuase you to continuously see Connecting to sbt messages, or other odd scenarios like a different jvm version being picked up than what Metals shows in your logs, and then seeing a failure about it.
.bsp/sbt.json
What is this file? If you have a project using sbt >= 1.4.0 and you have ran almost any sbt commands on it, you'll see that a
.bsp/
directory has been created. You'll want to make sure to include this in your.gitignore
as it's specific to your machine. sbt creates this directory and puts a.bsp/sbt.json
file in it. This file is used for Build Server Discovery which allows Metals to get theBspConnectionDetails
it needs to make a BSP connection with any build server that creates an entry in.bsp/
.Build server default and the overlooked scenario
In Metals, as we outlined in this blogpost defaults to Bloop as a build server. The intent is that if no explicit choice was made to use sbt BSP, you're given Bloop to use. The two ways that a user can make an explicit choice is by using the
generate-bsp-config
command orbsp-switch
command and choosing sbt.Now, the overlooked scenario was that when Metals doesn't see a
.bloop/
directory, it defaults to looking in.bsp/
for an server to connect to. So As you can imagine, in a fresh project that has yet to have a.bloop/
created, but does have a.bsp/sbt.json
file, it causes problems when you open a project for the first time. Mainly because Metals will immediately start to try and create a BSP connection with sbt while also showing you a message to either choose your build tool or import you build. Here is an example below that should be able to happen:You can see the Connecting to sbt message in the status bar, but Metals is also detecting that you're in a workspace that has a
build.sbt
and abuild.sc
file. So while it's still trying to figure out what build tool you're using, it's also trying to connect to sbt. So if I would then choose sbt and then followed by an Import Build, it would also try to make a connection to Bloop.Great, how do I fix it?
So if you're experiencing something like this, feel free to comment in here and we can try to help see if you're really hitting on this or something else. There are two ways to avoid this issue:
.bsp/sbt.json
file is created. This will create your.bloop/
directory and then from there onward you'll have no issue..bloop/
exists and a.bsp/sbt.json
file exists.Beta Was this translation helpful? Give feedback.
All reactions