From 02426170a86b0c20ec4dee00a15895b5e58b7aab Mon Sep 17 00:00:00 2001 From: azerr Date: Mon, 7 Oct 2019 10:26:47 +0200 Subject: [PATCH] XSD: IntelliSense and element substitutions See https://github.com/redhat-developer/vscode-xml/issues/186 Signed-off-by: azerr --- .../xsd/contentmodel/CMXSDDocument.java | 6 ++++- .../contentmodel/CMXSDElementDeclaration.java | 8 ++++++ .../XMLSchemaCompletionExtensionsTest.java | 9 +++++++ .../test/resources/xsd/substitutionGroup.xsd | 25 +++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 org.eclipse.lsp4xml/src/test/resources/xsd/substitutionGroup.xsd diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/xsd/contentmodel/CMXSDDocument.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/xsd/contentmodel/CMXSDDocument.java index 9d56f5e41..46299b428 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/xsd/contentmodel/CMXSDDocument.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/xsd/contentmodel/CMXSDDocument.java @@ -159,7 +159,7 @@ void collectElement(XSElementDeclaration elementDeclaration, Collection - XSObjectList list = model.getSubstitutionGroup(elementDeclaration); + XSObjectList list = getSubstitutionGroup(elementDeclaration); if (list != null) { // it exists elements list bind with this abstract declaration with // substitutionGroup @@ -181,6 +181,10 @@ void collectElement(XSElementDeclaration elementDeclaration, Collection paths = new ArrayList<>(); diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/xsd/contentmodel/CMXSDElementDeclaration.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/xsd/contentmodel/CMXSDElementDeclaration.java index 85268dfe3..b4a91e914 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/xsd/contentmodel/CMXSDElementDeclaration.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/xsd/contentmodel/CMXSDElementDeclaration.java @@ -164,6 +164,14 @@ public Collection 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: // diff --git a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/extensions/contentmodel/XMLSchemaCompletionExtensionsTest.java b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/extensions/contentmodel/XMLSchemaCompletionExtensionsTest.java index eef3e6928..183f44c56 100644 --- a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/extensions/contentmodel/XMLSchemaCompletionExtensionsTest.java +++ b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/extensions/contentmodel/XMLSchemaCompletionExtensionsTest.java @@ -779,6 +779,15 @@ public void xsAnyDuplicate() throws IOException, BadLocationException { c("DockLayout", te(2, 1, 2, 1, ""), "DockLayout", "Source: tns.xsd", MarkupKind.PLAINTEXT)); } + + @Test + public void substitutionGroup() throws BadLocationException { + String xml = "\r\n" + + " | "; + XMLAssert.testCompletionFor(xml, null, "src/test/resources/substitutionGroup.xml", null, + c("truck", ""), // + c("automobile", "")); + } @Test public void tag() throws BadLocationException { diff --git a/org.eclipse.lsp4xml/src/test/resources/xsd/substitutionGroup.xsd b/org.eclipse.lsp4xml/src/test/resources/xsd/substitutionGroup.xsd new file mode 100644 index 000000000..2356f159b --- /dev/null +++ b/org.eclipse.lsp4xml/src/test/resources/xsd/substitutionGroup.xsd @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file