Skip to content

Commit

Permalink
Adjust error range for RelaxNG element-not-allow-yet error
Browse files Browse the repository at this point in the history
Signed-off-by: Jessica He <jhe@redhat.com>
  • Loading branch information
JessicaJHee authored and datho7561 committed Mar 9, 2023
1 parent fb9eabd commit 705f1cf
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
Expand Up @@ -127,6 +127,7 @@ public static Range toLSPRange(XMLLocator location, RelaxNGErrorCode rngCode, Ob
// XML Validation based on RNG, RNC errors
case unknown_element:
case out_of_context_element:
case element_not_allowed_yet:
case incomplete_element_required_elements_missing_expected:
case unexpected_element_required_element_missing:
case incomplete_element_required_element_missing:
Expand Down
Expand Up @@ -103,6 +103,10 @@ private static RelaxNGReportInfo getRelaxNGReportInfo(String message) {
// out_of_context_element=element {0} not allowed here{1}
return new RelaxNGReportInfo(RelaxNGErrorCode.out_of_context_element);
}
if (message.contains("not allowed yet")) {
// element {0} not allowed yet{1}
return new RelaxNGReportInfo(RelaxNGErrorCode.element_not_allowed_yet);
}

// Required attributes

Expand Down
Expand Up @@ -161,4 +161,14 @@ public void required_attributes_missing() throws Exception {
d(1, 1, 4, RelaxNGErrorCode.incomplete_element_required_elements_missing_expected));
}

@Test
public void not_allowed_yet() throws Exception {
String xml = "<?xml-model href=\"notAllowedYet.rng\"?>\r\n" + //
"<root>\r\n" + //
" <element2></element2>\r\n" + //
"</root>";
testDiagnosticsFor(xml, null, null, "src/test/resources/relaxng/test.xml", //
d(2, 2, 10, RelaxNGErrorCode.element_not_allowed_yet));
}

}
21 changes: 21 additions & 0 deletions org.eclipse.lemminx/src/test/resources/relaxng/notAllowedYet.rng
@@ -0,0 +1,21 @@
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<start>
<ref name="rootElt" />
</start>
<define name="rootElt">
<element name="root">
<choice>
<element name="elementA">
<text />
</element>
<element name="elementB">
<text />
</element>
</choice>
<element name="element2">
<text />
</element>
</element>
</define>
</grammar>

0 comments on commit 705f1cf

Please sign in to comment.