Skip to content

Commit

Permalink
improvement: add project's java info to doctor (#6226)
Browse files Browse the repository at this point in the history
* improvement: add project's java info to doctor

* add to json

* bump doctor version
  • Loading branch information
kasiaMarek committed Apr 2, 2024
1 parent 94ad2e3 commit 73a272e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ object ClientCommands {
|```
|```json
|export interface DoctorFolderHeader {
| /** information about java used for project */
| projectsJavaInfo?: string;
| /** if Metals detected multiple build tools, this specifies the one the user has chosen */
| buildTool?: string;
| /** the build server that is being used */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ object JavaInteractiveSemanticdb {
}

case class JdkVersion(
major: Int
major: Int,
full: String,
) {

def hasJigsaw: Boolean = major >= 9
Expand Down Expand Up @@ -252,9 +253,9 @@ object JdkVersion {

numbers match {
case Some(1 :: minor :: _) =>
Some(JdkVersion(minor))
Some(JdkVersion(minor, v))
case Some(single :: _) =>
Some(JdkVersion(single))
Some(JdkVersion(single, v))
case _ => None
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import scala.meta.internal.metals.FileDecoderProvider
import scala.meta.internal.metals.HtmlBuilder
import scala.meta.internal.metals.Icons
import scala.meta.internal.metals.JavaTarget
import scala.meta.internal.metals.JdkSources
import scala.meta.internal.metals.JdkVersion
import scala.meta.internal.metals.Messages.CheckDoctor
import scala.meta.internal.metals.MetalsEnrichments._
Expand Down Expand Up @@ -185,6 +186,12 @@ final class Doctor(
}
}

def getJavaInfo(): Option[String] =
for {
home <- JdkSources.defaultJavaHome(javaHome()).headOption
version <- JdkVersion.maybeJdkVersionFromJavaHome(Some(home))
} yield s"${version.full} located at $home"

def buildTargetsJson(): DoctorFolderResults = {
val targetIds = allTargetIds()
val buildToolHeading = selectedBuildToolMessage().map(_._1)
Expand All @@ -193,6 +200,7 @@ final class Doctor(
val importBuildHeading = selectedImportBuildMessage()
val header =
DoctorFolderHeader(
getJavaInfo(),
buildToolHeading,
buildServerHeading,
importBuildHeading,
Expand Down Expand Up @@ -304,6 +312,13 @@ final class Doctor(
if (includeWorkspaceFolderName) {
html.element("h2")(_.text(folderName))
}
getJavaInfo().foreach { jdkMsg =>
html.element("p") { builder =>
builder.bold("Project's Java: ")
builder.text(jdkMsg)
}
}

selectedBuildToolMessage().foreach { case (msg, explicitChoice) =>
html.element("p")(
_.text(msg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final case class DoctorResults(

object DoctorResults {
// Version of the Doctor json that is returned.
val version = 5
val version = 6
}

final case class DoctorFolderResults(
Expand Down Expand Up @@ -128,13 +128,15 @@ final case class DoctorHeader(
}

/**
* @param projectsJavaInfo information about java used for project
* @param buildTool if Metals detected multiple build tools, this specifies
* the one the user has chosen
* @param buildServer the build server that is being used
* @param importBuildStatus if the user has turned the import prompt off, this
* will include a message on how to get it back.
*/
final case class DoctorFolderHeader(
projectsJavaInfo: Option[String],
buildTool: Option[String],
buildServer: String,
importBuildStatus: Option[String],
Expand All @@ -146,6 +148,7 @@ final case class DoctorFolderHeader(
"buildServer" -> buildServer
)

projectsJavaInfo.foreach(base.update("projectsJavaInfo", _))
buildTool.foreach { bt => base.update("buildTool", bt) }
importBuildStatus.foreach { ibs => base.update("importBuildStatus", ibs) }
isBuildServerResponsive.foreach { ibsr =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ class JavaInteractiveSemanticdbSuite extends FunSuite {
JdkVersion.maybeJdkVersionFromJavaHome(optJavaHome)

test("parse jdk-version") {
assertEquals(JdkVersion.parse("17-ea"), Some(JdkVersion(17)))
assertEquals(JdkVersion.parse("9"), Some(JdkVersion(9)))
assertEquals(JdkVersion.parse("1.8.0_312"), Some(JdkVersion(8)))
assertEquals(JdkVersion.parse("11.0.13"), Some(JdkVersion(11)))
assertEquals(JdkVersion.parse("17-ea"), Some(JdkVersion(17, "17-ea")))
assertEquals(JdkVersion.parse("9"), Some(JdkVersion(9, "9")))
assertEquals(
JdkVersion.parse("1.8.0_312"),
Some(JdkVersion(8, "1.8.0_312")),
)
assertEquals(JdkVersion.parse("11.0.13"), Some(JdkVersion(11, "11.0.13")))
}

test("compile jdk-class") {
Expand Down

0 comments on commit 73a272e

Please sign in to comment.