-
Notifications
You must be signed in to change notification settings - Fork 5
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
Support diagnostics in sbt #143
Comments
Is this feature only related to sbt server or also Bloop? For sbt server this could be helpful when implemented: sbt/sbt#5953 |
This would be for both the sbt Bloop integration and the sbt server integration. |
It's probably easier to do for sbt. I am not exactly sure how we would go about implementing it in Bloop 🤔 Maybe we could use diagnostics from the presentation compiler? |
SBT support this is close to landing: sbt/sbt#6553 |
This is really cool @retronym! This will be huge for Metals users that want to use sbt as a BSP server with Metals. I'll continue to play around with this today! Just to clarify though the main reason for this issue is to support diagnostics in your build files. I'm correct in saying that this still won't work with the added support in your pr correct? Since if a user makes a mistake in the build file, prompts a To illustrate. Notice the missing
So in order for this feature request to be closed, we'd basically want a way to notify the user that |
Shouldn't this give as diagnostics when you make the typo? We could not allow running reload if there are any diagnostics present. |
Well that's sort of the thing, how do you know it's a typo and not an actual key? The only way would be able to save it / compile it. By doing so Metals will detect you changed your build definition and prompt the import/reload. The reload will then fail since that's not a valid key, and then you're sort of just stuck. It's the same thing with Bloop. In an ideal world it'd be great to "recover" and basically go back to the last valid state, and then report the actual issue in the build definition. |
We could delay the prompt until we get the diagnostics and only show it if they are empty? |
Yea possibly, that might work. It doesn't look like diagnostics are being returned though in the situation. For example just testing it out, the compile goes, and returns with an error, but it looks like diagnostics aren't published for the build target. (Also not sure what's going on with the
One other thing we'll need to change is to ensure now that the |
So when trying to start up sbt in this scenario you get:
That's what we'd want right? I don't know if that is fully implemented on the sbt side to forward these as diagnostics via BSP. @adpi2 or @retronym do you know if these are forwarded as diagnostics in this scenario? |
I have only implemented the server logic to export the classpath and
automatic imports of the build. IntelliJ uses that to let it’s presentation
compiler perform error highlighting and autocomplete
I hadn’t considered the use case of just feeding the error/warnings back as
IntelliJ doesn’t need that
|
Ah just seeing this part now. Is it possible for this to be set to compile?
Gotcha, that makes sense. For us on the Metals side, this would be super helpful if these were returned via BSP. |
It seems that the only option for getting diagnostic would be to compile sbt-file on Metals side using Presentation Compiler. I have some idea for the case when the build has errors and the project can't be imported. |
Ok so one other thing I'm a bit confused about is how this actually works for navigation purposes. Metals will warn you in the doctor that you need to do a build import no matter what in your ScalacOptionsItem(
build._1,
Vector(), <-- this one
classpath,
new File(build._2.localBase, "project/target").toURI
) That's fine if there still is actually semanticdb files that we can locate and use, but I'm unsure of where these are as they seem to be empty in |
@ckipp01 We don't actually need enabled semanticDb for sbt files. Everything is done using PC and |
Huh, I never realized this. I'll need to dig in more. |
I've added a commit to pass the |
One thing to be aware of is that the build itself used Scala 2.12.x (.14 at the moment, I think). So your need to use that version of the Scala presentation compiler, too. |
We do use the presentation compiler version that is defined in the build target, so this should work all in all. Anyway, diagnostics will need to be handled separately, but that's to @retronym we will be able to provide completions, references etc. in sbt files 🎉 |
@ckipp01 said
I thought this was already working but it only partially does. Here is an example where it works: // build.sbt
lazy val sanity = project
.settings(Build.commonSettings) // project/Build.scala
import sbt.Keys._
import sbt._
object Build {
val commonSettings = Seq(
ibraryDependencies ++= Seq(
"com.lihaoyi" %% "pprint" % "0.6.6"
)
)
} Using sbt as the build server. When I hit "Import changes", I receive the correct diagnostic: In the BSP traces: [Trace - 10:51:56 AM] Received notification 'build/publishDiagnostics'
Params: {
"textDocument": {
"uri": "file:///home/piquerez/scalameta/metals-feature-143/project/Build.scala"
},
"buildTarget": {
"uri": "file:/home/piquerez/scalameta/metals-feature-143/project/#metals-feature-143-build/Compile"
},
"diagnostics": [
{
"range": {
"start": {
"line": 5,
"character": 4
},
"end": {
"line": 5,
"character": 5
}
},
"severity": 1,
"source": "sbt",
"message": "not found: value ibraryDependencies"
}
],
"reset": true
} So the fact that it does not work in the @tgodzik said
That would be great! To do so with sbt as the build server we need @retronym's PR as a first step, and then we need the @dos65 said
I think it would be better if sbt compiles its own files so that an sbt build target could be treated as any other build target. |
Is your feature request related to a problem? Please describe.
Thanks to scalameta/metals#1865 we now have most of the needed features for supporting sbt files.
One of the missing features is diagnostic support - Bloop doesn't currently compile sbt files, this will need to be somehow done via sbt, but is certainly non trivial
Describe the solution you'd like
A way to get full diagnostics about sbt files when saving.
Describe alternatives you've considered
Running sbt manually.
Search terms:
sbt diagnostics
The text was updated successfully, but these errors were encountered: