Skip to content

Commit

Permalink
feat: start forwarding diagnosticCode via BSP
Browse files Browse the repository at this point in the history
This change is a continuation of the work that was done in
sbt#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
scala/scala3#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 <[email protected]>
Refs: scala/scala3#14904
  • Loading branch information
ckipp01 and adpi2 committed Aug 9, 2022
1 parent d065f38 commit 15a45cb
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ final class BuildServerReporterImpl(
Diagnostic(
range,
Option(toDiagnosticSeverity(problem.severity)),
None,
problem.diagnosticCode().toOption.map(_.code),
Option("sbt"),
problem.message
)
Expand Down

0 comments on commit 15a45cb

Please sign in to comment.