Skip to content

Commit

Permalink
XSD: IntelliSense and element substitutions
Browse files Browse the repository at this point in the history
  • Loading branch information
angelozerr committed Oct 7, 2019
1 parent 9d9974f commit 897854c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void collectElement(XSElementDeclaration elementDeclaration, Collection<CMElemen
// element declaration is marked as abstract
// ex with xsl: <xs:element name="declaration" type="xsl:generic-element-type"
// abstract="true"/>
XSObjectList list = model.getSubstitutionGroup(elementDeclaration);
XSObjectList list = getSubstitutionGroup(elementDeclaration);
if (list != null) {
// it exists elements list bind with this abstract declaration with
// substitutionGroup
Expand All @@ -181,6 +181,10 @@ void collectElement(XSElementDeclaration elementDeclaration, Collection<CMElemen
}
}

XSObjectList getSubstitutionGroup(XSElementDeclaration elementDeclaration) {
return model.getSubstitutionGroup(elementDeclaration);
}

@Override
public CMElementDeclaration findCMElement(DOMElement element, String namespace) {
List<DOMElement> paths = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ public Collection<CMElementDeclaration> getPossibleElements(DOMElement parentEle
if (object instanceof XSElementDeclaration) {
XSElementDeclaration elementDecl = (XSElementDeclaration) object;
document.collectElement(elementDecl, possibleElements);
// Collect substitution group
XSObjectList group = document.getSubstitutionGroup(elementDecl);
if (group != null) {
for (int i = 0; i < group.getLength(); i++) {
XSElementDeclaration o = (XSElementDeclaration) group.item(i);
document.collectElement(o, possibleElements);
}
}
} else {
// case with xs:any. Ex:
// <xs:sequence>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,15 @@ public void xsAnyDuplicate() throws IOException, BadLocationException {
c("DockLayout", te(2, 1, 2, 1, "<DockLayout></DockLayout>"), "DockLayout", "Source: tns.xsd",
MarkupKind.PLAINTEXT));
}

@Test
public void substitutionGroup() throws BadLocationException {
String xml = "<fleet xmlns=\"http://example/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://example/ xsd/substitutionGroup.xsd\">\r\n"
+ " | ";
XMLAssert.testCompletionFor(xml, null, "src/test/resources/substitutionGroup.xml", null,
c("truck", "<truck />"), //
c("automobile", "<automobile />"));
}

@Test
public void tag() throws BadLocationException {
Expand Down
25 changes: 25 additions & 0 deletions org.eclipse.lsp4xml/src/test/resources/xsd/substitutionGroup.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://example/" targetNamespace="http://example/">
<xs:complexType name="AutomobileType">
<xs:attribute name="topSpeed" type="xs:float" />
</xs:complexType>
<xs:complexType name="TruckType">
<xs:complexContent>
<xs:extension base="AutomobileType">
<xs:attribute name="payloadCapacity" type="xs:float" />
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:element name="automobile" type="AutomobileType"/>
<xs:element name="truck" type="TruckType" substitutionGroup="automobile"/>

<xs:element name="fleet">
<xs:complexType>
<xs:sequence>
<xs:choice maxOccurs="unbounded">
<xs:element ref="automobile" minOccurs="0" maxOccurs="unbounded" />
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

0 comments on commit 897854c

Please sign in to comment.