From 76d37cab85490be2838c521b3d8cee3a99719ed3 Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Thu, 11 Jan 2024 08:45:25 -0600 Subject: [PATCH] Specify severity on diagnostics (#262) --- .../diagnostic/LibertyPropertiesDiagnosticService.java | 5 +++-- .../tools/langserver/diagnostic/AbstractDiagnosticTest.java | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/liberty-ls/src/main/java/io/openliberty/tools/langserver/diagnostic/LibertyPropertiesDiagnosticService.java b/liberty-ls/src/main/java/io/openliberty/tools/langserver/diagnostic/LibertyPropertiesDiagnosticService.java index 72222480..00762626 100644 --- a/liberty-ls/src/main/java/io/openliberty/tools/langserver/diagnostic/LibertyPropertiesDiagnosticService.java +++ b/liberty-ls/src/main/java/io/openliberty/tools/langserver/diagnostic/LibertyPropertiesDiagnosticService.java @@ -1,5 +1,5 @@ /******************************************************************************* -* Copyright (c) 2022, 2023 IBM Corporation and others. +* Copyright (c) 2022, 2024 IBM Corporation and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at @@ -26,6 +26,7 @@ import java.util.logging.Logger; import org.eclipse.lsp4j.Diagnostic; +import org.eclipse.lsp4j.DiagnosticSeverity; import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.Range; @@ -81,7 +82,7 @@ private List computeInvalidValuesDiagnostic(PropertiesValidationResu // Currently the last arg (getIntegerRange) is only used for the Integer messages which use {2}. Otherwise null is passed and is ignored by the other messages. String message = MessageFormat.format(messageTemplate, validationResult.getValue(), property, ServerPropertyValues.getIntegerRange(property)); - lspDiagnostics.add(new Diagnostic(computeRange(validationResult, lineContentInError), message)); + lspDiagnostics.add(new Diagnostic(computeRange(validationResult, lineContentInError), message, DiagnosticSeverity.Error, "Liberty Config Language Server")); } return lspDiagnostics; } diff --git a/liberty-ls/src/test/java/io/openliberty/tools/langserver/diagnostic/AbstractDiagnosticTest.java b/liberty-ls/src/test/java/io/openliberty/tools/langserver/diagnostic/AbstractDiagnosticTest.java index ffbe36d7..2d6be0ad 100644 --- a/liberty-ls/src/test/java/io/openliberty/tools/langserver/diagnostic/AbstractDiagnosticTest.java +++ b/liberty-ls/src/test/java/io/openliberty/tools/langserver/diagnostic/AbstractDiagnosticTest.java @@ -25,6 +25,7 @@ import org.awaitility.core.ConditionFactory; import org.eclipse.lsp4j.Diagnostic; +import org.eclipse.lsp4j.DiagnosticSeverity; import org.eclipse.lsp4j.DidOpenTextDocumentParams; import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.Range; @@ -76,7 +77,8 @@ protected void checkDiagnosticsContainsMessages(String... messages) { List expectedMessages = new LinkedList(Arrays.asList(messages)); for (Diagnostic diag : diags) { - assertFalse(diag.getMessage().isEmpty()); + assertFalse("Diagnostic message is unexpectedly empty.", diag.getMessage().isEmpty()); + assertTrue("Diagnostic severity not set to Error as expected.", diag.getSeverity() == DiagnosticSeverity.Error); expectedMessages.remove(diag.getMessage()); } assertEquals("Did not find all the expected diagnostic messages. These messages were not found: " + expectedMessages.toString(), 0, expectedMessages.size());