Skip to content

Commit

Permalink
Fix src-element.3 error range
Browse files Browse the repository at this point in the history
Signed-off-by: David Kwon <[email protected]>
  • Loading branch information
dkwon17 authored and angelozerr committed Jun 17, 2019
1 parent ca21f48 commit 39fc1fc
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public enum XMLSchemaErrorCode implements IXMLErrorCode {
cvc_minInclusive_valid("cvc-minInclusive-valid"), // https://wiki.xmldation.com/Support/validator/cvc-mininclusive-valid
TargetNamespace_2("TargetNamespace.2"),
SchemaLocation("SchemaLocation"),
schema_reference_4("schema_reference.4"); //
schema_reference_4("schema_reference.4"), //
src_element_3("src-element.3");

private final String code;

Expand Down Expand Up @@ -128,6 +129,7 @@ public static Range toLSPRange(XMLLocator location, XMLSchemaErrorCode code, Obj
case cvc_complex_type_2_4_f:
case cvc_elt_1_a:
case cvc_complex_type_4:
case src_element_3:
case TargetNamespace_2:
return XMLPositionUtility.selectStartTag(offset, document);
case cvc_complex_type_3_2_2: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public enum XSDErrorCode implements IXMLErrorCode {
s4s_att_not_allowed("s4s-att-not-allowed"), //
s4s_att_invalid_value("s4s-att-invalid-value"), //
s4s_elt_character("s4s-elt-character"), //
src_element_3("src-element.3"),
src_resolve_4_2("src-resolve.4.2"), //
src_resolve("src-resolve"), src_element_2_1("src-element.2.1");

Expand Down Expand Up @@ -104,6 +105,7 @@ public static Range toLSPRange(XMLLocator location, XSDErrorCode code, Object[]
case s4s_att_must_appear:
case s4s_elt_invalid_content_2:
case src_element_2_1:
case src_element_3:
return XMLPositionUtility.selectStartTag(offset, document);
case s4s_att_not_allowed: {
String attrName = (String) arguments[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,15 @@ public void cvc_type_3_1_2() throws Exception {
d(4,10,4,17, XMLSchemaErrorCode.cvc_type_3_1_3));
}

@Test
public void testSrcElement3() throws Exception {
String xml = "<a xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + //
" xsi:noNamespaceSchemaLocation=\"src/test/resources/xsd/srcElement3.xsd\">\r\n" +
" <b></b>\r\n" +
"</a>";
testDiagnosticsFor(xml, d(0, 1, 0, 2, XMLSchemaErrorCode.src_element_3));
}

private static void testDiagnosticsFor(String xml, Diagnostic... expected) {
XMLAssert.testDiagnosticsFor(xml, "src/test/resources/catalogs/catalog.xml", expected);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,20 @@ public void src_element_2_1() throws BadLocationException {
d(5, 17, 5, 27, XSDErrorCode.src_element_2_1));
}

@Test
public void src_element_3() throws BadLocationException {
String xml = "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\r\n" +
" <xs:element name=\"a\" type=\"xs:integer\">\r\n" +
" <xs:complexType>\r\n" +
" <xs:sequence>\r\n" +
" <xs:element name=\"b\"></xs:element>\r\n" +
" </xs:sequence>\r\n" +
" </xs:complexType>\r\n" +
" </xs:element>\r\n" +
"</xs:schema>";
testDiagnosticsFor(xml, d(1, 3, 1, 13, XSDErrorCode.src_element_3));
}

private static void testDiagnosticsFor(String xml, Diagnostic... expected) throws BadLocationException {
XMLAssert.testDiagnosticsFor(xml, null, null, "test.xsd", expected);
}
Expand Down
9 changes: 9 additions & 0 deletions org.eclipse.lsp4xml/src/test/resources/xsd/srcElement3.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="a" type="xs:integer">
<xs:complexType>
<xs:sequence>
<xs:element name="b"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

0 comments on commit 39fc1fc

Please sign in to comment.