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 168c4f9bd..7edfac093 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 @@ -65,6 +65,7 @@ public enum XMLSchemaErrorCode implements IXMLErrorCode { cvc_complex_type_3_2_2("cvc-complex-type.3.2.2"), // https://wiki.xmldation.com/Support/Validator/cvc-complex-type-3-2-2 cvc_complex_type_4("cvc-complex-type.4"), // https://wiki.xmldation.com/Support/Validator/cvc-complex-type-4 cvc_datatype_valid_1_2_1("cvc-datatype-valid.1.2.1"), // https://wiki.xmldation.com/Support/Validator/cvc-datatype-valid-1-2-1 + cvc_datatype_valid_1_2_3("cvc-datatype-valid.1.2.3"), // https://wiki.xmldation.com/Support/Validator/cvc-datatype-valid-1-2-3 cvc_elt_1_a("cvc-elt.1.a"), // https://wiki.xmldation.com/Support/Validator/cvc-elt-1 cvc_elt_3_1("cvc-elt.3.1"), // https://wiki.xmldation.com/Support/Validator/cvc-elt-3-1 cvc_elt_3_2_1("cvc-elt.3.2.1"), // https://wiki.xmldation.com/Support/Validator/cvc-elt-3-2-1 @@ -223,22 +224,8 @@ public static Range toLSPRange(XMLLocator location, XMLSchemaErrorCode code, Obj case cvc_elt_3_2_1: return XMLPositionUtility.selectContent(offset, document); case cvc_type_3_1_3: - case cvc_datatype_valid_1_2_1: { - String attrValue = getString(arguments[0]); - Range range = XMLPositionUtility.selectAttributeValueFromGivenValue(attrValue, offset, document); - - if (range != null) { - return range; - } - - DOMElement element = (DOMElement) document.findNodeAt(offset); - - if (DOMUtils.containsTextOnly(element)) { - return XMLPositionUtility.selectTrimmedText(offset, document); - } else { - return XMLPositionUtility.selectFirstChild(offset, document); - } - } + case cvc_datatype_valid_1_2_1: + case cvc_datatype_valid_1_2_3: case cvc_enumeration_valid: case cvc_maxlength_valid: case cvc_minlength_valid: @@ -254,7 +241,12 @@ public static Range toLSPRange(XMLLocator location, XMLSchemaErrorCode code, Obj return range; } else { // Try with text - return XMLPositionUtility.selectContent(offset, document); + DOMElement element = (DOMElement) document.findNodeAt(offset); + if (DOMUtils.containsTextOnly(element)) { + return XMLPositionUtility.selectTrimmedText(offset, document); + } else { + return XMLPositionUtility.selectFirstChild(offset, document); + } } } case cvc_type_3_1_2: 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 ae33364f8..8644d3ac0 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 @@ -332,6 +332,17 @@ public void cvc_datatype_valid_1_2_1_TwoElements() throws Exception { d(3, 4, 3, 11, XMLSchemaErrorCode.cvc_type_3_1_3)); } + @Test + public void cvc_datatype_valid_1_2_3OnText() throws Exception { + String xml = "\r\n" + // + "\r\n" + // + " XXX \r\n" + // <-- error + " "; + testDiagnosticsFor(xml, d(3, 15, 3, 18, XMLSchemaErrorCode.cvc_datatype_valid_1_2_3), + d(3, 15, 3, 18, XMLSchemaErrorCode.cvc_type_3_1_3)); + } + @Test public void cvc_maxLength_validOnAttribute() throws Exception { String xml = "\r\n" + // diff --git a/org.eclipse.lemminx/src/test/resources/validation/schema/cvc-datatype-valid.1.2.3.xml b/org.eclipse.lemminx/src/test/resources/validation/schema/cvc-datatype-valid.1.2.3.xml new file mode 100644 index 000000000..05dde905d --- /dev/null +++ b/org.eclipse.lemminx/src/test/resources/validation/schema/cvc-datatype-valid.1.2.3.xml @@ -0,0 +1,5 @@ + + + XXX + \ No newline at end of file diff --git a/org.eclipse.lemminx/src/test/resources/xsd/dressSize.xsd b/org.eclipse.lemminx/src/test/resources/xsd/dressSize.xsd new file mode 100644 index 000000000..6b076ff9a --- /dev/null +++ b/org.eclipse.lemminx/src/test/resources/xsd/dressSize.xsd @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file