-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: metals error reports (#4971)
* feature: reports A framework for creating error reports in metals. * reports for chosen errors The errors are chosen based on what reoccurs in `metals.log`. * feature: zip command zip reports command: - zips error reports - adds build target info from doctor
- Loading branch information
1 parent
565ac31
commit cd6c659
Showing
23 changed files
with
489 additions
and
64 deletions.
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
73 changes: 73 additions & 0 deletions
73
metals/src/main/scala/scala/meta/internal/metals/ZipReportsProvider.scala
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package scala.meta.internal.metals | ||
|
||
import java.nio.file.Files | ||
import java.util.zip.ZipEntry | ||
import java.util.zip.ZipOutputStream | ||
|
||
import scala.meta.internal.mtags.MtagsEnrichments._ | ||
import scala.meta.io.AbsolutePath | ||
|
||
class ZipReportsProvider( | ||
doctorTargetsInfo: () => List[ | ||
Map[String, String] | ||
], // we pass the function instead of a whole doctor for the simplicity of testing | ||
reportContext: StdReportContext, | ||
) { | ||
|
||
def zip(): AbsolutePath = { | ||
val buildTargersFile = storeBuildTargetsInfo() | ||
zipReports(List(buildTargersFile)) | ||
crateReportReadme() | ||
} | ||
|
||
private def crateReportReadme(): AbsolutePath = { | ||
val path = reportContext.reportsDir.resolve("READ_ME.md") | ||
if (Files.notExists(path.toNIO)) { | ||
path.writeText( | ||
s"""|Please attach `${StdReportContext.ZIP_FILE_NAME}` to your GitHub issue. | ||
|Reports zip URI: ${reportContext.reportsDir.resolve(StdReportContext.ZIP_FILE_NAME).toURI(false)} | ||
|""".stripMargin | ||
) | ||
} | ||
path | ||
} | ||
|
||
private def storeBuildTargetsInfo(): FileToZip = { | ||
val text = doctorTargetsInfo().zipWithIndex | ||
.map { case (info, ind) => | ||
s"""|#### $ind | ||
|${info.toList.map { case (key, value) => s"$key: $value" }.mkString("\n")} | ||
|""".stripMargin | ||
} | ||
.mkString("\n") | ||
FileToZip("build-targets-info.md", text.getBytes()) | ||
} | ||
|
||
private def zipReports(additionalToZip: List[FileToZip]): AbsolutePath = { | ||
val path = reportContext.reportsDir.resolve(StdReportContext.ZIP_FILE_NAME) | ||
val zipOut = new ZipOutputStream(Files.newOutputStream(path.toNIO)) | ||
|
||
for { | ||
reportsProvider <- reportContext.allToZip | ||
report <- reportsProvider.getReports() | ||
} { | ||
val zipEntry = new ZipEntry(report.name) | ||
zipOut.putNextEntry(zipEntry) | ||
zipOut.write(Files.readAllBytes(report.toPath)) | ||
} | ||
|
||
for { | ||
toZip <- additionalToZip | ||
} { | ||
val zipEntry = new ZipEntry(toZip.name) | ||
zipOut.putNextEntry(zipEntry) | ||
zipOut.write(toZip.text) | ||
} | ||
|
||
zipOut.close() | ||
|
||
path | ||
} | ||
} | ||
|
||
case class FileToZip(name: String, text: Array[Byte]) |
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
Oops, something went wrong.