diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/contentmodel/participants/XMLSchemaErrorCode.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/contentmodel/participants/XMLSchemaErrorCode.java index b153d7d578..a01d0a457b 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/contentmodel/participants/XMLSchemaErrorCode.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/contentmodel/participants/XMLSchemaErrorCode.java @@ -46,8 +46,10 @@ public enum XMLSchemaErrorCode implements IXMLErrorCode { 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_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 cvc_elt_4_2("cvc-elt.4.2"), // https://wiki.xmldation.com/Support/Validator/cvc-elt-4-2 cvc_type_3_1_1("cvc-type.3.1.1"), // https://wiki.xmldation.com/Support/Validator/cvc-type-3-1-1 + cvc_type_3_1_2("cvc-type.3.1.2"), // https://wiki.xmldation.com/Support/Validator/cvc-type-3-1-2 cvc_type_3_1_3("cvc-type.3.1.3"), // https://wiki.xmldation.com/Support/Validator/cvc-type-3-1-3, cvc_attribute_3("cvc-attribute.3"), // https://wiki.xmldation.com/Support/Validator/cvc-attribute-3 cvc_enumeration_valid("cvc-enumeration-valid"), // https://wiki.xmldation.com/Support/Validator/cvc-enumeration-valid @@ -148,7 +150,8 @@ public static Range toLSPRange(XMLLocator location, XMLSchemaErrorCode code, Obj return XMLPositionUtility.selectAllAttributes(offset, document); case cvc_complex_type_2_1: case cvc_type_3_1_3: - return XMLPositionUtility.selectText(offset, document); + case cvc_elt_3_2_1: + return XMLPositionUtility.selectContent(offset, document); case cvc_enumeration_valid: case cvc_datatype_valid_1_2_1: case cvc_maxlength_valid: @@ -165,9 +168,11 @@ public static Range toLSPRange(XMLLocator location, XMLSchemaErrorCode code, Obj return range; } else { // Try with text - return XMLPositionUtility.selectText(offset, document); + return XMLPositionUtility.selectContent(offset, document); } } + case cvc_type_3_1_2: + return XMLPositionUtility.selectStartTag(offset, document); default: } return null; diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/contentmodel/participants/XMLSyntaxErrorCode.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/contentmodel/participants/XMLSyntaxErrorCode.java index c5805285c4..ccea5db4d4 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/contentmodel/participants/XMLSyntaxErrorCode.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/contentmodel/participants/XMLSyntaxErrorCode.java @@ -127,7 +127,16 @@ public static Range toLSPRange(XMLLocator location, XMLSyntaxErrorCode code, Obj return XMLPositionUtility.selectAttributeValueByGivenValueAt(attrValue, offset, document); } case ETagUnterminated: - return XMLPositionUtility.selectPreviousEndTag(offset - 1, document); + /** + * Cases: + * + * + * + * + * + * This will include the tag it starts in if the offset is within a tag's content:
+ *+ * {@code | } , will give {@code } + *
+ * + * or within an unclosed end tag: + * + *+ * {@code } , will give {@code } + *
+ * + * + *+ * {@code } , will give {@code } + *
* - * eg: - * | , will give 'b' - * , will give 'a' */ - public static Range selectPreviousEndTag(int offset, DOMDocument document) { + public static Range selectPreviousNodesEndTag(int offset, DOMDocument document) { + + DOMNode node = null; + DOMNode nodeAt = document.findNodeAt(offset); + if(nodeAt != null && nodeAt.isElement()) { + node = nodeAt; + } else { + DOMNode nodeBefore = document.findNodeBefore(offset); + if(nodeBefore != null && nodeBefore.isElement()) { + node = nodeBefore; + } + } + if(node != null) { + DOMElement element = (DOMElement) node; + if(element.isClosed() && element.getEndTagCloseOffset() == null) { + return selectEndTag(element.getEnd(), document); + } + } + // boolean firstBracket = false; int i = offset; char c = document.getText().charAt(i); @@ -337,18 +366,15 @@ public static Range createRange(int startOffset, int endOffset, DOMDocument docu } } - public static Range selectText(int offset, DOMDocument document) { + public static Range selectContent(int offset, DOMDocument document) { DOMNode node = document.findNodeAt(offset); if (node != null) { - if (node.hasChildNodes()) { - //