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 ecb9315d4..5704b03f1 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 @@ -13,9 +13,14 @@ import static org.eclipse.lsp4xml.XMLAssert.c; import static org.eclipse.lsp4xml.XMLAssert.te; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + import org.eclipse.lsp4j.CompletionItem; import org.eclipse.lsp4xml.XMLAssert; import org.eclipse.lsp4xml.commons.BadLocationException; +import org.eclipse.lsp4xml.services.XMLLanguageService; import org.junit.Ignore; import org.junit.Test; @@ -246,7 +251,8 @@ public void schemaLocationWithElementAndAttributeCompletion() throws BadLocation "\r\n" + // " "; - XMLAssert.testCompletionFor(xml, null, "src/test/resources/simpleAttribute.xml", null, c("product", "")); + XMLAssert.testCompletionFor(xml, null, "src/test/resources/simpleAttribute.xml", null, + c("product", "")); } @Test @@ -268,37 +274,99 @@ public void completionWithoutStartBracket() throws BadLocationException { + // " |" + ""; XMLAssert.testCompletionFor(xml, c("bean", "")); - + xml = "\r\n" + // "\r\n" + // " |"; XMLAssert.testCompletionFor(xml, c("bean", "")); - + xml = "\r\n" + // "\r\n" + // " |" + ""; XMLAssert.testCompletionFor(xml, c("bean", "")); - + xml = "\r\n" + // "\r\n" + // " |"; XMLAssert.testCompletionFor(xml, c("bean", "")); - + xml = "\r\n" + // "\r\n" + // " |"; XMLAssert.testCompletionFor(xml, c("constructor-arg", "")); - + xml = "\r\n" + // "\r\n" + // " \r\n | \r\n"; XMLAssert.testCompletionFor(xml, c("constructor-arg", "")); - + + } + + @Test + public void completionWithXMLSchemaContentChanged() throws Exception { + // This https://github.com/angelozerr/lsp4xml/issues/194 for the test scenario + Path dir = Paths.get("target/xsd/"); + if (!Files.isDirectory(dir)) { + Files.createDirectory(dir); + } + Files.deleteIfExists(Paths.get(dir.toString(), "resources.xsd")); + + XMLLanguageService xmlLanguageService = new XMLLanguageService(); + + String xml = "\r\n" + + "\r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + ""; + + // Schema defines variant attribute -> completion for @variant + String schema = "\r\n" + "\r\n" + + "\r\n" + " \r\n" + + " \r\n" + + " \r\n" + " \r\n" + + "\r\n" + " \r\n" + " \r\n" + + " \r\n" + + " \r\n" + + " \r\n" + + " \r\n" + "\r\n" + " \r\n" + + " \r\n" + " \r\n" + + " \r\n" + + " \r\n" + + " \r\n" + + " \r\n" + " \r\n" + ""; + Files.write(Paths.get("target/xsd/resources.xsd"), schema.getBytes()); + XMLAssert.testCompletionFor(xmlLanguageService, xml, null, "target/resources.xml", 1, false, + c("variant", "variant=\"\"")); + + // Update resources.xsd, Schema doesn't define variant attribute -> no completion + schema = "\r\n" + "\r\n" + + "\r\n" + " \r\n" + + " \r\n" + + " \r\n" + " \r\n" + + "\r\n" + " \r\n" + " \r\n" + + " \r\n" + + " \r\n" + + " \r\n" + + " \r\n" + "\r\n" + " \r\n" + + " \r\n" + " \r\n" + + " \r\n" + + " \r\n" + //+ " \r\n" + + " \r\n" + " \r\n" + ""; + Files.write(Paths.get("target/xsd/resources.xsd"), schema.getBytes()); + XMLAssert.testCompletionFor(xmlLanguageService, xml, null, "target/resources.xml", 0, false); + } private void testCompletionFor(String xml, CompletionItem... expectedItems) throws BadLocationException {