Skip to content

Commit

Permalink
In Maven <configuration>, all known XML elements from schema are
Browse files Browse the repository at this point in the history
suggested as completion

Fixes eclipse-lemminx#612

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Mar 12, 2020
1 parent d8556f4 commit de76603
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.lemminx.services.extensions.ICompletionResponse;
import org.eclipse.lemminx.settings.XMLFormattingOptions;
import org.eclipse.lemminx.uriresolver.CacheResourceDownloadingException;
import org.eclipse.lemminx.utils.StringUtils;
import org.eclipse.lsp4j.CompletionItem;
import org.eclipse.lsp4j.CompletionItemKind;
import org.eclipse.lsp4j.InsertTextFormat;
Expand Down Expand Up @@ -202,7 +203,7 @@ private static void addTagName(NodeList list, Set<String> tags, ICompletionReque
if (Node.ELEMENT_NODE == node.getNodeType()) {
DOMElement elt = (DOMElement) node;
String tagName = elt.getTagName();
if (!tags.contains(tagName)) {
if (!StringUtils.isEmpty(tagName) && !tags.contains(tagName)) {
CompletionItem item = new CompletionItem(tagName);
item.setKind(CompletionItemKind.Property);
item.setFilterText(request.getFilterForStartTagName(tagName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,12 @@ private Collection<CMElementDeclaration> getXSAnyElements(Object declaration) {
// xs:any
switch (processContents) {
case XSWildcard.PC_STRICT:
// <xs:any processContents="strict" />
case XSWildcard.PC_SKIP:
// <xs:any processContents="strict" /> or <xs:any processContents="skip" />
// only global element declaration from the XML Schema are allowed
return document.getElements();
default:
// <xs:any processContents="lax" /> or <xs:any processContents="skip" />
// <xs:any processContents="lax" />
// all tags are allowed.
return ANY_ELEMENT_DECLARATIONS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@

import org.apache.xerces.impl.XMLEntityManager;
import org.apache.xerces.util.URI.MalformedURIException;
import org.eclipse.lsp4j.CompletionCapabilities;
import org.eclipse.lsp4j.CompletionItem;
import org.eclipse.lsp4j.CompletionItemCapabilities;
import org.eclipse.lsp4j.MarkupKind;
import org.eclipse.lemminx.XMLAssert;
import org.eclipse.lemminx.commons.BadLocationException;
import org.eclipse.lemminx.services.XMLLanguageService;
import org.eclipse.lemminx.settings.XMLCompletionSettings;
import org.eclipse.lsp4j.CompletionCapabilities;
import org.eclipse.lsp4j.CompletionItem;
import org.eclipse.lsp4j.CompletionItemCapabilities;
import org.eclipse.lsp4j.MarkupKind;
import org.junit.Test;

/**
Expand Down Expand Up @@ -370,7 +370,7 @@ public void completionWithXMLSchemaContentChanged() throws Exception {
+ " </xs:sequence>\r\n"
+ " <xs:attribute name=\"variant\" type=\"xs:string\" use=\"required\"/>\r\n"
+ " </xs:complexType>\r\n" + " </xs:element>\r\n" + "</xs:schema>";

createFile(xsdPath, schema);
XMLAssert.testCompletionFor(xmlLanguageService, xml, null, null, "target/resources.xml", 5, false,
c("variant", "variant=\"\""));
Expand Down Expand Up @@ -763,6 +763,42 @@ public void xsAny() throws IOException, BadLocationException {
XMLAssert.testCompletionFor(xmlLanguageService, xml, null, null, "target/any.xml", 4, true);
}

@Test
public void xsAnySkip() throws BadLocationException {
String xml = "<project xmlns=\"http://maven.apache.org/POM/4.0.0\"\r\n" + //
" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\"\r\n"
+ //
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n" + //
" <modelVersion>4.0.0</modelVersion>\r\n" + //
"\r\n" + //
" <groupId>org.test</groupId>\r\n" + //
" <artifactId>test</artifactId>\r\n" + //
" <version>0.0.1-SNAPSHOT</version>\r\n" + //
" <packaging>pom</packaging>\r\n" + //
" \r\n" + //
" <build>\r\n" + //
" <plugins>\r\n" + //
" <plugin>\r\n" + //
" <groupId>org.apache.maven.plugins</groupId>\r\n" + //
" <artifactId>maven-dependency-plugin</artifactId>\r\n" + //
" <version>3.1.1</version>\r\n" + //
" <executions>\r\n" + //
" <execution>\r\n" + //
" <goals><goal>list</goal></goals>\r\n" + //
" <configuration>\r\n" + //
" <|>\r\n" + // <-- completion is triggered here (configuration has xs:any
// processContents="skip"), it must return only project element.
" </configuration>\r\n" + //
" </execution>\r\n" + //
" </executions>\r\n" + //
" </plugin>\r\n" + //
" </plugins>\r\n" + //
" </build>\r\n" + //
"</project>";
XMLAssert.testCompletionFor(xml, "src/test/resources/catalogs/catalog.xml", null,
3 /* project, comment and cdata */, c("project", te(20, 7, 20, 9, "<project></project>"), "<project"));
}

@Test
public void xsAnyDuplicate() throws IOException, BadLocationException {
String xml = "<Page loaded=\"pageLoaded\" class=\"page\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"xsd/tns.xsd\" >\r\n"
Expand All @@ -777,7 +813,7 @@ 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"
Expand Down

0 comments on commit de76603

Please sign in to comment.