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 the SBT extension in BSP import #6553
Conversation
14b2eee
to
256adb8
Compare
main/src/main/scala/sbt/internal/server/BuildServerProtocol.scala
Outdated
Show resolved
Hide resolved
Looks very promising so far. Thank you @retronym for taking care of this! |
I should get back to this later today, thanks for the review comments so far. The corresponding change to IntelliJ is just about ready to land: JetBrains/intellij-scala#593 |
ff2db6f
to
05ba7d7
Compare
This one is ready for another round of review. I'll try to address attaching SBT source JARs to the project in a followup PR. |
main/src/main/scala/sbt/internal/server/BuildServerProtocol.scala
Outdated
Show resolved
Hide resolved
main/src/main/scala/sbt/internal/server/BuildServerProtocol.scala
Outdated
Show resolved
Hide resolved
This enables code assist in the .sbt and project/*.scala files in IntelliJ and any other IDEs that implement this extension.
- Restore old type of `bspWorkspace` key for backwards compat. Instead, introduce `bspFullWorkspace` that includes the SBT targets - Log a warning if the client requests, e.g. `scalaMainClasses` for a SBT target - Refactor the code that creates the SBT build targets so it doesn't depend on `sbtFullWorkspace`. - Add a setting `bspSbtEnabled` to let the user opt-opt of SBT target export (e.g. to compensate for a client that does not yet support them)
89ae692
to
1dd9cf1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I yield the detail review to Adrien.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I yield the detail review to Adrien.
// Not a constructor parameter to avoid a binary incompatibility | ||
private[this] var _buildSources: BuildSources = BuildSources.Empty | ||
private[sbt] def setBuildSourcesData(data: BuildSources): PluginData = { | ||
_buildSources = data; this | ||
} | ||
private[sbt] def buildSourcesData: BuildSources = _buildSources |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The breakage is just for the constructor, copy, and apply factory methods, not for consumers of the data. I think it is highly unlikely to break existing plugins.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really necessary to preserve the binary compatibility of
PluginData
? How bad would it be to break it in sbt 1.6?
We maintain binary compatibility for the purpose of maintaining plugin compatibility, so I think PluginData
would be ok to break, but ultimately we the only way to quantify this would be to release a milestone and test it using Community Build. If none of the existing builds break, then we should be ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 2 comments below should be addressed before merging. Otherwise I would suggest to update the test here:
sbt/server-test/src/test/scala/testpkg/BuildServerTest.scala
Lines 24 to 35 in e4231ac
test("workspace/buildTargets") { _ => | |
svr.sendJsonRpc( | |
"""{ "jsonrpc": "2.0", "id": "16", "method": "workspace/buildTargets", "params": {} }""" | |
) | |
assert(processing("workspace/buildTargets")) | |
assert { | |
svr.waitForString(10.seconds) { s => | |
(s contains """"id":"16"""") && | |
(s contains """"displayName":"util"""") | |
} | |
} | |
} |
and to add a new test for the sources of the build.sbt target.
main/src/main/scala/sbt/internal/server/BuildServerProtocol.scala
Outdated
Show resolved
Hide resolved
1dd9cf1
to
0bd736b
Compare
Update: I'm currently trying to extend the BSP test. Having some difficulty there as one of my new tests for |
- Pass source dirs and current list of files - Align display name and URI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just pushed a small fix for the new buildTarget/resources
request. Otherwise it looks good to me as it is.
I tried in Metals and most of the things (goto definitions and code completions) are already working out-of-the-box. That's cool!
@eed3si9n Are you happy with this one now, in particular deeming |
There was a scalacheck test failure in one of the test runs, not related to this PR, but maybe worth looking into:
|
@retronym I'm guessing it's a known ambiguity when we have subproject named I'm fine with |
I did a GitHub code search for "plugindata language:scala", filtered out files with
Not a perfect method, but I think it is likely safe enough for 1.5.x. @adpi2 mentioned that he also has a followup change to add extra data to |
ok. We can merge it now, and see. |
This enables code assist in the
.sbt
andproject/*.scala
files in IntelliJ (pending merge of the related PR to intelli-scala).Other IDEs that support BSP import could also take advantage of this; scala-metals has a ticket to add support: scalameta/metals-feature-requests#143
To disable this feature (e.g. if using an IDE version that does not yet support the sbt extension in the BSP protocl, set
ThisBuild / bspSbtEnabled := false
.Fixes #5953
Requires: JetBrains/intellij-scala#593