From 3200147d56adcb3fcc63b2ad0c5a80640ca6d3f7 Mon Sep 17 00:00:00 2001 From: Anup Chenthamarakshan Date: Wed, 25 Sep 2024 20:15:32 +0000 Subject: [PATCH] Avoid NPE when no severity is supplied in PublishDiagnosticsParams.Diagnostic Per spec https://build-server-protocol.github.io/docs/specification#diagnostic: ``` /** The diagnostic's severity. Can be omitted. If omitted it is up to the * client to interpret diagnostics as error, warning, info or hint. */ severity?: DiagnosticSeverity; ``` --- .../scala/scala/meta/internal/metals/MetalsEnrichments.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/metals/src/main/scala/scala/meta/internal/metals/MetalsEnrichments.scala b/metals/src/main/scala/scala/meta/internal/metals/MetalsEnrichments.scala index b00b90bf99f..e53f686a3af 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/MetalsEnrichments.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/MetalsEnrichments.scala @@ -971,7 +971,8 @@ object MetalsEnrichments val ld = new l.Diagnostic( diag.getRange.toLsp, fansi.Str(diag.getMessage, ErrorMode.Strip).plainText, - diag.getSeverity.toLsp, + if (diag.getSeverity == null) l.DiagnosticSeverity.Warning + else diag.getSeverity.toLsp, if (diag.getSource == null) "scalac" else diag.getSource, ) Option(diag.getCode()).foreach { code =>