-
Notifications
You must be signed in to change notification settings - Fork 348
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
Handle Java-only build targets #2520
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4bf5efe
Initial Java support
Arthurm1 4dacf29
Java handling fixes
Arthurm1 bdc4dab
Java handling fixes
Arthurm1 113013f
Fix test failures
Arthurm1 18961e4
Fix scalafix import ordering issue
Arthurm1 69d9e50
Add exports to CI for jdk 17 + semantic plugin
Arthurm1 cc3acd9
Merge branch 'main' into java_targets
tgodzik a4a681e
hardcode eclipse transitive dependency versions
Arthurm1 675816a
Skipp asking about javacOptions when using sbt via BSP
tgodzik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ package scala.meta.internal.metals | |
import java.io.IOException | ||
import java.io.InputStream | ||
import java.net.URI | ||
import java.util.Collections | ||
import java.util.concurrent.CompletableFuture | ||
import java.util.concurrent.TimeUnit | ||
import java.util.concurrent.TimeoutException | ||
|
@@ -160,10 +159,34 @@ class BuildServerConnection private ( | |
register(server => server.workspaceBuildTargets()).asScala | ||
} | ||
|
||
def buildTargetJavacOptions( | ||
params: JavacOptionsParams | ||
): Future[JavacOptionsResult] = { | ||
val resultOnJavacOptionsUnsupported = new JavacOptionsResult( | ||
List.empty[JavacOptionsItem].asJava | ||
) | ||
if (isSbt) Future.successful(resultOnJavacOptionsUnsupported) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Arthurm1 I added this check since it seems that sbt shuts down when unexpected request is made. |
||
else { | ||
val onFail = Some( | ||
( | ||
resultOnJavacOptionsUnsupported, | ||
"Java targets not supported by server" | ||
) | ||
) | ||
register(server => server.buildTargetJavacOptions(params), onFail).asScala | ||
} | ||
} | ||
|
||
def buildTargetScalacOptions( | ||
params: ScalacOptionsParams | ||
): Future[ScalacOptionsResult] = { | ||
register(server => server.buildTargetScalacOptions(params)).asScala | ||
val resultOnScalaOptionsUnsupported = new ScalacOptionsResult( | ||
List.empty[ScalacOptionsItem].asJava | ||
) | ||
val onFail = Some( | ||
(resultOnScalaOptionsUnsupported, "Scala targets not supported by server") | ||
) | ||
register(server => server.buildTargetScalacOptions(params), onFail).asScala | ||
} | ||
|
||
def buildTargetSources(params: SourcesParams): Future[SourcesResult] = { | ||
|
@@ -228,7 +251,8 @@ class BuildServerConnection private ( | |
|
||
} | ||
private def register[T: ClassTag]( | ||
action: MetalsBuildServer => CompletableFuture[T] | ||
action: MetalsBuildServer => CompletableFuture[T], | ||
onFail: => Option[(T, String)] = None | ||
): CompletableFuture[T] = { | ||
val original = connection | ||
val actionFuture = original | ||
|
@@ -248,8 +272,15 @@ class BuildServerConnection private ( | |
} | ||
case t | ||
if implicitly[ClassTag[T]].runtimeClass.getSimpleName != "Object" => | ||
val name = implicitly[ClassTag[T]].runtimeClass.getSimpleName | ||
Future.failed(MetalsBspException(name, t.getMessage)) | ||
onFail | ||
.map { case (defaultResult, message) => | ||
scribe.info(message) | ||
Future.successful(defaultResult) | ||
} | ||
.getOrElse({ | ||
val name = implicitly[ClassTag[T]].runtimeClass.getSimpleName | ||
Future.failed(MetalsBspException(name, t.getMessage)) | ||
}) | ||
} | ||
CancelTokens.future(_ => actionFuture) | ||
} | ||
|
@@ -345,6 +376,7 @@ object BuildServerConnection { | |
} | ||
|
||
final case class BspExtraBuildParams( | ||
javaSemanticdbVersion: String, | ||
semanticdbVersion: String, | ||
supportedScalaVersions: java.util.List[String] | ||
) | ||
|
@@ -358,6 +390,7 @@ object BuildServerConnection { | |
serverName: String | ||
): InitializeBuildResult = { | ||
val extraParams = BspExtraBuildParams( | ||
BuildInfo.javaSemanticdbVersion, | ||
BuildInfo.scalametaVersion, | ||
BuildInfo.supportedScala2Versions.asJava | ||
) | ||
|
@@ -369,7 +402,7 @@ object BuildServerConnection { | |
BuildInfo.bspVersion, | ||
workspace.toURI.toString, | ||
new BuildClientCapabilities( | ||
Collections.singletonList("scala") | ||
List("scala", "java").asJava | ||
) | ||
) | ||
val gson = new Gson | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Uff, this is a lot, thanks for compiling the list!
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've had more fun afternoons
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.
If possible can we add a note here as to why we are doing this? I can see later on someone jumping in here and looking at this and wondering what in the world we are doing here with all these overrides.
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 was thinking of moving it later to a separate file and commenting. This PR is pretty huge and I don't want to add anything more right now.
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.
Also, I think you did another comment and I can't find it 😅 which is a good indicator that this got way to big. What do you think? Is it ok to do same follow ups later?
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.
:) of course, a follow-up is totally fine.
For the other comment 😆 I deleted it. A couple weeks ago I started reviewing this and only got like half way through and didn't realize I had draft comments saved, so when I added this comment it also posted those. They aren't relevant anymore, so I just removed them. Sorry for the noise!