Skip to content

Commit

Permalink
Fix error range for cvc-pattern-valid
Browse files Browse the repository at this point in the history
Signed-off-by: David Kwon <dakwon@redhat.com>
  • Loading branch information
dkwon17 authored and angelozerr committed Jun 28, 2019
1 parent 85bf167 commit fee5859
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public enum XMLSchemaErrorCode implements IXMLErrorCode {
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_pattern_valid("cvc-pattern-valid"), // https://wiki.xmldation.com/Support/Validator/cvc-pattern-valid
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,
Expand Down Expand Up @@ -150,6 +151,10 @@ public static Range toLSPRange(XMLLocator location, XMLSchemaErrorCode code, Obj
}
return XMLPositionUtility.selectAttributeFromGivenNameAt(attrName, offset, document);
}
case cvc_pattern_valid: {
String attrValue = (String) arguments[0];
return XMLPositionUtility.selectAttributeValueByGivenValueAt(attrValue, offset, document);
}
case SchemaLocation:
case schema_reference_4: {
DOMNode attrValueNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,17 @@ public void cvc_complex_type_2_1WithLinefeed() throws Exception {
testCodeActionsFor(xml, d, ca(d, te(5, 25, 7, 8, "/>")));
}

@Test
public void cvc_pattern_valid() throws Exception {
String xml = "<Annotation\r\n" +
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" +
" xsi:noNamespaceSchemaLocation=\"src/test/resources/xsd/pattern.xsd\"\r\n" +
" Term=\"X\"></Annotation>";
Diagnostic patternValid = d(3, 6, 3, 9, XMLSchemaErrorCode.cvc_pattern_valid);
Diagnostic cvcAttribute3 = d(3, 6, 3, 9, XMLSchemaErrorCode.cvc_attribute_3);
testDiagnosticsFor(xml, patternValid, cvcAttribute3);
}

/**
* @see https://github.com/angelozerr/lsp4xml/issues/217
*/
Expand Down
20 changes: 20 additions & 0 deletions org.eclipse.lsp4xml/src/test/resources/xsd/pattern.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">

<xs:element name="Annotation">
<xs:complexType>
<xs:attribute name="Term" type="TQualifiedName"
use="required" />
</xs:complexType>
</xs:element>


<xs:simpleType name="TQualifiedName">
<xs:restriction base="xs:NCName">
<xs:pattern
value="[\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}(\.[\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}){1,}" />
</xs:restriction>
</xs:simpleType>

</xs:schema>

0 comments on commit fee5859

Please sign in to comment.