-
Notifications
You must be signed in to change notification settings - Fork 315
/
DoctorResults.scala
186 lines (172 loc) Β· 5.24 KB
/
DoctorResults.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package scala.meta.internal.metals.doctor
import scala.meta.internal.metals.Icons
import ujson.Obj
final case class DoctorResults(
title: String,
header: DoctorHeader,
folders: List[DoctorFolderResults],
) {
def toJson: Obj =
ujson.Obj(
"title" -> title,
"header" -> header.toJson,
"folders" -> folders.map(_.toJson),
"version" -> DoctorResults.version,
)
}
object DoctorResults {
// Version of the Doctor json that is returned.
val version = 5
}
final case class DoctorFolderResults(
folder: String,
header: DoctorFolderHeader,
messages: Option[List[DoctorMessage]],
targets: Option[Seq[DoctorTargetInfo]],
explanations: List[Obj],
errorReports: List[ErrorReportInfo],
) {
def toJson: Obj = {
val json = ujson.Obj(
"folder" -> folder,
"header" -> header.toJson,
)
messages.foreach(messageList =>
json("messages") = messageList.map(_.toJson)
)
targets.foreach(targetList => json("targets") = targetList.map(_.toJson))
json("explanations") = explanations
json("errorReports") = errorReports.map(_.toJson)
json
}
}
final case class DoctorMessage(title: String, recommendations: List[String]) {
def toJson: Obj =
ujson.Obj(
"title" -> title,
"recommendations" -> recommendations,
)
}
sealed case class DoctorStatus(explanation: String, isCorrect: Boolean)
object DoctorStatus {
object check extends DoctorStatus(Icons.unicode.check, true)
object alert extends DoctorStatus(Icons.unicode.alert, false)
object error extends DoctorStatus(Icons.unicode.error, false)
object info extends DoctorStatus(Icons.unicode.info, false)
}
final case class DoctorTargetInfo(
name: String,
gotoCommand: String,
dataKind: String,
baseDirectory: Option[String],
targetType: String,
compilationStatus: DoctorStatus,
diagnosticsStatus: DoctorStatus,
interactiveStatus: DoctorStatus,
indexesStatus: DoctorStatus,
debuggingStatus: DoctorStatus,
javaStatus: DoctorStatus,
recommenedFix: String,
) {
def toJson: Obj =
ujson.Obj(
"buildTarget" -> name,
"gotoCommand" -> gotoCommand,
"compilationStatus" -> compilationStatus.explanation,
"targetType" -> targetType,
"diagnostics" -> diagnosticsStatus.explanation,
"interactive" -> interactiveStatus.explanation,
"semanticdb" -> indexesStatus.explanation,
"debugging" -> debuggingStatus.explanation,
"java" -> javaStatus.explanation,
"recommendation" -> recommenedFix,
)
def toMap(exclude: List[String] = List()): Map[String, String] =
Map(
"buildTarget" -> name,
"gotoCommand" -> gotoCommand,
"compilationStatus" -> compilationStatus.explanation,
"targetType" -> targetType,
"diagnostics" -> diagnosticsStatus.explanation,
"interactive" -> interactiveStatus.explanation,
"semanticdb" -> indexesStatus.explanation,
"debugging" -> debuggingStatus.explanation,
"java" -> javaStatus.explanation,
"recommendation" -> recommenedFix,
) -- exclude
}
/**
* @param jdkInfo java version and location information
* @param serverInfo the version of the server that is being used
* @param buildTargetDescription small description on what a build target is
*/
final case class DoctorHeader(
jdkInfo: Option[String],
serverInfo: String,
buildTargetDescription: String,
) {
def toJson: Obj = {
val base =
ujson.Obj(
"serverInfo" -> serverInfo,
"buildTargetDescription" -> buildTargetDescription,
)
jdkInfo.foreach { jdki => base.update("jdkInfo", jdki) }
base
}
}
/**
* @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(
buildTool: Option[String],
buildServer: String,
importBuildStatus: Option[String],
isBuildServerResponsive: Option[Boolean],
) {
def toJson: Obj = {
val base =
ujson.Obj(
"buildServer" -> buildServer
)
buildTool.foreach { bt => base.update("buildTool", bt) }
importBuildStatus.foreach { ibs => base.update("importBuildStatus", ibs) }
isBuildServerResponsive.foreach { ibsr =>
base.update("isBuildServerResponsive", ibsr)
}
base
}
}
/**
* Information about an error report.
* @param name display name of the error
* @param timestamp date and time timestamp of the report
* @param uri error report file uri
* @param buildTarget optional build target that error is associated with
* @param shortSummary short error summary
* @param errorReportType one of "metals", "metals-full", "bloop"
*/
final case class ErrorReportInfo(
name: String,
timestamp: Long,
uri: String,
buildTarget: Option[String],
shortSummary: String,
errorReportType: String,
) {
def toJson: Obj = {
val json = ujson.Obj(
"name" -> name,
"timestamp" -> timestamp,
"uri" -> uri,
"shortSummary" -> shortSummary,
"errorReportType" -> errorReportType,
)
buildTarget.foreach(json("buildTarget") = _)
json
}
}