diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/participants/XMLSchemaErrorCode.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/participants/XMLSchemaErrorCode.java index 7edfac0937..c80898c6ba 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/participants/XMLSchemaErrorCode.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/participants/XMLSchemaErrorCode.java @@ -48,7 +48,7 @@ /** * XML Schema error code. - * + * * @see https://wiki.xmldation.com/Support/Validator * */ @@ -126,7 +126,7 @@ public static XMLSchemaErrorCode get(String name) { /** * Create the LSP range from the SAX error. - * + * * @param location * @param key * @param arguments @@ -242,7 +242,9 @@ public static Range toLSPRange(XMLLocator location, XMLSchemaErrorCode code, Obj } else { // Try with text DOMElement element = (DOMElement) document.findNodeAt(offset); - if (DOMUtils.containsTextOnly(element)) { + if (element != null && element.isEmpty()) { + return XMLPositionUtility.createRange(element); + } else if (DOMUtils.containsTextOnly(element)) { return XMLPositionUtility.selectTrimmedText(offset, document); } else { return XMLPositionUtility.selectFirstChild(offset, document); diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSchemaDiagnosticsTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSchemaDiagnosticsTest.java index 8644d3ac09..6d9f4455ff 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSchemaDiagnosticsTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSchemaDiagnosticsTest.java @@ -85,7 +85,7 @@ public void cvc_type_4_Multiple_attributes() throws Exception { String xml = "\r\n" + // "\r\n" + // - " 2017-11-30\r\n" + // + " 2017-11-30\r\n" + // " 2\r\n" + // " \r\n" + // " \r\n" + // <- error @@ -103,7 +103,7 @@ public void cvc_type_4_Multiple_attributes() throws Exception { @Test public void cvc_complex_type_2_4_a() throws Exception { - String xml = + String xml = "\r\n"+ // @@ -142,7 +142,7 @@ public void cvc_complex_type_2_4_d() throws Exception { @Test public void cvc_complex_type_2_4_f() throws Exception { - String xml = + String xml = "\r\n" + // "\r\n" + // + ""; + testDiagnosticsFor(xml, d(1, 0, 2, 82, XMLSchemaErrorCode.cvc_datatype_valid_1_2_3), + d(1, 0, 2, 82, XMLSchemaErrorCode.cvc_type_3_1_3)); + } + @Test public void cvc_maxLength_validOnAttribute() throws Exception { String xml = "\r\n" + // @@ -386,12 +395,12 @@ public void cvc_complex_type_2_1() throws Exception { @Test public void cvc_complex_type_2_1_SelfClosing() throws Exception { String xml = " "; - + Diagnostic d = d(0, 143, 0, 144, XMLSchemaErrorCode.cvc_complex_type_2_1); testDiagnosticsFor(xml, d); testCodeActionsFor(xml, d, ca(d, te(0, 142, 0, 152, "/>"))); } - + @Test public void cvc_complex_type_2_1WithLinefeed() throws Exception { String xml = "\r\n" + // @@ -472,7 +481,7 @@ public void cvc_type_3_1_2() throws Exception { String xml = "\r\n" + // "\r\n" + // - " 2017-11-30\r\n" + // + " 2017-11-30\r\n" + // " \r\n" + //<- error " \r\n" + // " \r\n" + // @@ -481,7 +490,7 @@ public void cvc_type_3_1_2() throws Exception { " \r\n" + // " \r\n" + // ""; - testDiagnosticsFor(xml, + testDiagnosticsFor(xml, d(4, 3, 4, 9, XMLSchemaErrorCode.cvc_type_3_1_2), d(4,10,4,17, XMLSchemaErrorCode.cvc_datatype_valid_1_2_1), d(4,10,4,17, XMLSchemaErrorCode.cvc_type_3_1_3)); @@ -535,7 +544,7 @@ public void schema_reference_4_schemaLocationMultipleBothWrong() { @Test public void fuzzyElementNameCodeActionTest() throws Exception { - String xml = + String xml = "\r\n" + @@ -552,7 +561,7 @@ public void fuzzyElementNameCodeActionTest() throws Exception { @Test public void fuzzyElementNamesWithOtherOptionsCodeActionTest() throws Exception { - String xml = + String xml = "\r\n" + @@ -569,7 +578,7 @@ public void fuzzyElementNamesWithOtherOptionsCodeActionTest() throws Exception { @Test public void fuzzyElementNamesWithPrefix() throws Exception { - String xml = + String xml = ""; Diagnostic diagnostic = d(5, 4, 5, 17, XMLSchemaErrorCode.cvc_complex_type_2_4_c, "cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'schemaA:XXXXX'."); testDiagnosticsFor(xml, diagnostic); - testCodeActionsFor(xml, diagnostic, ca(diagnostic, te(5, 12, 5, 17, "AElement1"), te(5, 28, 5, 33, "AElement1")), + testCodeActionsFor(xml, diagnostic, ca(diagnostic, te(5, 12, 5, 17, "AElement1"), te(5, 28, 5, 33, "AElement1")), ca(diagnostic, te(5, 12, 5, 17, "AElement2"), te(5, 28, 5, 33, "AElement2"))); } @@ -652,7 +661,7 @@ public void testTargetNamespace_1ShortNS() throws Exception { ); testCodeActionsFor(xml, targetNamespace, ca(targetNamespace, te(2, 23, 2, 26, "\"http://two-letter-name\""))); } - + @Test public void testTargetNamespace_1SingleQuotes() throws Exception { String xml = "\n" + //