Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XSD: IntelliSense and element substitutions #568

Merged
merged 1 commit into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>