Skip to content

Commit 6fca4bc

Browse files
ckipp01tgodzik
authored andcommitted
feat: capture and forward diagnosticCode
This relates to the grand plan of scala/scala3#14904 and recently forwarding the `diagnosticCode` has been merged in scala/scala3#15565 and also backported so it should show up in the 3.2.x series. While this pr isn't super exciting, it's just making sure we capture the code and forward it, this should unlock _much_ better ways to determine what code actions are available for a given diagnostic. Meaning we don't have to do lovely things like regex on the diagnostic message for Scala 3 diagnostics. NOTE: that this does need some more changes in the build servers before this is usable. So we can wait for those to be merged in if you'd like. - [ ] sbt - sbt/sbt#6998 - [ ] Bloop - scalacenter/bloop#1750 - [ ] Mill - com-lihaoyi/mill#1912 Now if you look at the trace file for a diagnostic you'll see the addition of the code: ``` "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" } ], ``` Refs: scala/scala3#14904
1 parent c029a6e commit 6fca4bc

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

metals/src/main/scala/scala/meta/internal/metals/Diagnostics.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ final class Diagnostics(
267267
d.getSeverity,
268268
d.getSource,
269269
)
270+
if (d.getCode() != null) ld.setCode(d.getCode())
270271
ld.setData(d.getData)
271272
ld
272273
}

metals/src/main/scala/scala/meta/internal/metals/MetalsEnrichments.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,9 +761,10 @@ object MetalsEnrichments
761761
fansi.Str(diag.getMessage, ErrorMode.Strip).plainText,
762762
diag.getSeverity.toLsp,
763763
if (diag.getSource == null) "scalac" else diag.getSource,
764-
// We omit diag.getCode since Bloop's BSP implementation uses 'code' with different semantics
765-
// than LSP. See https://github.com/scalacenter/bloop/issues/1134 for details
766764
)
765+
if (diag.getCode() != null) {
766+
ld.setCode(diag.getCode())
767+
}
767768
ld.setData(diag.getData)
768769
ld
769770
}

0 commit comments

Comments
 (0)