From 15a45cb3c0a480b8d19d693cb94811ca5d515afa Mon Sep 17 00:00:00 2001 From: Chris Kipp Date: Tue, 9 Aug 2022 19:02:52 +0200 Subject: [PATCH] feat: start forwarding diagnosticCode via BSP This change is a continuation of the work that was done in https://github.com/sbt/sbt/pull/6874 to allow the Scala 3 compiler to forward the `diagnosticCode` of an error as well as the other normal things. This change in dotty was merged in https://github.com/lampepfl/dotty/pull/15565 and also backported so it will be in the 3.2.x series release. This change captures the `diagnosticCode` and forwards it on via BSP so that tools like Metals can can use this code. You can see this in the BSP trace now for a diagnostic: For example with some code that contains the following: ```scala val x: Int = "hi" ``` You'll see the code in the BSP diagnostic: ``` "diagnostics": [ { "range": { "start": { "line": 9, "character": 15 }, "end": { "line": 9, "character": 19 } }, "severity": 1, "code": "7", "source": "sbt", "message": "Found: (\u001b[32m\"hi\"\u001b[0m : String)\nRequired: Int\n\nThe following import might make progress towards fixing the problem:\n\n import sourcecode.Text.generate\n\n" } ] ``` Co-authored-by: Adrien Piquerez Refs: https://github.com/lampepfl/dotty/issues/14904 --- .../main/scala/sbt/internal/server/BuildServerReporter.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/src/main/scala/sbt/internal/server/BuildServerReporter.scala b/main/src/main/scala/sbt/internal/server/BuildServerReporter.scala index 98d59d645..3c8c8bb0c 100644 --- a/main/src/main/scala/sbt/internal/server/BuildServerReporter.scala +++ b/main/src/main/scala/sbt/internal/server/BuildServerReporter.scala @@ -174,7 +174,7 @@ final class BuildServerReporterImpl( Diagnostic( range, Option(toDiagnosticSeverity(problem.severity)), - None, + problem.diagnosticCode().toOption.map(_.code), Option("sbt"), problem.message )