Skip to content

Commit

Permalink
added src-import.3.2 XSD error highlighting support
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Chen authored and datho7561 committed Jul 20, 2021
1 parent 33c8672 commit 0007ad4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public enum XSDErrorCode implements IXMLErrorCode {
src_resolve_4_2("src-resolve.4.2"), //
src_resolve("src-resolve"), src_element_2_1("src-element.2.1"),
EmptyTargetNamespace("EmptyTargetNamespace"),
src_import_3_1("src-import.3.1");
src_import_3_1("src-import.3.1"),
src_import_3_2("src-import.3.2");

private final String code;

Expand Down Expand Up @@ -177,6 +178,8 @@ public static Range toLSPRange(XMLLocator location, XSDErrorCode code, Object[]
return XMLPositionUtility.selectAttributeValueAt(XSDUtils.NAMESPACE_ATTR, offset, document);
}
}
case src_import_3_2:
return XMLPositionUtility.selectChildNodeAttributeValueFromGivenNameAt(XSDUtils.XS_IMPORT_TAG, XSDUtils.SCHEMA_LOCATION_ATTR, offset, document);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,19 @@ public void src_import_3_1_BadNamespaceWithSchemaContent() throws BadLocationExc
testDiagnosticsFor(xsd, d);
}

@Test
public void src_import_3_2_NoNamespaceFound() throws BadLocationException {
String xsd = "<xs:schema\n" +
"xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n" +
"targetNamespace=\"http://example.org/my-example\"\n" +
"xmlns:NS=\"http://example.org/my-example\">\n" +
"<xs:import schemaLocation=\"src/test/resources/xsd/baseSchema.xsd\"/>\n" +
"</xs:schema>";

Diagnostic d = d(4, 26, 4, 65, XSDErrorCode.src_import_3_2);
testDiagnosticsFor(xsd, d);
}


private static void testDiagnosticsFor(String xml, Diagnostic... expected) throws BadLocationException {
XMLAssert.testDiagnosticsFor(xml, null, null, "test.xsd", expected);
Expand Down
10 changes: 5 additions & 5 deletions org.eclipse.lemminx/src/test/resources/xsd/baseSchema.xsd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root-element">

</xs:element>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://foo.bar"
>
<xs:element name="root-element"></xs:element>
</xs:schema>

0 comments on commit 0007ad4

Please sign in to comment.