diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/contentmodel/participants/ContentModelCompletionParticipant.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/contentmodel/participants/ContentModelCompletionParticipant.java index 784f9a381..54923c052 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/contentmodel/participants/ContentModelCompletionParticipant.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/contentmodel/participants/ContentModelCompletionParticipant.java @@ -115,7 +115,7 @@ private void fillWithChildrenElementDeclaration(DOMElement element, Collection attributes, int level, i */ public static String generateAttributeValue(String defaultValue, Collection enumerationValues, boolean canSupportSnippets, int snippetIndex, boolean withQuote) { + return generateAttributeValue(defaultValue, enumerationValues, canSupportSnippets, snippetIndex, withQuote, null); + } + + /** + * Creates the string value for a CompletionItem TextEdit + * + * Can create an enumerated TextEdit if given a collection of values. + */ + public static String generateAttributeValue(String defaultValue, Collection enumerationValues, + boolean canSupportSnippets, int snippetIndex, boolean withQuote, SharedSettings settings) { StringBuilder value = new StringBuilder(); + String quotation = "\""; if (withQuote) { - value.append("=\""); + if(settings != null) { + quotation = settings.formattingSettings.getQuotationAsString(); + } + value.append("=" + quotation); } if (!canSupportSnippets) { if (defaultValue != null) { @@ -191,7 +206,7 @@ public static String generateAttributeValue(String defaultValue, Collection enumerationValues) { + String defaultValue, Collection enumerationValues, SharedSettings settings) { super.setLabel(attrName); super.setKind(CompletionItemKind.Unit); super.setFilterText(attrName); @@ -42,7 +43,7 @@ public AttributeCompletionItem(String attrName, boolean canSupportSnippets, Rang if (generateValue) { // Generate attribute value content String attributeValue = XMLGenerator.generateAttributeValue(defaultValue, enumerationValues, - canSupportSnippets, 1, true); + canSupportSnippets, 1, true, settings); attributeContent.append(attributeValue); } super.setTextEdit(new TextEdit(fullRange, attributeContent.toString())); diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLCompletions.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLCompletions.java index 106d8f531..4da249fc3 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLCompletions.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLCompletions.java @@ -107,7 +107,7 @@ public CompletionList doComplete(DOMDocument xmlDocument, Position position, case AttributeName: if (scanner.getTokenOffset() <= offset && offset <= scanner.getTokenEnd()) { collectAttributeNameSuggestions(scanner.getTokenOffset(), scanner.getTokenEnd(), completionRequest, - completionResponse); + completionResponse, settings); return completionResponse; } completionRequest.setCurrentAttributeName(scanner.getTokenText()); @@ -136,7 +136,7 @@ public CompletionList doComplete(DOMDocument xmlDocument, Position position, return completionResponse; case WithinTag: case AfterAttributeName: - collectAttributeNameSuggestions(scanner.getTokenEnd(), completionRequest, completionResponse); + collectAttributeNameSuggestions(scanner.getTokenEnd(), completionRequest, completionResponse, settings); return completionResponse; case BeforeAttributeValue: collectAttributeValueSuggestions(scanner.getTokenEnd(), offset, completionRequest, @@ -694,13 +694,13 @@ private void collectCharacterEntityProposals(ICompletionRequest request, IComple } private void collectAttributeNameSuggestions(int nameStart, CompletionRequest completionRequest, - CompletionResponse completionResponse) { + CompletionResponse completionResponse, SharedSettings settings) { collectAttributeNameSuggestions(nameStart, completionRequest.getOffset(), completionRequest, - completionResponse); + completionResponse, settings); } private void collectAttributeNameSuggestions(int nameStart, int nameEnd, CompletionRequest completionRequest, - CompletionResponse completionResponse) { + CompletionResponse completionResponse, SharedSettings settings) { int replaceEnd = completionRequest.getOffset(); String text = completionRequest.getXMLDocument().getText(); while (replaceEnd < nameEnd && text.charAt(replaceEnd) != '<') { // < is a valid attribute name character, but @@ -713,7 +713,7 @@ private void collectAttributeNameSuggestions(int nameStart, int nameEnd, Complet boolean generateValue = !isFollowedBy(text, nameEnd, ScannerState.AfterAttributeName, TokenType.DelimiterAssign); for (ICompletionParticipant participant : getCompletionParticipants()) { - participant.onAttributeName(generateValue, range, completionRequest, completionResponse); + participant.onAttributeName(generateValue, range, completionRequest, completionResponse, settings); } } catch (BadLocationException e) { LOGGER.log(Level.SEVERE, "While performing Completions, getReplaceRange() was given a bad Offset location", diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XSISchemaModel.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XSISchemaModel.java index 9ee7fc784..614920e4f 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XSISchemaModel.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XSISchemaModel.java @@ -16,18 +16,14 @@ import org.eclipse.lsp4j.CompletionItem; import org.eclipse.lsp4j.CompletionItemKind; import org.eclipse.lsp4j.Hover; -import org.eclipse.lsp4j.InsertTextFormat; import org.eclipse.lsp4j.MarkupContent; import org.eclipse.lsp4j.MarkupKind; -import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.Range; import org.eclipse.lsp4j.TextEdit; import org.eclipse.lsp4xml.commons.BadLocationException; import org.eclipse.lsp4xml.dom.DOMAttr; import org.eclipse.lsp4xml.dom.DOMDocument; import org.eclipse.lsp4xml.dom.DOMElement; -import org.eclipse.lsp4xml.dom.DOMNode; -import org.eclipse.lsp4xml.extensions.contentmodel.utils.XMLGenerator; import org.eclipse.lsp4xml.services.extensions.ICompletionRequest; import org.eclipse.lsp4xml.services.extensions.ICompletionResponse; import org.eclipse.lsp4xml.services.extensions.IHoverRequest; @@ -64,8 +60,10 @@ public class XSISchemaModel { " " + lineSeparator + " " + lineSeparator + "```" ; + public static final String XSI_WEBSITE = "http://www.w3.org/2001/XMLSchema-instance"; + public static final String XSI_DOC = "The namespace that defines important attributes such as `noNamespaceSchemaLocation` and `schemaLocation`."; public static void computeCompletionResponses(ICompletionRequest request, - ICompletionResponse response, Range editRange, DOMDocument document, boolean generateValue) throws BadLocationException { + ICompletionResponse response, Range editRange, DOMDocument document, boolean generateValue, SharedSettings settings) throws BadLocationException { DOMElement rootElement = document.getDocumentElement(); int offset = document.offsetAt(editRange.getStart()); @@ -74,9 +72,23 @@ public static void computeCompletionResponses(ICompletionRequest request, if(rootElement.equals(nodeAtOffset)) { inRootElement = true; } - + boolean isSnippetsSupported = request.getCompletionSettings().isCompletionSnippetsSupported(); + if(inRootElement) { + if(!hasAttribute(nodeAtOffset, "xmlns") && !response.hasAttribute("xmlns")) { // "xmlns" completion + createCompletionItem("xmlns", isSnippetsSupported, generateValue, editRange, null, null, null, response, settings); + } + if(document.hasSchemaInstancePrefix() == false) { // "xmlns:xsi" completion + createCompletionItem("xmlns:xsi", isSnippetsSupported, generateValue, editRange, XSI_WEBSITE, null, XSI_DOC, response, settings); + return;// All the following completion cases dont exist, so return. + } + } + String actualPrefix = document.getSchemaInstancePrefix(); + if(actualPrefix == null) { + return; + } + String name; String documentation; @@ -87,7 +99,7 @@ public static void computeCompletionResponses(ICompletionRequest request, documentation = NIL_DOC; name = actualPrefix + ":nil"; createCompletionItem(name, isSnippetsSupported, generateValue, editRange, StringUtils.TRUE, - StringUtils.TRUE_FALSE_ARRAY, documentation, response); + StringUtils.TRUE_FALSE_ARRAY, documentation, response, settings); } //Signals that an element should be accepted as ·valid· when it has no content despite //a content type which does not require or even necessarily allow empty content. @@ -96,26 +108,29 @@ public static void computeCompletionResponses(ICompletionRequest request, if(!hasAttribute(nodeAtOffset, actualPrefix, "type")) { documentation = TYPE_DOC; name = actualPrefix + ":type"; - createCompletionItem(name, isSnippetsSupported, generateValue, editRange, null, null, documentation, response); + createCompletionItem(name, isSnippetsSupported, generateValue, editRange, null, null, documentation, response, settings); } - //The xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes can be used in a document - //to provide hints as to the physical location of schema documents which may be used for ·assessment·. - if(inRootElement && !schemaLocationExists && !noNamespaceSchemaLocationExists) { - documentation = SCHEMA_LOCATION_DOC; - name = actualPrefix + ":schemaLocation"; - createCompletionItem(name, isSnippetsSupported, generateValue, editRange, null, null, documentation, response); - - documentation = NO_NAMESPACE_SCHEMA_LOCATION_DOC; - name = actualPrefix + ":noNamespaceSchemaLocation"; - createCompletionItem(name, isSnippetsSupported, generateValue, editRange, null, null, documentation, response); + + if(inRootElement) { + if(!schemaLocationExists && !noNamespaceSchemaLocationExists) { + //The xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes can be used in a document + //to provide hints as to the physical location of schema documents which may be used for ·assessment·. + documentation = SCHEMA_LOCATION_DOC; + name = actualPrefix + ":schemaLocation"; + createCompletionItem(name, isSnippetsSupported, generateValue, editRange, null, null, documentation, response, settings); + + documentation = NO_NAMESPACE_SCHEMA_LOCATION_DOC; + name = actualPrefix + ":noNamespaceSchemaLocation"; + createCompletionItem(name, isSnippetsSupported, generateValue, editRange, null, null, documentation, response, settings); + } } } private static void createCompletionItem(String attrName, boolean canSupportSnippet, boolean generateValue, Range editRange, String defaultValue, Collection enumerationValues, String documentation, - ICompletionResponse response) { + ICompletionResponse response, SharedSettings settings){ CompletionItem item = new AttributeCompletionItem(attrName, canSupportSnippet, editRange, generateValue, - defaultValue, enumerationValues); + defaultValue, enumerationValues, settings); MarkupContent markup = new MarkupContent(); markup.setKind(MarkupKind.MARKDOWN); markup.setValue(documentation); @@ -129,12 +144,21 @@ public static void computeValueCompletionResponses(ICompletionRequest request, int offset = document.offsetAt(editRange.getStart()); DOMElement nodeAtOffset = (DOMElement) document.findNodeAt(offset); + String actualPrefix = document.getSchemaInstancePrefix(); + DOMAttr attrAtOffset = nodeAtOffset.findAttrAt(offset); + String attrName = attrAtOffset.getName(); - // Value completion for 'nil' attribute - DOMAttr nilAttr = nodeAtOffset.getAttributeNode(actualPrefix, "nil"); - if(nilAttr != null) { - createCompletionItemsForValues(StringUtils.TRUE_FALSE_ARRAY, editRange, document, response, settings); + if(attrName != null) { + if(actualPrefix != null && attrName.equals(actualPrefix + ":nil")) { // Value completion for 'nil' attribute + createCompletionItemsForValues(StringUtils.TRUE_FALSE_ARRAY, editRange, document, response, settings); + } + else if(document.getDocumentElement().equals(nodeAtOffset)) { // if in the root element + if(attrName.equals("xmlns:xsi")) { + createSingleCompletionItemForValue(XSI_WEBSITE, editRange, document, response, settings); + } + } + } } @@ -178,6 +202,10 @@ private static boolean hasAttribute(DOMElement root, String prefix, String suffi } + private static boolean hasAttribute(DOMElement root, String name) { + return hasAttribute(root, null, name); + } + public static Hover computeHoverResponse(DOMAttr attribute, IHoverRequest request) { String name = attribute.getName(); diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/extensions/CompletionParticipantAdapter.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/extensions/CompletionParticipantAdapter.java index 59b606943..12a2028de 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/extensions/CompletionParticipantAdapter.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/extensions/CompletionParticipantAdapter.java @@ -32,7 +32,7 @@ public void onXMLContent(ICompletionRequest request, ICompletionResponse respons @Override public void onAttributeName(boolean generateValue, Range fullRange, ICompletionRequest request, - ICompletionResponse response) throws Exception { + ICompletionResponse response, SharedSettings settings) throws Exception { // Do nothing } diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/extensions/ICompletionParticipant.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/extensions/ICompletionParticipant.java index 03efdea6f..0e9f33f1f 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/extensions/ICompletionParticipant.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/extensions/ICompletionParticipant.java @@ -24,8 +24,8 @@ public interface ICompletionParticipant { void onXMLContent(ICompletionRequest request, ICompletionResponse response) throws Exception; - void onAttributeName(boolean generateValue, Range fullRange, ICompletionRequest request, ICompletionResponse response) - throws Exception; + void onAttributeName(boolean generateValue, Range fullRange, ICompletionRequest request, ICompletionResponse response, + SharedSettings settings) throws Exception; void onAttributeValue(String valuePrefix, Range fullRange, boolean addQuotes, ICompletionRequest request, ICompletionResponse response, SharedSettings settings) throws Exception; diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/settings/XMLFormattingOptions.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/settings/XMLFormattingOptions.java index d675ad0d3..2b0487ba0 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/settings/XMLFormattingOptions.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/settings/XMLFormattingOptions.java @@ -203,7 +203,9 @@ public String getQuotations() { /** * Returns the actual quotation value as a String. * - * Either a {@code '} or {@code "} + * Either a {@code '} or {@code "}. + * + * Defaults to {@code "}. */ public String getQuotationAsString() { return XMLFormattingOptions.DOUBLE_QUOTES_VALUE.equals(getQuotations()) ? "\"" : "\'"; diff --git a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/XMLAssert.java b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/XMLAssert.java index 88aedfca2..dc18540f8 100644 --- a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/XMLAssert.java +++ b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/XMLAssert.java @@ -119,10 +119,17 @@ public static void testCompletionFor(XMLLanguageService xmlLanguageService, Stri public static void testCompletionFor(XMLLanguageService xmlLanguageService, String value, String catalogPath, Consumer customConfiguration, String fileURI, Integer expectedCount, CompletionSettings completionSettings, CompletionItem... expectedItems) throws BadLocationException { + testCompletionFor(xmlLanguageService, value, catalogPath, customConfiguration, fileURI, expectedCount, completionSettings, new XMLFormattingOptions(4, true), expectedItems); + } + + public static void testCompletionFor(XMLLanguageService xmlLanguageService, String value, String catalogPath, + Consumer customConfiguration, String fileURI, Integer expectedCount, + CompletionSettings completionSettings, XMLFormattingOptions formattingSettings, CompletionItem... expectedItems) + throws BadLocationException { int offset = value.indexOf('|'); value = value.substring(0, offset) + value.substring(offset + 1); - TextDocument document = new TextDocument(value, fileURI != null ? fileURI : "test://test/test.html"); + TextDocument document = new TextDocument(value, fileURI != null ? fileURI : "test://test/test.xml"); Position position = document.positionAt(offset); DOMDocument htmlDoc = DOMParser.getInstance().parse(document, xmlLanguageService.getResolverExtensionManager()); xmlLanguageService.setDocumentProvider((uri) -> htmlDoc); @@ -141,7 +148,7 @@ public static void testCompletionFor(XMLLanguageService xmlLanguageService, Stri } SharedSettings sharedSettings = new SharedSettings(); - sharedSettings.setFormattingSettings(new XMLFormattingOptions(4, false)); + sharedSettings.setFormattingSettings(formattingSettings); sharedSettings.setCompletionSettings(completionSettings); CompletionList list = xmlLanguageService.doComplete(htmlDoc, position, sharedSettings); 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 7c9d63434..d7e133986 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 @@ -345,12 +345,13 @@ public void completionWithXMLSchemaContentChanged() throws Exception { + " \r\n" + " \r\n" + " \r\n" + ""; Files.write(Paths.get("target/xsd/resources.xsd"), schema.getBytes()); - XMLAssert.testCompletionFor(xmlLanguageService, xml, null, null, "target/resources.xml", 3, false, + XMLAssert.testCompletionFor(xmlLanguageService, xml, null, null, "target/resources.xml", 4, false, c("variant", "variant=\"\"")); // Update resources.xsd, Schema doesn't define variant attribute -> no // completion - schema = "\r\n" + "\r\n" + schema = "\r\n" + + "\r\n" + "\r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" @@ -365,7 +366,7 @@ public void completionWithXMLSchemaContentChanged() throws Exception { // + " \r\n" + " \r\n" + " \r\n" + ""; Files.write(Paths.get("target/xsd/resources.xsd"), schema.getBytes()); - XMLAssert.testCompletionFor(xmlLanguageService, xml, null, null, "target/resources.xml", 2, false); + XMLAssert.testCompletionFor(xmlLanguageService, xml, null, null, "target/resources.xml", 3, false); } @@ -451,7 +452,7 @@ public void xsiCompletionNotUsingXSIName() throws BadLocationException { } @Test - public void xsiCompletionDoesntAppearSinceDoesntExist() throws BadLocationException { + public void xmlnsXSICompletion() throws BadLocationException { String xml = "\r\n" + ""; - XMLAssert.testCompletionFor(xml, 0); + XMLAssert.testCompletionFor(xml, 1, c("xmlns:xsi", "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"")); + } + + @Test + public void xmlnsXSIValueCompletion() throws BadLocationException { + String xml = + "\r\n" + + " \r\n" + + ""; + + XMLAssert.testCompletionFor(xml, 1, c("http://www.w3.org/2001/XMLSchema-instance", "\"http://www.w3.org/2001/XMLSchema-instance\"")); } @Test diff --git a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/extensions/xsi/XSICompletionExtensionsTest.java b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/extensions/xsi/XSICompletionExtensionsTest.java index 04f752e1d..c4fcc7220 100644 --- a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/extensions/xsi/XSICompletionExtensionsTest.java +++ b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/extensions/xsi/XSICompletionExtensionsTest.java @@ -16,6 +16,10 @@ import org.eclipse.lsp4j.CompletionItem; import org.eclipse.lsp4xml.XMLAssert; import org.eclipse.lsp4xml.commons.BadLocationException; +import org.eclipse.lsp4xml.services.XMLLanguageService; +import org.eclipse.lsp4xml.services.extensions.CompletionSettings; +import org.eclipse.lsp4xml.settings.XMLFormattingOptions; +import org.junit.BeforeClass; import org.junit.Test; /** @@ -23,6 +27,16 @@ * */ public class XSICompletionExtensionsTest { + + public static XMLFormattingOptions formattingSettingsSingleQuotes = new XMLFormattingOptions(true); + + @BeforeClass + public static void runOnceBeforeClass() { + formattingSettingsSingleQuotes.setQuotations(XMLFormattingOptions.SINGLE_QUOTES_VALUE); + } + + + @Test public void completion() throws BadLocationException { @@ -30,8 +44,8 @@ public void completion() throws BadLocationException { String xml = "\r\n" + // ""; testCompletionFor(xml, - c("true", te(1, 71, 1, 71, "\"true\""), "\"true\""), // <-- coming from substition group of xsl:declaration - c("false", te(1, 71, 1, 71, "\"false\""), "\"false\"")); // coming from stylesheet children + c("true", te(1, 71, 1, 71, "\"true\""), "\"true\""), + c("false", te(1, 71, 1, 71, "\"false\""), "\"false\"")); } @Test @@ -40,8 +54,8 @@ public void completion2() throws BadLocationException { String xml = "\r\n" + // ""; testCompletionFor(xml, - c("true", te(1, 71, 1, 73, "\"true\""), "\"true\""), // <-- coming from substition group of xsl:declaration - c("false", te(1, 71, 1, 73, "\"false\""), "\"false\"")); // coming from stylesheet children + c("true", te(1, 71, 1, 73, "\"true\""), "\"true\""), + c("false", te(1, 71, 1, 73, "\"false\""), "\"false\"")); } @Test @@ -51,11 +65,95 @@ public void completion3() throws BadLocationException { "\r\n" + " "; testCompletionFor(xml, - c("true", te(2, 13, 2, 13, "\"true\""), "\"true\""), // <-- coming from substition group of xsl:declaration - c("false", te(2, 13, 2, 13, "\"false\""), "\"false\"")); // coming from stylesheet children + c("true", te(2, 13, 2, 13, "\"true\""), "\"true\""), + c("false", te(2, 13, 2, 13, "\"false\""), "\"false\"")); + } + + @Test + public void completion3NNamespace() throws BadLocationException { + // completion on | + String xml = "\r\n" + // + "\r\n" + + " "; + testCompletionFor(xml); + } + + @Test + public void completion4() throws BadLocationException { + // completion on | + String xml = "\r\n" + // + "\r\n" + + " "; + + testCompletionFor(xml, formattingSettingsSingleQuotes, + c("true", te(2, 13, 2, 13, "\'true\'"), "\'true\'"), + c("false", te(2, 13, 2, 13, "\'false\'"), "\'false\'")); + } + + @Test + public void completionXMLNSXSIValue() throws BadLocationException { + // completion on | + String xml = "\r\n" + // + "\r\n" + + " \r\n"+ + ""; + testCompletionFor(xml, + c("http://www.w3.org/2001/XMLSchema-instance", te(1, 19, 1, 19, "\"http://www.w3.org/2001/XMLSchema-instance\""), "\"http://www.w3.org/2001/XMLSchema-instance\"") + ); // coming from stylesheet children + } + + @Test + public void completionXMLNSXSIValueSingleQuotes() throws BadLocationException { + // completion on | + String xml = "\r\n" + // + "\r\n" + + " \r\n"+ + ""; + testCompletionFor(xml, formattingSettingsSingleQuotes, + c("http://www.w3.org/2001/XMLSchema-instance", te(1, 19, 1, 19, "\'http://www.w3.org/2001/XMLSchema-instance\'"), "\'http://www.w3.org/2001/XMLSchema-instance\'") + ); // coming from stylesheet children + } + + @Test + public void completionXMLNSXSIWhole() throws BadLocationException { + // completion on | + String xml = "\r\n" + // + "\r\n" + + " \r\n"+ + ""; + testCompletionFor(xml, + c("xmlns:xsi", te(1, 9, 1, 16, "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""), "xmlns:xsi") + ); // coming from stylesheet children + } + + @Test + public void completionXMLNS() throws BadLocationException { + // completion on | + String xml = "\r\n" + // + "\r\n" + + " \r\n"+ + ""; + testCompletionFor(xml, + c("xmlns", te(1, 9, 1, 10, "xmlns=\"\""), "xmlns") + ); // coming from stylesheet children + } + + @Test + public void completionXMLNSOnlyInRoot() throws BadLocationException { + // completion on | + String xml = "\r\n" + // + "\r\n" + + " \r\n"+ + ""; + testCompletionFor(xml + ); // coming from stylesheet children } private void testCompletionFor(String xml, CompletionItem... expectedItems) throws BadLocationException { XMLAssert.testCompletionFor(xml, null, expectedItems); } + + private void testCompletionFor(String xml, XMLFormattingOptions formattingSettings, CompletionItem... expectedItems) throws BadLocationException { + XMLAssert.testCompletionFor(new XMLLanguageService(), xml, null, null, null, null, new CompletionSettings(true), formattingSettings, expectedItems); + } } diff --git a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/services/extensions/HTMLCompletionExtensionsTest.java b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/services/extensions/HTMLCompletionExtensionsTest.java index b487f3fb2..a8ded0a3b 100644 --- a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/services/extensions/HTMLCompletionExtensionsTest.java +++ b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/services/extensions/HTMLCompletionExtensionsTest.java @@ -152,7 +152,7 @@ public void onTagOpen(ICompletionRequest completionRequest, ICompletionResponse @Override public void onAttributeName(boolean generateValue, Range replaceRange, ICompletionRequest completionRequest, - ICompletionResponse completionResponse) { + ICompletionResponse completionResponse, SharedSettings settings) { String tag = completionRequest.getCurrentTag(); HTMLTag htmlTag = HTMLTag.getHTMLTag(tag); if (htmlTag != null) {