Skip to content

Commit

Permalink
Specify severity on diagnostics (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
cherylking authored Jan 11, 2024
1 parent b6c0eb4 commit 76d37ca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -81,7 +82,7 @@ private List<Diagnostic> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,7 +77,8 @@ protected void checkDiagnosticsContainsMessages(String... messages) {
List<String> expectedMessages = new LinkedList<String>(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());
Expand Down

0 comments on commit 76d37ca

Please sign in to comment.