From 74f7553bd3616408778aa9ea0ac30b80ce968b22 Mon Sep 17 00:00:00 2001 From: enxio Date: Thu, 19 Sep 2019 16:02:47 +0200 Subject: [PATCH 01/39] DJ/cwr --- README.md | 138 +----------------- .../lsp4xml/services/XMLFormatter.java | 83 ++++++++++- .../eclipse/lsp4xml/utils/StringUtils.java | 33 +++++ .../org/eclipse/lsp4xml/utils/XMLBuilder.java | 19 ++- 4 files changed, 122 insertions(+), 151 deletions(-) diff --git a/README.md b/README.md index f55bfd96a..9839eb208 100644 --- a/README.md +++ b/README.md @@ -1,137 +1 @@ -XML Language Server (lsp4xml) -=========================== - -[![Build Status](https://travis-ci.org/angelozerr/lsp4xml.svg?branch=master)](http://travis-ci.org/angelozerr/lsp4xml) - -The **lsp4xml** is a XML language specific implementation of the [Language Server Protocol](https://github.com/Microsoft/language-server-protocol) -and can be used with any editor that supports the protocol, to offer good support for the **XML Language**. The server is based on: - - * [Eclipse LSP4J](https://github.com/eclipse/lsp4j), the Java binding for the Language Server Protocol. - * Xerces to manage XML Schema validation, completion and hover - -Features --------------- - -* [textDocument/codeAction](https://microsoft.github.io/language-server-protocol/specification#textDocument_codeAction). -* [textDocument/completion](https://microsoft.github.io/language-server-protocol/specification#textDocument_completion). -* [textDocument/documentHighlight](https://microsoft.github.io/language-server-protocol/specification#textDocument_documentHighlight). -* [textDocument/documentLink](https://microsoft.github.io/language-server-protocol/specification#textDocument_documentLink). -* [textDocument/documentSymbol](https://microsoft.github.io/language-server-protocol/specification#textDocument_documentSymbol). -* [textDocument/foldingRanges](https://microsoft.github.io/language-server-protocol/specification#textDocument_foldingRange). -* [textDocument/formatting](https://microsoft.github.io/language-server-protocol/specification#textDocument_formatting). -* [textDocument/hover](https://microsoft.github.io/language-server-protocol/specification#textDocument_hover). -* [textDocument/rangeFormatting](https://microsoft.github.io/language-server-protocol/specification#textDocument_rangeFormatting) -* [textDocument/rename](https://microsoft.github.io/language-server-protocol/specification#textDocument_rename). - -See screenshots in the [wiki](https://github.com/angelozerr/lsp4xml/wiki/Features). - -See the [changelog](CHANGELOG.md) for the latest release. - -Extension --------------- - -The XML Language Server is extensible with plugin kind (with SPI). Here existings extensions: - - * content model to provide completion, validation, hover based on XML Schema. - * emmet to provide completion based on Emmet. - -Demo --------------- - -![XML Language Server Demo](demos/XMLLanguageServerDemo.gif) - -Get started --------------- -* Clone this repository -* Open the folder in your terminal / command line -* Run `./mvnw clean verify` (OSX, Linux) or `mvnw.cmd clean verify` (Windows) -* After successful compilation you can find the resulting `org.eclipse.lsp4xml-uber.jar` in the folder `org.eclipse.lsp4xml/target` - -Developer --------------- - -To debug the XML LS you can use XMLServerSocketLauncher: - -1. Run the XMLServerSocketLauncher in debug mode (e.g. in eclipse) -2. Connect your client via socket port. Default port is 5008, but you can change it with start argument `--port` in step 1 - -Client connection example using Theia and TypeScript: - -```js -let socketPort = '5008' -console.log(`Connecting via port ${socketPort}`) -const socket = new net.Socket() -const serverConnection = createSocketConnection(socket, - socket, () => { - socket.destroy() - }); -this.forward(clientConnection, serverConnection) -socket.connect(socketPort) -``` - -Maven coordinates: ------------------- - -Here are the Maven coordinates for lsp4xml (replace the `X.Y.Z` version with the [latest release](https://bintray.com/beta/#/lsp4xml/releases/lsp4xml)): -```xml - - org.lsp4xml - org.eclipse.lsp4xml - X.Y.Z - - uber - -``` - -for Gradle: -``` -compile(group: 'org.lsp4xml', name: 'org.eclipse.lsp4xml', version: 'X.Y.Z', classifier: 'uber') -``` - -You will have to reference the Maven repository hosting the dependency you need. E.g. for Maven, add this repository to your pom.xml or settings.xml : -```xml - - lsp4xml-releases - https://dl.bintray.com/lsp4xml/releases - - false - - - true - - -``` -or P2 repository: [https://dl.bintray.com/lsp4xml/p2/``](https://dl.bintray.com/lsp4xml/p2/) - - -And if you want to consume the SNAPSHOT builds instead: -```xml - - lsp4xml-snapshots - https://oss.jfrog.org/artifactory/libs-snapshot - - false - - - true - - -``` -or P2 repository: -[https://lsp4xml.jfrog.io/lsp4xml/generic-local/p2/lsp4xml/``](https://lsp4xml.jfrog.io/lsp4xml/generic-local/p2/lsp4xml/) - -Clients -------- - -Here are some clients consuming this XML Language Server: - - * Eclipse IDE with [Wild Web Developer](https://github.com/eclipse/wildwebdeveloper) - * VSCode with [vscode-xml](https://github.com/redhat-developer/vscode-xml) - * Theia with [theia-xml](https://github.com/theia-ide/theia-xml-extension) - * [Spring Tools 4](https://github.com/spring-projects/sts4) - re-using the XML parser for Spring-specific analysis and content-assist - * Vim/Neovim with [coc-xml](https://github.com/fannheyward/coc-xml) - - --- - - ![Gracefully powered by Artifactory](images/Powered-by-artifactory_01.png) - +experimental diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java index cd7c329d0..3be43c8e5 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java @@ -137,6 +137,30 @@ private boolean containsTextWithinStartTag() { } return ((DOMElement) fullNode).isInStartTag(fullDocOffset); } +// ATSEC + private boolean putTagInline(String tag) { + return (tag.equals("b")|| + tag.equals("bibref")|| + tag.equals("color")|| + tag.equals("em")|| + tag.equals("figure")|| + tag.equals("i")|| + tag.equals("it")|| + tag.equals("link")|| + tag.equals("mark")|| + tag.equals("note")|| + tag.equals("s")|| + tag.equals("sub")|| + tag.equals("sup")|| + tag.equals("tt")|| + tag.equals("u")|| + tag.equals("xref")|| + tag.equals("show-number")|| + tag.equals("show-page")|| + tag.equals("show-id")|| + tag.equals("show-label")|| + tag.equals("show-title")); + } private void adjustOffsetToStartTag() throws BadLocationException { int tagContentOffset = this.rangeDomDocument.getChild(0).getStart(); @@ -261,23 +285,59 @@ private void format(DOMNode node) throws BadLocationException { if (node.getOwnerDocument().isDTD()) { doLineFeed = false; } else { - doLineFeed = !(node.isComment() && ((DOMComment) node).isCommentSameLineEndTag()) - && (!node.isText() || (!((DOMText) node).isWhitespace() && ((DOMText) node).hasSiblings())); +// ATSEC + doLineFeed = + !(node.isComment() && + ((DOMComment) node).isCommentSameLineEndTag()) + && ( + !node.isText() || + ( + !((DOMText) node).isWhitespace() && + ((DOMText) node).hasSiblings() + ) + ); + } + if (node.isElement()) { + DOMElement element = (DOMElement) node; + String tag = element.getTagName(); + if (putTagInline(tag)) { + doLineFeed = false; + //this.xmlBuilder.addContent("[trace-4]"); + if (!node.isText()) { + //this.xmlBuilder.appendSpace(); + } + } } if (this.indentLevel > 0 && doLineFeed) { // add new line + indent if (!node.isChildOfOwnerDocument() || node.getPreviousNonTextSibling() != null) { - this.xmlBuilder.linefeed(); + if (node.isElement()) { + DOMElement element = (DOMElement) node; + String tag = element.getTagName(); + if (!putTagInline(tag)) { + //this.xmlBuilder.addContent("[trace-1]"); + this.xmlBuilder.linefeed(); + } + } else { + if (!node.isText()) { + //this.xmlBuilder.addContent("[trace-2]"); + this.xmlBuilder.linefeed(); + } + } } if (!startTagExistsInRangeDocument(node) && startTagExistsInFullDocument(node)) { DOMNode startNode = getFullDocElemFromRangeElem((DOMElement) node); int currentIndentLevel = getNodeIndentLevel(startNode); + //this.xmlBuilder.addContent("[trace-5]"); this.xmlBuilder.indent(currentIndentLevel); this.indentLevel = currentIndentLevel; } else { - this.xmlBuilder.indent(this.indentLevel); + if (!node.isText()) { + //this.xmlBuilder.addContent("[trace-3]"); + this.xmlBuilder.indent(this.indentLevel); + } } } // generate start element @@ -323,19 +383,25 @@ private void format(DOMNode node) throws BadLocationException { } if (element.hasEndTag()) { if (hasElements) { - this.xmlBuilder.linefeed(); - this.xmlBuilder.indent(this.indentLevel); + //this.xmlBuilder.addContent("[trace-8]"); + if (!putTagInline(tag)) { + this.xmlBuilder.linefeed(); + this.xmlBuilder.indent(this.indentLevel); + } } // end tag element is done, only if the element is closed // the format, doesn't fix the close tag if (element.hasEndTag() && element.getEndTagOpenOffset() <= this.endOffset) { + //this.xmlBuilder.addContent("[trace-6b]"); this.xmlBuilder.endElement(tag, element.isEndTagClosed()); } else { + //this.xmlBuilder.addContent("[trace-6a]"); this.xmlBuilder.selfCloseElement(); } + //this.xmlBuilder.appendSpace(); } else if (element.isSelfClosed()) { this.xmlBuilder.selfCloseElement(); - + //this.xmlBuilder.addContent("[trace-7]"); } } return; @@ -366,7 +432,8 @@ private void format(DOMNode node) throws BadLocationException { // Generate content String content = textNode.getData(); - xmlBuilder.addContent(content, textNode.isWhitespace(), textNode.hasSiblings(), + //this.xmlBuilder.addContent(content); + this.xmlBuilder.addContent(content, textNode.isWhitespace(), textNode.hasSiblings(), textNode.getDelimiter(), this.indentLevel); return; } else if (node.isDoctype()) { diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java index c6ec3ea40..b1f4ed8aa 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java @@ -37,6 +37,10 @@ public static boolean isQuote(char c) { return c == '\'' || c == '"'; } + public static boolean isTabOrSpace(char c) { + return c == '\t' || c == ' '; + } + public static boolean isWhitespace(String value) { if (value == null) { return false; @@ -54,6 +58,7 @@ public static boolean isWhitespace(String value) { return true; } + /** * Normalizes the whitespace characters of a given string and applies it to the * given string builder. @@ -76,6 +81,26 @@ public static void normalizeSpace(String str, StringBuilder b) { space = ""; b.append(c); } + } + +// ATSEC + public static void normalizeSpace2(String str, StringBuilder b) { + String space = ""; + char c; + int i = 0, len = str.length(); + + while (i < len) { + c = str.charAt(i); + if (c != '\n') { + if (isTabOrSpace(c)) { + for (int j = i + 1; j < len && isTabOrSpace(str.charAt(j)); ++j) { + i = j; + } + } + b.append(c); + } + i++; + } } /** @@ -90,6 +115,14 @@ public static String normalizeSpace(String str) { return b.toString(); } +// ATSEC + public static String normalizeSpace2(String str) { + StringBuilder b = new StringBuilder(str.length()); + normalizeSpace2(str, b); + return b.toString(); + } + + /** * Returns the start whitespaces of the given line text. * diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/XMLBuilder.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/XMLBuilder.java index c13542820..ba4045399 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/XMLBuilder.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/XMLBuilder.java @@ -11,6 +11,7 @@ package org.eclipse.lsp4xml.utils; import static org.eclipse.lsp4xml.utils.StringUtils.normalizeSpace; +import static org.eclipse.lsp4xml.utils.StringUtils.normalizeSpace2; import org.eclipse.lsp4xml.dom.DOMAttr; import org.eclipse.lsp4xml.dom.DOMComment; @@ -226,11 +227,16 @@ public XMLBuilder addContent(String text) { public XMLBuilder addContent(String text, Boolean isWhitespaceContent, Boolean hasSiblings, String delimiter, int level) { if(!isWhitespaceContent) { if(isJoinContentLines()) { - text = StringUtils.normalizeSpace(text); - } - else if(hasSiblings) { +// ATSEC +// xml.append("A:"); + text = StringUtils.normalizeSpace2(text); + } else if(hasSiblings) { +// xml.append("B:"); text = text.trim(); - } +// } else { +// xml.append("C:"); + } +// xml.append("["+text+"]"); xml.append(text); } else if (!hasSiblings && isPreserveEmptyContent()) { @@ -253,7 +259,8 @@ public XMLBuilder indent(int level) { for (int i = 0; i < level; i++) { if (isInsertSpaces()) { for (int j = 0; j < getTabSize(); j++) { - xml.append(" "); + xml.append(" "); +// xml.append("x"); } } else { xml.append("\t"); @@ -314,7 +321,7 @@ public XMLBuilder startComment(DOMComment comment) { public XMLBuilder addContentComment(String content) { if (isJoinCommentLines()) { xml.append(" "); - xml.append(normalizeSpace(content)); + xml.append(normalizeSpace2(content)); xml.append(" "); } else { xml.append(content); From 17394379a417e3b8df5254d6047f31ff42eec69b Mon Sep 17 00:00:00 2001 From: enxio Date: Fri, 20 Sep 2019 13:34:52 +0200 Subject: [PATCH 02/39] formatting --- .gitignore | 1 + .../eclipse/lsp4xml/utils/StringUtils.java | 36 +++++++++---------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 44f3782d5..4013b58a2 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ target/ .Trash* **/adhoctest/ +lsp4xml.code-workspace diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java index b1f4ed8aa..d86e98807 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java @@ -58,7 +58,6 @@ public static boolean isWhitespace(String value) { return true; } - /** * Normalizes the whitespace characters of a given string and applies it to the * given string builder. @@ -81,26 +80,25 @@ public static void normalizeSpace(String str, StringBuilder b) { space = ""; b.append(c); } - } + } // ATSEC - public static void normalizeSpace2(String str, StringBuilder b) { - String space = ""; - char c; - int i = 0, len = str.length(); - - while (i < len) { - c = str.charAt(i); - if (c != '\n') { - if (isTabOrSpace(c)) { - for (int j = i + 1; j < len && isTabOrSpace(str.charAt(j)); ++j) { - i = j; - } - } - b.append(c); - } - i++; - } + public static void normalizeSpace2(String str, StringBuilder b) { + char c; + int i = 0, len = str.length(); + + while (i < len) { + c = str.charAt(i); + if (c != '\n') { + if (isTabOrSpace(c)) { + for (int j = i + 1; j < len && isTabOrSpace(str.charAt(j)); ++j) { + i = j; + } + } + b.append(c); + } + i++; + } } /** From df9962f1f49f0a79f3f736b10064f789d4705434 Mon Sep 17 00:00:00 2001 From: enxio Date: Fri, 20 Sep 2019 13:39:12 +0200 Subject: [PATCH 03/39] ignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 4013b58a2..89b3e62b1 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,4 @@ target/ **/adhoctest/ lsp4xml.code-workspace +.vscode/** From 55c13c13f9cca7c8ad1c312d9847eaa16a5dd1ed Mon Sep 17 00:00:00 2001 From: enxio Date: Thu, 26 Sep 2019 13:34:22 +0200 Subject: [PATCH 04/39] Fix preservation of single WS --- .../org/eclipse/lsp4xml/utils/XMLBuilder.java | 57 ++++++++++--------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/XMLBuilder.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/XMLBuilder.java index ba4045399..eb63dd7f8 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/XMLBuilder.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/XMLBuilder.java @@ -225,34 +225,37 @@ public XMLBuilder addContent(String text) { } public XMLBuilder addContent(String text, Boolean isWhitespaceContent, Boolean hasSiblings, String delimiter, int level) { - if(!isWhitespaceContent) { - if(isJoinContentLines()) { -// ATSEC -// xml.append("A:"); - text = StringUtils.normalizeSpace2(text); - } else if(hasSiblings) { -// xml.append("B:"); - text = text.trim(); -// } else { -// xml.append("C:"); - } -// xml.append("["+text+"]"); - xml.append(text); - } - else if (!hasSiblings && isPreserveEmptyContent()) { - xml.append(text); - } - else if(hasSiblings) { - int preservedNewLines = getPreservedNewlines(); - if(preservedNewLines > 0) { - int newLineCount = StringUtils.getNumberOfNewLines(text, isWhitespaceContent, delimiter, preservedNewLines); - for (int i = 0; i < newLineCount - 1; i++) { // - 1 because the node after will insert a delimiter - xml.append(delimiter); - } - } + if (isWhitespaceContent) { + // whoah: terriable, but this one seems to preserve single space. + if (text.length() == 1) { + xml.append(text); + } + } else if (!isWhitespaceContent) { + if(isJoinContentLines()) { + // ATSEC + // xml.append("A:"); + text = StringUtils.normalizeSpace2(text); + } else if(hasSiblings) { + // xml.append("B:"); + text = text.trim(); + // } else { + // xml.append("C:"); + } + // xml.append("["+text+"]"); + xml.append(text); + } else if (!hasSiblings && isPreserveEmptyContent()) { + xml.append(text); + } else if(hasSiblings) { + int preservedNewLines = getPreservedNewlines(); + if(preservedNewLines > 0) { + int newLineCount = StringUtils.getNumberOfNewLines(text, isWhitespaceContent, delimiter, preservedNewLines); + for (int i = 0; i < newLineCount - 1; i++) { // - 1 because the node after will insert a delimiter + xml.append(delimiter); + } + } - } - return this; + } + return this; } public XMLBuilder indent(int level) { From 5a3094d660b3983b70e4445873e8a3f145ca6f96 Mon Sep 17 00:00:00 2001 From: enxio Date: Thu, 26 Sep 2019 13:48:35 +0200 Subject: [PATCH 05/39] Make editing with emacs possible. Why are these files DOS?!?! --- .../java/org/eclipse/lsp4xml/services/XMLFormatter.java | 6 ++++++ .../main/java/org/eclipse/lsp4xml/utils/XMLBuilder.java | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java index 3be43c8e5..608cc3e3c 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java @@ -644,3 +644,9 @@ public List format(TextDocument textDocument, Range range, return null; } } + +// Local Variables: +// tab-width: 8 +// indent-tabs-mode: t +// c-basic-offset: 8 +// End: diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/XMLBuilder.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/XMLBuilder.java index eb63dd7f8..2387d9b7f 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/XMLBuilder.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/XMLBuilder.java @@ -23,7 +23,7 @@ * */ public class XMLBuilder { - + private final XMLFormattingOptions formattingOptions; private final String lineDelimiter; private final StringBuilder xml; @@ -409,3 +409,9 @@ private int getPreservedNewlines() { } } + +// Local Variables: +// tab-width: 8 +// indent-tabs-mode: t +// c-basic-offset: 8 +// End: From 12065435480e2ec1e674a5aefc87f65c456b3254 Mon Sep 17 00:00:00 2001 From: enxio Date: Thu, 26 Sep 2019 14:45:00 +0200 Subject: [PATCH 06/39] possibly not break things. --- .../org/eclipse/lsp4xml/utils/XMLBuilder.java | 54 ++++++++++--------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/XMLBuilder.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/XMLBuilder.java index 2387d9b7f..1f93c292c 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/XMLBuilder.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/XMLBuilder.java @@ -226,34 +226,36 @@ public XMLBuilder addContent(String text) { public XMLBuilder addContent(String text, Boolean isWhitespaceContent, Boolean hasSiblings, String delimiter, int level) { if (isWhitespaceContent) { - // whoah: terriable, but this one seems to preserve single space. - if (text.length() == 1) { - xml.append(text); - } - } else if (!isWhitespaceContent) { - if(isJoinContentLines()) { - // ATSEC - // xml.append("A:"); - text = StringUtils.normalizeSpace2(text); - } else if(hasSiblings) { - // xml.append("B:"); - text = text.trim(); - // } else { - // xml.append("C:"); - } - // xml.append("["+text+"]"); - xml.append(text); + // whoah: terriable, but this one seems to preserve single space. + if (text.length() == 1) { + xml.append(text); + } + } + // "compatible" if() follow, changes are based on basically no understanding what's really going on here. + if (!isWhitespaceContent) { + if(isJoinContentLines()) { + // ATSEC + // xml.append("A:"); + text = StringUtils.normalizeSpace2(text); + } else if(hasSiblings) { + // xml.append("B:"); + text = text.trim(); + // } else { + // xml.append("C:"); + } + // xml.append("["+text+"]"); + xml.append(text); } else if (!hasSiblings && isPreserveEmptyContent()) { - xml.append(text); + xml.append(text); } else if(hasSiblings) { - int preservedNewLines = getPreservedNewlines(); - if(preservedNewLines > 0) { - int newLineCount = StringUtils.getNumberOfNewLines(text, isWhitespaceContent, delimiter, preservedNewLines); - for (int i = 0; i < newLineCount - 1; i++) { // - 1 because the node after will insert a delimiter - xml.append(delimiter); - } - } - + int preservedNewLines = getPreservedNewlines(); + if(preservedNewLines > 0) { + int newLineCount = StringUtils.getNumberOfNewLines(text, isWhitespaceContent, delimiter, preservedNewLines); + for (int i = 0; i < newLineCount - 1; i++) { // - 1 because the node after will insert a delimiter + xml.append(delimiter); + } + } + } return this; } From 0d8d8cb9de3c07c7d2a7f80b04d8b25d717992f5 Mon Sep 17 00:00:00 2001 From: enxio Date: Mon, 30 Sep 2019 12:21:18 +0200 Subject: [PATCH 07/39] add one more tag to put in line. --- .../java/org/eclipse/lsp4xml/services/XMLFormatter.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java index 608cc3e3c..198397d09 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java @@ -112,7 +112,7 @@ private void setupRangeFormatting(Range range) throws BadLocationException { adjustOffsetToStartTag(); rangeText = fullText.substring(this.startOffset, this.endOffset); this.rangeDomDocument = DOMParser.getInstance().parse(rangeText, this.textDocument.getUri(), null, false); - } + } this.xmlBuilder = new XMLBuilder(this.options, "", textDocument.lineDelimiter(startPosition.getLine())); } @@ -159,7 +159,8 @@ private boolean putTagInline(String tag) { tag.equals("show-page")|| tag.equals("show-id")|| tag.equals("show-label")|| - tag.equals("show-title")); + tag.equals("show-title")|| + tag.equals("footnote")); } private void adjustOffsetToStartTag() throws BadLocationException { @@ -241,7 +242,7 @@ private DOMElement getFullDocElemFromRangeElem(DOMElement elemFromRangeDoc) { int fullOffset = -1; if (elemFromRangeDoc.hasStartTag()) { - fullOffset = getFullOffsetFromRangeOffset(elemFromRangeDoc.getStartTagOpenOffset()) + 1; + fullOffset = getFullOffsetFromRangeOffset(elemFromRangeDoc.getStartTagOpenOffset()) + 1; // +1 because offset must be here: <|root // for DOMNode.findNodeAt() to find the correct element } else if (elemFromRangeDoc.hasEndTag()) { @@ -370,7 +371,7 @@ private void format(DOMNode node) throws BadLocationException { boolean hasElements = false; if (node.hasChildNodes()) { // element has body - + this.indentLevel++; for (DOMNode child : node.getChildren()) { boolean textElement = !child.isText(); From 743679fa8e1e57b3c58f636ef8fa76442dd7d71d Mon Sep 17 00:00:00 2001 From: enxio Date: Tue, 1 Oct 2019 13:05:31 +0200 Subject: [PATCH 08/39] Formatting and indetation. Does not work properly. --- .../lsp4xml/services/XMLFormatter.java | 35 ++++++++++-------- .../eclipse/lsp4xml/utils/StringUtils.java | 16 +++++--- .../org/eclipse/lsp4xml/utils/XMLBuilder.java | 37 ++++++++++--------- 3 files changed, 51 insertions(+), 37 deletions(-) diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java index 198397d09..fb158fdcd 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java @@ -112,7 +112,7 @@ private void setupRangeFormatting(Range range) throws BadLocationException { adjustOffsetToStartTag(); rangeText = fullText.substring(this.startOffset, this.endOffset); this.rangeDomDocument = DOMParser.getInstance().parse(rangeText, this.textDocument.getUri(), null, false); - } + } this.xmlBuilder = new XMLBuilder(this.options, "", textDocument.lineDelimiter(startPosition.getLine())); } @@ -159,8 +159,7 @@ private boolean putTagInline(String tag) { tag.equals("show-page")|| tag.equals("show-id")|| tag.equals("show-label")|| - tag.equals("show-title")|| - tag.equals("footnote")); + tag.equals("show-title")); } private void adjustOffsetToStartTag() throws BadLocationException { @@ -242,7 +241,7 @@ private DOMElement getFullDocElemFromRangeElem(DOMElement elemFromRangeDoc) { int fullOffset = -1; if (elemFromRangeDoc.hasStartTag()) { - fullOffset = getFullOffsetFromRangeOffset(elemFromRangeDoc.getStartTagOpenOffset()) + 1; + fullOffset = getFullOffsetFromRangeOffset(elemFromRangeDoc.getStartTagOpenOffset()) + 1; // +1 because offset must be here: <|root // for DOMNode.findNodeAt() to find the correct element } else if (elemFromRangeDoc.hasEndTag()) { @@ -286,17 +285,16 @@ private void format(DOMNode node) throws BadLocationException { if (node.getOwnerDocument().isDTD()) { doLineFeed = false; } else { -// ATSEC + // ATSEC doLineFeed = - !(node.isComment() && - ((DOMComment) node).isCommentSameLineEndTag()) + !(node.isComment() && ((DOMComment) node).isCommentSameLineEndTag()) && ( - !node.isText() || - ( - !((DOMText) node).isWhitespace() && - ((DOMText) node).hasSiblings() - ) - ); + !node.isText() || + ( + !((DOMText) node).isWhitespace() && + ((DOMText) node).hasSiblings() + ) + ); } if (node.isElement()) { DOMElement element = (DOMElement) node; @@ -371,8 +369,9 @@ private void format(DOMNode node) throws BadLocationException { boolean hasElements = false; if (node.hasChildNodes()) { // element has body - + this.indentLevel++; + //this.xmlBuilder.addContent("+>"); for (DOMNode child : node.getChildren()) { boolean textElement = !child.isText(); @@ -381,8 +380,10 @@ private void format(DOMNode node) throws BadLocationException { format(child); } this.indentLevel--; + //this.xmlBuilder.addContent("<+"); } if (element.hasEndTag()) { + //this.xmlBuilder.addContent(""); if (hasElements) { //this.xmlBuilder.addContent("[trace-8]"); if (!putTagInline(tag)) { @@ -419,7 +420,11 @@ private void format(DOMNode node) throws BadLocationException { this.xmlBuilder.endComment(); if (this.indentLevel == 0) { this.xmlBuilder.linefeed(); + } else if (this.indentLevel > 0 && !comment.isCommentSameLineEndTag()) { + this.xmlBuilder.linefeed(); + this.xmlBuilder.indent(this.indentLevel); } + } else if (node.isProcessingInstruction()) { addPIToXMLBuilder(node, this.xmlBuilder); if (this.indentLevel == 0) { @@ -433,7 +438,7 @@ private void format(DOMNode node) throws BadLocationException { // Generate content String content = textNode.getData(); - //this.xmlBuilder.addContent(content); + //this.xmlBuilder.addContent("["+content+"]"); this.xmlBuilder.addContent(content, textNode.isWhitespace(), textNode.hasSiblings(), textNode.getDelimiter(), this.indentLevel); return; diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java index d86e98807..463b294e9 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java @@ -80,13 +80,13 @@ public static void normalizeSpace(String str, StringBuilder b) { space = ""; b.append(c); } - } + } -// ATSEC - public static void normalizeSpace2(String str, StringBuilder b) { + // ATSEC + public static void normalizeSpace2(String str, StringBuilder b) { char c; int i = 0, len = str.length(); - + while (i < len) { c = str.charAt(i); if (c != '\n') { @@ -113,7 +113,7 @@ public static String normalizeSpace(String str) { return b.toString(); } -// ATSEC + // ATSEC public static String normalizeSpace2(String str) { StringBuilder b = new StringBuilder(str.length()); normalizeSpace2(str, b); @@ -433,3 +433,9 @@ public static String getString(Object obj) { } } + +// Local Variables: +// tab-width: 8 +// indent-tabs-mode: t +// c-basic-offset: 8 +// End: diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/XMLBuilder.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/XMLBuilder.java index 1f93c292c..66326997e 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/XMLBuilder.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/XMLBuilder.java @@ -23,7 +23,7 @@ * */ public class XMLBuilder { - + private final XMLFormattingOptions formattingOptions; private final String lineDelimiter; private final StringBuilder xml; @@ -103,9 +103,9 @@ public XMLBuilder addSingleAttribute(String name, String value) { /** * Used when only one attribute is being added to a node. - * + * * It will not perform any linefeeds and only basic indentation. - * + * * @param name attribute name * @param value attribute value * @return @@ -113,7 +113,7 @@ public XMLBuilder addSingleAttribute(String name, String value) { public XMLBuilder addSingleAttribute(String name, String value, boolean surroundWithQuotes) { xml.append(" "); addAttributeContents(name, true, value, surroundWithQuotes); - + return this; } @@ -130,9 +130,9 @@ public XMLBuilder addAttribute(String name, String value, int level) { /** * Used when you are knowingly adding multiple attributes. - * + * * It will do linefeeds and indentation. - * + * * @param name * @param value * @param level @@ -168,7 +168,7 @@ public XMLBuilder addAttribute(DOMAttr attr, int level, boolean surroundWithQuot /** * Builds the attribute {name, '=', and value}. - * + * * Never puts quotes around unquoted values unless indicated to by 'surroundWithQuotes' */ private void addAttributeContents(String name, Boolean equalsSign, String originalValue, boolean surroundWithQuotes) { @@ -180,7 +180,7 @@ private void addAttributeContents(String name, Boolean equalsSign, String origin } if(originalValue != null) { String quote = formattingOptions.isQuotations(XMLFormattingOptions.DOUBLE_QUOTES_VALUE) ? "\"" : "'"; - + if(DOMAttr.isQuoted(originalValue)) { if(originalValue.charAt(0) == '\'' && formattingOptions.isQuotations(XMLFormattingOptions.DOUBLE_QUOTES_VALUE) || originalValue.charAt(0) == '\"' && formattingOptions.isQuotations(XMLFormattingOptions.SINGLE_QUOTES_VALUE)) { @@ -192,11 +192,11 @@ private void addAttributeContents(String name, Boolean equalsSign, String origin } xml.append(quote); return; - } + } else { xml.append(originalValue); return; - } + } } else if(surroundWithQuotes) { xml.append(quote); @@ -209,7 +209,7 @@ else if(surroundWithQuotes) { else { xml.append(originalValue); } - } + } } public XMLBuilder linefeed() { @@ -228,6 +228,7 @@ public XMLBuilder addContent(String text, Boolean isWhitespaceContent, Boolean h if (isWhitespaceContent) { // whoah: terriable, but this one seems to preserve single space. if (text.length() == 1) { + //xml.append("+"); xml.append(text); } } @@ -235,15 +236,15 @@ public XMLBuilder addContent(String text, Boolean isWhitespaceContent, Boolean h if (!isWhitespaceContent) { if(isJoinContentLines()) { // ATSEC - // xml.append("A:"); + //xml.append("A:"); text = StringUtils.normalizeSpace2(text); } else if(hasSiblings) { - // xml.append("B:"); + //xml.append("B:"); text = text.trim(); // } else { // xml.append("C:"); } - // xml.append("["+text+"]"); + //xml.append("-["+text+"]-"); xml.append(text); } else if (!hasSiblings && isPreserveEmptyContent()) { xml.append(text); @@ -252,10 +253,11 @@ public XMLBuilder addContent(String text, Boolean isWhitespaceContent, Boolean h if(preservedNewLines > 0) { int newLineCount = StringUtils.getNumberOfNewLines(text, isWhitespaceContent, delimiter, preservedNewLines); for (int i = 0; i < newLineCount - 1; i++) { // - 1 because the node after will insert a delimiter + //xml.append("+"); xml.append(delimiter); } } - + } return this; } @@ -265,10 +267,11 @@ public XMLBuilder indent(int level) { if (isInsertSpaces()) { for (int j = 0; j < getTabSize(); j++) { xml.append(" "); -// xml.append("x"); + //xml.append("x"); } } else { xml.append("\t"); + //xml.append("y"); } } return this; @@ -335,7 +338,7 @@ public XMLBuilder addContentComment(String content) { } public XMLBuilder addDeclTagStart(DTDDeclNode tag) { - + xml.append(" Date: Wed, 2 Oct 2019 08:53:31 +0200 Subject: [PATCH 09/39] More debugging... --- .../lsp4xml/services/XMLFormatter.java | 57 ++++++++++++------- .../eclipse/lsp4xml/utils/StringUtils.java | 4 +- 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java index fb158fdcd..5c10a9f15 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java @@ -137,29 +137,29 @@ private boolean containsTextWithinStartTag() { } return ((DOMElement) fullNode).isInStartTag(fullDocOffset); } -// ATSEC + // ATSEC private boolean putTagInline(String tag) { return (tag.equals("b")|| - tag.equals("bibref")|| - tag.equals("color")|| - tag.equals("em")|| - tag.equals("figure")|| - tag.equals("i")|| - tag.equals("it")|| - tag.equals("link")|| - tag.equals("mark")|| - tag.equals("note")|| - tag.equals("s")|| - tag.equals("sub")|| - tag.equals("sup")|| - tag.equals("tt")|| - tag.equals("u")|| - tag.equals("xref")|| - tag.equals("show-number")|| - tag.equals("show-page")|| - tag.equals("show-id")|| - tag.equals("show-label")|| - tag.equals("show-title")); + tag.equals("bibref")|| + tag.equals("color")|| + tag.equals("em")|| + tag.equals("figure")|| + tag.equals("i")|| + tag.equals("it")|| + tag.equals("link")|| + tag.equals("mark")|| + tag.equals("note")|| + tag.equals("s")|| + tag.equals("sub")|| + tag.equals("sup")|| + tag.equals("tt")|| + tag.equals("u")|| + tag.equals("xref")|| + tag.equals("show-number")|| + tag.equals("show-page")|| + tag.equals("show-id")|| + tag.equals("show-label")|| + tag.equals("show-title")); } private void adjustOffsetToStartTag() throws BadLocationException { @@ -286,6 +286,21 @@ private void format(DOMNode node) throws BadLocationException { doLineFeed = false; } else { // ATSEC + // if (node.isComment()) { + // this.xmlBuilder.addContent("+isComment+"); + // if (((DOMComment) node).isCommentSameLineEndTag()) { + // this.xmlBuilder.addContent("+commentSameLine+"); + // } + // } + // if (node.isText()) { + // this.xmlBuilder.addContent("+isText+"); + // if (((DOMText) node).isWhitespace()) { + // this.xmlBuilder.addContent("+WS+"); + // } + // if (((DOMText) node).hasSiblings()) { + // this.xmlBuilder.addContent("+SIBL+"); + // } + // } doLineFeed = !(node.isComment() && ((DOMComment) node).isCommentSameLineEndTag()) && ( diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java index 463b294e9..ca8a89b75 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java @@ -86,7 +86,8 @@ public static void normalizeSpace(String str, StringBuilder b) { public static void normalizeSpace2(String str, StringBuilder b) { char c; int i = 0, len = str.length(); - + + //b.append("["+str+"]"); while (i < len) { c = str.charAt(i); if (c != '\n') { @@ -99,6 +100,7 @@ public static void normalizeSpace2(String str, StringBuilder b) { } i++; } + //b.append("!["+b+"]!"); } /** From 01b9cf9d7681e2e214a78fd7cc0253963f0e5d52 Mon Sep 17 00:00:00 2001 From: enxio Date: Fri, 4 Oct 2019 12:42:40 +0200 Subject: [PATCH 10/39] explain repo --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 9839eb208..0d7ab9d67 100644 --- a/README.md +++ b/README.md @@ -1 +1,5 @@ experimental + +attempts to implement a different formatting strategy where not every tag is in a new line, but some are kept inline. + +experimental From 58dc5dbe8fa0dec2ec0b2082a65d43b347edfb92 Mon Sep 17 00:00:00 2001 From: enxio Date: Fri, 18 Oct 2019 12:55:05 +0200 Subject: [PATCH 11/39] revert change in comment processing. --- .../main/java/org/eclipse/lsp4xml/services/XMLFormatter.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java index 5c10a9f15..da59bff62 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java @@ -435,11 +435,7 @@ private void format(DOMNode node) throws BadLocationException { this.xmlBuilder.endComment(); if (this.indentLevel == 0) { this.xmlBuilder.linefeed(); - } else if (this.indentLevel > 0 && !comment.isCommentSameLineEndTag()) { - this.xmlBuilder.linefeed(); - this.xmlBuilder.indent(this.indentLevel); } - } else if (node.isProcessingInstruction()) { addPIToXMLBuilder(node, this.xmlBuilder); if (this.indentLevel == 0) { From d6c740a5a34559f60debe091e292bf154a56ec82 Mon Sep 17 00:00:00 2001 From: enxio Date: Mon, 21 Oct 2019 10:54:44 +0200 Subject: [PATCH 12/39] Added quote to the list of inline tags --- .../src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java | 1 + 1 file changed, 1 insertion(+) diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java index da59bff62..4da0871e9 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java @@ -155,6 +155,7 @@ private boolean putTagInline(String tag) { tag.equals("tt")|| tag.equals("u")|| tag.equals("xref")|| + tag.equals("quote")|| tag.equals("show-number")|| tag.equals("show-page")|| tag.equals("show-id")|| From 076a4cfbb0926e95efdefc75051b221ad0138b28 Mon Sep 17 00:00:00 2001 From: enxio Date: Fri, 15 Nov 2019 09:26:42 +0100 Subject: [PATCH 13/39] Make normalizeSpace2 handle CRLF properly --- .../eclipse/lsp4xml/utils/StringUtils.java | 45 ++++++++++++------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java index ca8a89b75..70977ff65 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java @@ -61,7 +61,7 @@ public static boolean isWhitespace(String value) { /** * Normalizes the whitespace characters of a given string and applies it to the * given string builder. - * + * * @param str * @return the result of normalize space of the given string. */ @@ -83,29 +83,42 @@ public static void normalizeSpace(String str, StringBuilder b) { } // ATSEC + /** + * Normalizes the whitespace characters of a given string differently and applies it to the + * given string builder. + * + * @param str + * @return the result of normalize space of the given string. + */ public static void normalizeSpace2(String str, StringBuilder b) { char c; int i = 0, len = str.length(); + boolean lastWasSpace = false; - //b.append("["+str+"]"); while (i < len) { c = str.charAt(i); - if (c != '\n') { + if ((c != '\n') && (c != '\r')) { if (isTabOrSpace(c)) { for (int j = i + 1; j < len && isTabOrSpace(str.charAt(j)); ++j) { i = j; } } b.append(c); + lastWasSpace = false; + } else { + // do not append a space twice (CRLF) + if (!lastWasSpace) { + b.append(" "); + lastWasSpace = true; + } } i++; } - //b.append("!["+b+"]!"); } /** * Returns the result of normalize space of the given string. - * + * * @param str * @return the result of normalize space of the given string. */ @@ -125,7 +138,7 @@ public static String normalizeSpace2(String str) { /** * Returns the start whitespaces of the given line text. - * + * * @param lineText * @return the start whitespaces of the given line text. */ @@ -212,10 +225,10 @@ public static String lTrim(String value) { /** * Given a string that is only whitespace, this will return the amount of * newline characters. - * + * * If the newLineCounter becomes > newLineLimit, then the value of newLineLimit * is always returned. - * + * * @param text * @param isWhitespace * @param delimiter @@ -251,7 +264,7 @@ public static int getNumberOfNewLines(String text, boolean isWhitespace, String /** * Given a string will give back a non null string that is either the given * string, or an empty string. - * + * * @param text * @return */ @@ -264,12 +277,12 @@ public static String getDefaultString(String text) { /** * Traverses backwards from the endOffset until it finds a whitespace character. - * + * * The offset of the character after the whitespace is returned. - * + * * (text = "abcd efg|h", endOffset = 8) -> 5 - * - * + * + * * @param text * @param endOffset non-inclusive * @return Start offset directly after the first whitespace. @@ -298,10 +311,10 @@ public static int getOffsetAfterWhitespace(String text, int endOffset) { /** * Returns the number of consecutive whitespace characters in front - * of text + * of text * @param text String of interest * @return the number of consecutive whitespace characters in front - * of text + * of text */ public static int getFrontWhitespaceLength(String text) { @@ -325,7 +338,7 @@ public static int getFrontWhitespaceLength(String text) { * the end of text */ public static int getTrailingWhitespaceLength(String text) { - + if (StringUtils.isWhitespace(text)) { return text.length(); } From 6143c9354e3c60f35e20e4d9e5a2080e630f3639 Mon Sep 17 00:00:00 2001 From: enxio Date: Fri, 15 Nov 2019 09:36:52 +0100 Subject: [PATCH 14/39] More better. --- .../src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java index 70977ff65..e64f3cbd9 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java @@ -104,7 +104,7 @@ public static void normalizeSpace2(String str, StringBuilder b) { } } b.append(c); - lastWasSpace = false; + lastWasSpace = c == ' '; } else { // do not append a space twice (CRLF) if (!lastWasSpace) { From 96e8137643f03959bd39478e96d36df97e2fecb6 Mon Sep 17 00:00:00 2001 From: enxio Date: Fri, 15 Nov 2019 09:59:09 +0100 Subject: [PATCH 15/39] Now it's good... --- .../src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java index e64f3cbd9..2faacaabd 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java @@ -104,7 +104,7 @@ public static void normalizeSpace2(String str, StringBuilder b) { } } b.append(c); - lastWasSpace = c == ' '; + lastWasSpace = isTabOrSpace(c); } else { // do not append a space twice (CRLF) if (!lastWasSpace) { From e92407196087060e2a34166af7c654d7f9fcca3a Mon Sep 17 00:00:00 2001 From: enxio Date: Fri, 15 Nov 2019 10:18:12 +0100 Subject: [PATCH 16/39] More corrections, but check the need for normalizeSpace2() --- .../org/eclipse/lsp4xml/utils/StringUtils.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java index 2faacaabd..775a87255 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java @@ -86,27 +86,31 @@ public static void normalizeSpace(String str, StringBuilder b) { /** * Normalizes the whitespace characters of a given string differently and applies it to the * given string builder. - * + * XXX: not sure whether this is really needed and the function above already is what we need... * @param str * @return the result of normalize space of the given string. */ public static void normalizeSpace2(String str, StringBuilder b) { - char c; int i = 0, len = str.length(); boolean lastWasSpace = false; while (i < len) { - c = str.charAt(i); + char c = str.charAt(i); if ((c != '\n') && (c != '\r')) { - if (isTabOrSpace(c)) { - for (int j = i + 1; j < len && isTabOrSpace(str.charAt(j)); ++j) { + boolean isWS = Character.isWhitespace(c); + if (isWS) { + for (int j = i + 1; j < len && Character.isWhitespace(str.charAt(j)); ++j) { i = j; } } + // normalize to " " not the first WS char + if (isWS) { + c = ' '; + } b.append(c); - lastWasSpace = isTabOrSpace(c); + lastWasSpace = isWS; } else { - // do not append a space twice (CRLF) + // do not append a space twice if (!lastWasSpace) { b.append(" "); lastWasSpace = true; From 511bf5ba7e1bb1d81a9167099b266464214dd921 Mon Sep 17 00:00:00 2001 From: enxio <31342498+enxio@users.noreply.github.com> Date: Mon, 13 Jan 2020 11:14:56 +0100 Subject: [PATCH 17/39] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0d7ab9d67..e1e0b99c7 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ experimental -attempts to implement a different formatting strategy where not every tag is in a new line, but some are kept inline. +attempts to implement a different formatting strategy where not every tag is in a new line, but some are kept inline (see https://github.com/angelozerr/lsp4xml/issues/594). experimental From e5278e451d57396b2cd2e186fd3c15a6059b5aef Mon Sep 17 00:00:00 2001 From: enxio Date: Fri, 28 Feb 2020 12:04:14 +0100 Subject: [PATCH 18/39] newlines... --- .../java/org/eclipse/lsp4xml/services/XMLFormatter.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java index 4da0871e9..fee4d3fc9 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLFormatter.java @@ -112,7 +112,7 @@ private void setupRangeFormatting(Range range) throws BadLocationException { adjustOffsetToStartTag(); rangeText = fullText.substring(this.startOffset, this.endOffset); this.rangeDomDocument = DOMParser.getInstance().parse(rangeText, this.textDocument.getUri(), null, false); - } + } this.xmlBuilder = new XMLBuilder(this.options, "", textDocument.lineDelimiter(startPosition.getLine())); } @@ -242,7 +242,7 @@ private DOMElement getFullDocElemFromRangeElem(DOMElement elemFromRangeDoc) { int fullOffset = -1; if (elemFromRangeDoc.hasStartTag()) { - fullOffset = getFullOffsetFromRangeOffset(elemFromRangeDoc.getStartTagOpenOffset()) + 1; + fullOffset = getFullOffsetFromRangeOffset(elemFromRangeDoc.getStartTagOpenOffset()) + 1; // +1 because offset must be here: <|root // for DOMNode.findNodeAt() to find the correct element } else if (elemFromRangeDoc.hasEndTag()) { @@ -385,7 +385,7 @@ private void format(DOMNode node) throws BadLocationException { boolean hasElements = false; if (node.hasChildNodes()) { // element has body - + this.indentLevel++; //this.xmlBuilder.addContent("+>"); for (DOMNode child : node.getChildren()) { From ce827caf31085c71adde8b4384859aae086ec32c Mon Sep 17 00:00:00 2001 From: enxio Date: Fri, 28 Feb 2020 13:30:23 +0100 Subject: [PATCH 19/39] Ignore more local stuff. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 89b3e62b1..e1fc0bb74 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ target/ **/adhoctest/ lsp4xml.code-workspace .vscode/** +mkdist From f433569d33a43f8b53c0a892631aa3769b5c7516 Mon Sep 17 00:00:00 2001 From: enxio Date: Fri, 28 Feb 2020 13:38:42 +0100 Subject: [PATCH 20/39] comment clarification --- .../src/main/java/org/eclipse/lemminx/utils/StringUtils.java | 1 - 1 file changed, 1 deletion(-) diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/StringUtils.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/StringUtils.java index 7f2d69385..4e94ced62 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/StringUtils.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/StringUtils.java @@ -88,7 +88,6 @@ public static void normalizeSpace(String str, StringBuilder b) { /** * Normalizes the whitespace characters of a given string differently and applies it to the * given string builder. - * XXX: not sure whether this is really needed and the function above already is what we need... * @param str * @return the result of normalize space of the given string. */ From a8c8360399270cea2f1eb3a42eefcde77b9ac992 Mon Sep 17 00:00:00 2001 From: enxio Date: Mon, 9 Mar 2020 08:38:40 +0100 Subject: [PATCH 21/39] merge --- .vscode/settings.json | 2 +- Jenkinsfile | 35 ++ org.eclipse.lemminx/pom.xml | 335 ++++++++++-------- .../eclipse/lemminx/XMLWorkspaceService.java | 1 - .../extensions/xsd/utils/XSDUtils.java | 2 +- .../lemminx/services/HoverRequest.java | 2 +- .../lemminx/services/XMLFormatter.java | 9 - .../eclipse/lemminx/services/XMLRename.java | 1 - .../lemminx/commons/TextDocumentTest.java | 2 - .../dom/DOMDocumentVersionCheckerTest.java | 2 - .../dom/DOMParserForInternalDTDTest.java | 8 - .../eclipse/lemminx/dom/DOMParserTest.java | 16 - .../parser/XMLScannerForExternalDTDTest.java | 3 - .../parser/XMLScannerForInternalDTDTest.java | 3 - .../lemminx/dom/parser/XMLScannerTest.java | 3 - .../XMLFileAssociationsDiagnosticsTest.java | 1 - .../model/FilesChangedTrackerTest.java | 1 - .../PrologCompletionExtensionsTest.java | 2 +- .../lemminx/extensions/xsd/DataTypeTest.java | 1 - .../xsl/XSLCompletionExtensionsTest.java | 1 - .../xsl/XSLValidationExtensionsTest.java | 1 - .../lemminx/services/XMLCompletionTest.java | 5 - .../lemminx/services/XMLFoldingsTest.java | 1 - .../lemminx/services/XMLFormatterTest.java | 1 - .../services/XMLSymbolInformationsTest.java | 1 - .../extensions/AggregetedHoverValuesTest.java | 2 - .../ExtensionRegistryDisposeTest.java | 2 - .../extensions/HTMLHoverExtensionsTest.java | 3 - .../lemminx/settings/SettingsTest.java | 11 +- .../capabilities/XMLCapabilitiesTest.java | 2 - .../CacheResourcesManagerTest.java | 8 +- .../utils/CompletionSortTextHelperTest.java | 1 - .../eclipse/lemminx/utils/FilesUtilsTest.java | 1 - .../lemminx/utils/StringUtilsTest.java | 1 - .../lemminx/utils/VersionHelperTest.java | 1 - .../eclipse/lemminx/utils/XMLBuilderTest.java | 1 - .../lemminx/utils/XMLPositionUtilityTest.java | 1 - pom.xml | 11 +- 38 files changed, 232 insertions(+), 252 deletions(-) create mode 100644 Jenkinsfile diff --git a/.vscode/settings.json b/.vscode/settings.json index 41cc1904f..7d853bf9f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,7 +6,7 @@ "**/.factorypath": true }, "editor.formatOnSave": false, - "editor.renderWhitespace": "boundary", + "editor.renderWhitespace": "all", //Use consistent indentation "editor.detectIndentation": false, "editor.tabSize": 4, diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..a41d25942 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,35 @@ +pipeline{ + agent any + tools { + jdk 'adoptopenjdk-hotspot-jdk8-latest' + } + environment { + MAVEN_HOME = '$WORKSPACE/.m2/' + MAVEN_USER_HOME = '$MAVEN_HOME' + } + stages{ + stage("Maven Build"){ + steps { + withMaven { + sh './mvnw clean verify -B -Pci,eclipse-sign,generate-p2' + } + } + } + stage('Deploy') { + when { + branch 'master' + } + steps { + sshagent ( ['projects-storage.eclipse.org-bot-ssh']) { + sh ''' + targetDir=/home/data/httpd/download.eclipse.org/lemminx/snapshots + ssh genie.lemminx@projects-storage.eclipse.org rm -rf $targetDir + ssh genie.lemminx@projects-storage.eclipse.org mkdir -p $targetDir + scp -r org.eclipse.lemminx/target/org.eclipse.lemminx-* genie.lemminx@projects-storage.eclipse.org:$targetDir + ssh genie.lemminx@projects-storage.eclipse.org unzip $targetDir/org.eclipse.lemminx-p2repo.zip -d $targetDir/repository + ''' + } + } + } + } +} \ No newline at end of file diff --git a/org.eclipse.lemminx/pom.xml b/org.eclipse.lemminx/pom.xml index 715a765e4..99a97a6a8 100644 --- a/org.eclipse.lemminx/pom.xml +++ b/org.eclipse.lemminx/pom.xml @@ -1,158 +1,179 @@ - - 4.0.0 - - org.eclipse - lemminx - 0.9.2-SNAPSHOT - - org.eclipse.lemminx - - UTF-8 - yyyyMMdd-HHmm - ${maven.build.timestamp} - - - - - src/main/resources/ - true - - **/*.properties - - - - src/main/resources/ - false - - **/*.properties - - - - - - org.codehaus.mojo - build-helper-maven-plugin - 3.0.0 - - - parse-version - - parse-version - - - - - - org.apache.felix - maven-bundle-plugin - - - maven-assembly-plugin - 3.1.1 - - - src/assembly/distribution.xml - - ${project.artifactId} - - - org.eclipse.lemminx.XMLServerLauncher - - - - - - make-assembly - package - - single - - - - - - - - - com.google.guava - guava - 27.0.1-jre - - - com.google.code.gson - gson - - - org.eclipse.lsp4j - org.eclipse.lsp4j - - - com.google.guava - guava - - - - - org.eclipse.lsp4j - org.eclipse.lsp4j.jsonrpc - - - xerces - xercesImpl - 2.12.0 - - - xml-apis - xml-apis - 1.4.01 - - - com.kotcrab.remark - remark - 1.0.0 - - - org.jsoup - jsoup - 1.9.2 - - - xml-resolver - xml-resolver - 1.2 - runtime - - - junit - junit - test - - - org.eclipse.jetty - jetty-server - 9.4.17.v20190418 - test - - - - - generate-p2 - - - - org.eclipse.tycho.extras - tycho-eclipserun-plugin - - - maven-assembly-plugin - - - src/assembly/p2repo.xml - - - - - - - + + 4.0.0 + + org.eclipse + lemminx + 0.9.2-SNAPSHOT + + org.eclipse.lemminx + + UTF-8 + yyyyMMdd-HHmm + ${maven.build.timestamp} + + + + + src/main/resources/ + true + + **/*.properties + + + + src/main/resources/ + false + + **/*.properties + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 3.0.0 + + + parse-version + + parse-version + + + + + + org.apache.felix + maven-bundle-plugin + + + maven-assembly-plugin + 3.1.1 + + + src/assembly/distribution.xml + + ${project.artifactId} + + + org.eclipse.lemminx.XMLServerLauncher + + + + + + make-assembly + package + + single + + + + + + + + + com.google.guava + guava + 27.0.1-jre + + + com.google.code.gson + gson + + + org.eclipse.lsp4j + org.eclipse.lsp4j + + + com.google.guava + guava + + + + + org.eclipse.lsp4j + org.eclipse.lsp4j.jsonrpc + + + xerces + xercesImpl + 2.12.0 + + + xml-apis + xml-apis + 1.4.01 + + + com.kotcrab.remark + remark + 1.0.0 + + + org.jsoup + jsoup + 1.9.2 + + + xml-resolver + xml-resolver + 1.2 + runtime + + + junit + junit + test + + + org.eclipse.jetty + jetty-server + 9.4.17.v20190418 + test + + + + + eclipse-sign + + + + org.eclipse.cbi.maven.plugins + eclipse-jarsigner-plugin + 1.1.4 + + + sign + package + + sign + + + + + + + + + generate-p2 + + + + org.eclipse.tycho.extras + tycho-eclipserun-plugin + + + maven-assembly-plugin + + + src/assembly/p2repo.xml + + + + + + + \ No newline at end of file diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/XMLWorkspaceService.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/XMLWorkspaceService.java index 89e16f4f1..5b0b5713e 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/XMLWorkspaceService.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/XMLWorkspaceService.java @@ -15,7 +15,6 @@ import java.util.List; import java.util.concurrent.CompletableFuture; -import org.eclipse.lemminx.XMLTextDocumentService; import org.eclipse.lsp4j.DidChangeConfigurationParams; import org.eclipse.lsp4j.DidChangeWatchedFilesParams; import org.eclipse.lsp4j.FileEvent; diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xsd/utils/XSDUtils.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xsd/utils/XSDUtils.java index 57e9ee131..b3addd083 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xsd/utils/XSDUtils.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xsd/utils/XSDUtils.java @@ -437,7 +437,7 @@ private static void updateTracker(SchemaGrammar grammar, Set trac } } // Track the imported grammars - Vector importedGrammars = grammar.getImportedGrammars(); + Vector importedGrammars = grammar.getImportedGrammars(); if (importedGrammars != null) { for (Object importedGrammar : importedGrammars) { updateTracker((SchemaGrammar) importedGrammar, trackedGrammars, trackedURIs, tracker); diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/HoverRequest.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/HoverRequest.java index 90b864c67..891270a6f 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/HoverRequest.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/HoverRequest.java @@ -44,7 +44,7 @@ public HoverRequest(DOMDocument xmlDocument, Position position, XMLHoverSettings protected DOMNode findNodeAt(DOMDocument xmlDocument, int offset) { DOMNode node = xmlDocument.findNodeAt(offset); if (node != null && node.isElement()) { - DOMAttr attr = xmlDocument.findAttrAt(node, offset); + DOMAttr attr = DOMNode.findAttrAt(node, offset); if (attr != null) { return attr; } diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java index 568f75619..1a38b016b 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java @@ -593,15 +593,6 @@ private List getFormatTextEdit() throws BadLocationException return edits; } - private static boolean isFirstChildNode(DOMNode node) { - return node.equals(node.getParentNode().getFirstChild()); - } - - private static boolean isPreviousSiblingNodeType(DOMNode node, short nodeType) { - DOMNode previousNode = node.getPreviousSibling(); - return previousNode != null && previousNode.getNodeType() == nodeType; - } - private static void addPIToXMLBuilder(DOMNode node, XMLBuilder xml) { DOMProcessingInstruction processingInstruction = (DOMProcessingInstruction) node; xml.startPrologOrPI(processingInstruction.getTarget()); diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLRename.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLRename.java index 7ad0ec9b7..826ab8bb0 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLRename.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLRename.java @@ -32,7 +32,6 @@ import org.eclipse.lemminx.dom.DOMElement; import org.eclipse.lemminx.dom.DOMNode; import org.eclipse.lemminx.dom.parser.TokenType; -import org.eclipse.lemminx.services.RenameRequest; import org.eclipse.lemminx.services.extensions.IRenameParticipant; import org.eclipse.lemminx.services.extensions.XMLExtensionsRegistry; import org.eclipse.lsp4j.Position; diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/commons/TextDocumentTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/commons/TextDocumentTest.java index c2d573e17..d11cf1755 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/commons/TextDocumentTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/commons/TextDocumentTest.java @@ -12,8 +12,6 @@ */ package org.eclipse.lemminx.commons; -import org.eclipse.lemminx.commons.BadLocationException; -import org.eclipse.lemminx.commons.TextDocument; import org.eclipse.lsp4j.Position; import org.junit.Assert; import org.junit.Test; diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/dom/DOMDocumentVersionCheckerTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/dom/DOMDocumentVersionCheckerTest.java index 95fe9963d..776504a4e 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/dom/DOMDocumentVersionCheckerTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/dom/DOMDocumentVersionCheckerTest.java @@ -16,8 +16,6 @@ import org.eclipse.lemminx.commons.BadLocationException; import org.eclipse.lemminx.commons.TextDocument; import org.eclipse.lemminx.commons.TextDocumentVersionChecker; -import org.eclipse.lemminx.dom.DOMDocument; -import org.eclipse.lemminx.dom.DOMParser; import org.junit.Assert; import org.junit.Test; diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/dom/DOMParserForInternalDTDTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/dom/DOMParserForInternalDTDTest.java index 63f72e921..0fbc40e42 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/dom/DOMParserForInternalDTDTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/dom/DOMParserForInternalDTDTest.java @@ -14,14 +14,6 @@ import static org.junit.Assert.assertTrue; -import org.eclipse.lemminx.dom.DOMDocument; -import org.eclipse.lemminx.dom.DOMDocumentType; -import org.eclipse.lemminx.dom.DOMParser; -import org.eclipse.lemminx.dom.DOMText; -import org.eclipse.lemminx.dom.DTDAttlistDecl; -import org.eclipse.lemminx.dom.DTDElementDecl; -import org.eclipse.lemminx.dom.DTDEntityDecl; -import org.eclipse.lemminx.dom.DTDNotationDecl; import org.junit.Assert; import org.junit.Test; diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/dom/DOMParserTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/dom/DOMParserTest.java index 993d147d2..4aa6aac07 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/dom/DOMParserTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/dom/DOMParserTest.java @@ -16,22 +16,6 @@ import java.util.List; -import org.eclipse.lemminx.dom.DOMCDATASection; -import org.eclipse.lemminx.dom.DOMCharacterData; -import org.eclipse.lemminx.dom.DOMComment; -import org.eclipse.lemminx.dom.DOMDocument; -import org.eclipse.lemminx.dom.DOMDocumentType; -import org.eclipse.lemminx.dom.DOMElement; -import org.eclipse.lemminx.dom.DOMNode; -import org.eclipse.lemminx.dom.DOMParser; -import org.eclipse.lemminx.dom.DOMProcessingInstruction; -import org.eclipse.lemminx.dom.DOMText; -import org.eclipse.lemminx.dom.DTDAttlistDecl; -import org.eclipse.lemminx.dom.DTDDeclNode; -import org.eclipse.lemminx.dom.DTDDeclParameter; -import org.eclipse.lemminx.dom.DTDElementDecl; -import org.eclipse.lemminx.dom.DTDEntityDecl; -import org.eclipse.lemminx.dom.DTDNotationDecl; import org.eclipse.lemminx.dom.DOMDocumentType.DocumentTypeKind; import org.junit.Assert; import org.junit.Ignore; diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/dom/parser/XMLScannerForExternalDTDTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/dom/parser/XMLScannerForExternalDTDTest.java index 06f16a885..df3ca2125 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/dom/parser/XMLScannerForExternalDTDTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/dom/parser/XMLScannerForExternalDTDTest.java @@ -14,9 +14,6 @@ import static org.junit.Assert.assertEquals; -import org.eclipse.lemminx.dom.parser.Scanner; -import org.eclipse.lemminx.dom.parser.TokenType; -import org.eclipse.lemminx.dom.parser.XMLScanner; import org.junit.Test; /** diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/dom/parser/XMLScannerForInternalDTDTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/dom/parser/XMLScannerForInternalDTDTest.java index 634556d57..764c9debb 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/dom/parser/XMLScannerForInternalDTDTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/dom/parser/XMLScannerForInternalDTDTest.java @@ -14,9 +14,6 @@ import static org.junit.Assert.assertEquals; -import org.eclipse.lemminx.dom.parser.Scanner; -import org.eclipse.lemminx.dom.parser.TokenType; -import org.eclipse.lemminx.dom.parser.XMLScanner; import org.junit.Test; /** diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/dom/parser/XMLScannerTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/dom/parser/XMLScannerTest.java index c5022047c..b010c4bde 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/dom/parser/XMLScannerTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/dom/parser/XMLScannerTest.java @@ -14,9 +14,6 @@ import static org.junit.Assert.assertEquals; -import org.eclipse.lemminx.dom.parser.Scanner; -import org.eclipse.lemminx.dom.parser.TokenType; -import org.eclipse.lemminx.dom.parser.XMLScanner; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLFileAssociationsDiagnosticsTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLFileAssociationsDiagnosticsTest.java index a02dfc450..534c9205b 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLFileAssociationsDiagnosticsTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLFileAssociationsDiagnosticsTest.java @@ -24,7 +24,6 @@ import org.eclipse.lemminx.XMLAssert; import org.eclipse.lemminx.XMLAssert.SettingsSaveContext; import org.eclipse.lemminx.commons.BadLocationException; -import org.eclipse.lemminx.extensions.contentmodel.ContentModelPlugin; import org.eclipse.lemminx.extensions.contentmodel.model.ContentModelManager; import org.eclipse.lemminx.extensions.contentmodel.participants.XMLSchemaErrorCode; import org.eclipse.lemminx.extensions.contentmodel.settings.ContentModelSettings; diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/model/FilesChangedTrackerTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/model/FilesChangedTrackerTest.java index afed56c4f..fa7ce2f27 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/model/FilesChangedTrackerTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/model/FilesChangedTrackerTest.java @@ -14,7 +14,6 @@ import java.io.IOException; import org.eclipse.lemminx.extensions.contentmodel.BaseFileTempTest; -import org.eclipse.lemminx.extensions.contentmodel.model.FilesChangedTracker; import org.junit.Assert; import org.junit.Test; diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/prolog/PrologCompletionExtensionsTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/prolog/PrologCompletionExtensionsTest.java index 7b0bbc0bb..add6fb9a6 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/prolog/PrologCompletionExtensionsTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/prolog/PrologCompletionExtensionsTest.java @@ -18,7 +18,7 @@ import org.eclipse.lemminx.XMLAssert; import org.eclipse.lemminx.commons.BadLocationException; -import org.eclipse.lemminx.extensions.prolog.PrologModel; +import org.eclipse.lemminx.extensions.xsl.XSLURIResolverExtension; import org.eclipse.lemminx.services.XMLLanguageService; import org.eclipse.lemminx.settings.XMLCompletionSettings; import org.eclipse.lemminx.settings.XMLFormattingOptions; diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/xsd/DataTypeTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/xsd/DataTypeTest.java index e3c1ffbf6..e0a502157 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/xsd/DataTypeTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/xsd/DataTypeTest.java @@ -11,7 +11,6 @@ *******************************************************************************/ package org.eclipse.lemminx.extensions.xsd; -import org.eclipse.lemminx.extensions.xsd.DataType; import org.junit.Assert; import org.junit.Test; diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/xsl/XSLCompletionExtensionsTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/xsl/XSLCompletionExtensionsTest.java index c1ec15ecd..a301a1b3c 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/xsl/XSLCompletionExtensionsTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/xsl/XSLCompletionExtensionsTest.java @@ -17,7 +17,6 @@ import org.eclipse.lemminx.XMLAssert; import org.eclipse.lemminx.commons.BadLocationException; -import org.eclipse.lemminx.extensions.xsl.XSLURIResolverExtension; import org.eclipse.lsp4j.CompletionItem; import org.junit.Test; diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/xsl/XSLValidationExtensionsTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/xsl/XSLValidationExtensionsTest.java index 1242b05fb..ffe762c24 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/xsl/XSLValidationExtensionsTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/xsl/XSLValidationExtensionsTest.java @@ -17,7 +17,6 @@ import org.eclipse.lemminx.XMLAssert; import org.eclipse.lemminx.commons.BadLocationException; import org.eclipse.lemminx.extensions.contentmodel.participants.XMLSchemaErrorCode; -import org.eclipse.lemminx.extensions.xsl.XSLURIResolverExtension; import org.eclipse.lsp4j.Diagnostic; import org.junit.Test; diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLCompletionTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLCompletionTest.java index 6252d9c1a..5f65e71d4 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLCompletionTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLCompletionTest.java @@ -27,9 +27,7 @@ import org.eclipse.lemminx.customservice.AutoCloseTagResponse; import org.eclipse.lemminx.dom.DOMDocument; import org.eclipse.lemminx.dom.DOMParser; -import org.eclipse.lemminx.services.XMLLanguageService; import org.eclipse.lemminx.settings.SharedSettings; -import org.eclipse.lemminx.settings.XMLCompletionSettings; import org.eclipse.lsp4j.CompletionItem; import org.eclipse.lsp4j.CompletionList; import org.eclipse.lsp4j.Position; @@ -44,13 +42,10 @@ public class XMLCompletionTest { private XMLLanguageService languageService; - private XMLCompletionSettings sharedCompletionSettings; @Before public void initializeLanguageService() { languageService = new XMLLanguageService(); - sharedCompletionSettings = new XMLCompletionSettings(); - } @Test diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLFoldingsTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLFoldingsTest.java index 9a5d944e7..691fa9917 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLFoldingsTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLFoldingsTest.java @@ -19,7 +19,6 @@ import org.eclipse.lemminx.commons.TextDocument; import org.eclipse.lemminx.dom.DOMDocument; import org.eclipse.lemminx.dom.DOMParser; -import org.eclipse.lemminx.services.XMLLanguageService; import org.eclipse.lemminx.settings.XMLFoldingSettings; import org.eclipse.lsp4j.FoldingRange; import org.eclipse.lsp4j.FoldingRangeCapabilities; diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLFormatterTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLFormatterTest.java index a8364b3e8..da0fa069e 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLFormatterTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLFormatterTest.java @@ -21,7 +21,6 @@ import org.eclipse.lemminx.commons.TextDocument; import org.eclipse.lemminx.dom.DOMDocument; import org.eclipse.lemminx.dom.DOMParser; -import org.eclipse.lemminx.services.XMLLanguageService; import org.eclipse.lemminx.settings.XMLFormattingOptions; import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.Range; diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLSymbolInformationsTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLSymbolInformationsTest.java index de0b55334..16b5f14e8 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLSymbolInformationsTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLSymbolInformationsTest.java @@ -21,7 +21,6 @@ import org.eclipse.lemminx.commons.BadLocationException; import org.eclipse.lemminx.dom.DOMDocument; import org.eclipse.lemminx.dom.DOMParser; -import org.eclipse.lemminx.services.XMLLanguageService; import org.eclipse.lsp4j.Location; import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.Range; diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/extensions/AggregetedHoverValuesTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/extensions/AggregetedHoverValuesTest.java index 9900b233b..61c0ad1b9 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/extensions/AggregetedHoverValuesTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/extensions/AggregetedHoverValuesTest.java @@ -18,8 +18,6 @@ import org.eclipse.lemminx.XMLAssert; import org.eclipse.lemminx.commons.BadLocationException; import org.eclipse.lemminx.services.XMLLanguageService; -import org.eclipse.lemminx.services.extensions.HoverParticipantAdapter; -import org.eclipse.lemminx.services.extensions.IHoverRequest; import org.junit.Test; /** diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/extensions/ExtensionRegistryDisposeTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/extensions/ExtensionRegistryDisposeTest.java index e0f05e36d..2ee5492d0 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/extensions/ExtensionRegistryDisposeTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/extensions/ExtensionRegistryDisposeTest.java @@ -13,8 +13,6 @@ import static org.junit.Assert.assertTrue; -import org.eclipse.lemminx.services.extensions.IXMLExtension; -import org.eclipse.lemminx.services.extensions.XMLExtensionsRegistry; import org.eclipse.lemminx.services.extensions.save.ISaveContext; import org.eclipse.lsp4j.InitializeParams; import org.junit.Test; diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/extensions/HTMLHoverExtensionsTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/extensions/HTMLHoverExtensionsTest.java index 6550cae49..3eb1fbe6b 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/extensions/HTMLHoverExtensionsTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/extensions/HTMLHoverExtensionsTest.java @@ -15,9 +15,6 @@ import org.eclipse.lemminx.XMLAssert; import org.eclipse.lemminx.commons.BadLocationException; import org.eclipse.lemminx.services.XMLLanguageService; -import org.eclipse.lemminx.services.extensions.HoverParticipantAdapter; -import org.eclipse.lemminx.services.extensions.IHoverParticipant; -import org.eclipse.lemminx.services.extensions.IHoverRequest; import org.junit.Test; /** diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/settings/SettingsTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/settings/SettingsTest.java index b1a7a74fb..5ce342f9d 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/settings/SettingsTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/settings/SettingsTest.java @@ -22,16 +22,14 @@ import java.io.File; +import com.google.gson.Gson; +import com.google.gson.JsonObject; + import org.eclipse.lemminx.XMLLanguageServer; import org.eclipse.lemminx.XMLTextDocumentService; import org.eclipse.lemminx.client.CodeLensKind; import org.eclipse.lemminx.client.ExtendedClientCapabilities; import org.eclipse.lemminx.extensions.contentmodel.settings.ContentModelSettings; -import org.eclipse.lemminx.settings.AllXMLSettings; -import org.eclipse.lemminx.settings.InitializationOptionsSettings; -import org.eclipse.lemminx.settings.XMLExcludedSymbolFile; -import org.eclipse.lemminx.settings.XMLFormattingOptions; -import org.eclipse.lemminx.settings.XMLGeneralClientSettings; import org.eclipse.lemminx.settings.capabilities.InitializationOptionsExtendedClientCapabilities; import org.eclipse.lemminx.utils.FilesUtils; import org.eclipse.lsp4j.FormattingOptions; @@ -40,9 +38,6 @@ import org.junit.Assert; import org.junit.Test; -import com.google.gson.Gson; -import com.google.gson.JsonObject; - /** * Tests for settings. */ diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/settings/capabilities/XMLCapabilitiesTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/settings/capabilities/XMLCapabilitiesTest.java index 376ba2955..86ca47d25 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/settings/capabilities/XMLCapabilitiesTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/settings/capabilities/XMLCapabilitiesTest.java @@ -24,8 +24,6 @@ import java.util.concurrent.CompletableFuture; import org.eclipse.lemminx.XMLTextDocumentService; -import org.eclipse.lemminx.settings.capabilities.ServerCapabilitiesInitializer; -import org.eclipse.lemminx.settings.capabilities.XMLCapabilityManager; import org.eclipse.lsp4j.ClientCapabilities; import org.eclipse.lsp4j.CodeActionCapabilities; import org.eclipse.lsp4j.CompletionCapabilities; diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/uriresolver/CacheResourcesManagerTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/uriresolver/CacheResourcesManagerTest.java index 80fa21634..4843d5259 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/uriresolver/CacheResourcesManagerTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/uriresolver/CacheResourcesManagerTest.java @@ -20,17 +20,15 @@ import java.io.IOException; import java.util.concurrent.TimeUnit; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; + import org.eclipse.lemminx.AbstractCacheBasedTest; -import org.eclipse.lemminx.uriresolver.CacheResourceDownloadingException; -import org.eclipse.lemminx.uriresolver.CacheResourcesManager; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; - public class CacheResourcesManagerTest extends AbstractCacheBasedTest { private CacheResourcesManager cacheResourcesManager; diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/CompletionSortTextHelperTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/CompletionSortTextHelperTest.java index bea9f931b..b206e3ebd 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/CompletionSortTextHelperTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/CompletionSortTextHelperTest.java @@ -13,7 +13,6 @@ import static org.junit.Assert.assertEquals; -import org.eclipse.lemminx.utils.CompletionSortTextHelper; import org.eclipse.lsp4j.CompletionItemKind; import org.junit.Test; diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/FilesUtilsTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/FilesUtilsTest.java index 3004f0f29..716b5419f 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/FilesUtilsTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/FilesUtilsTest.java @@ -17,7 +17,6 @@ import java.nio.file.Path; import java.nio.file.Paths; -import org.eclipse.lemminx.utils.FilesUtils; import org.junit.Test; /** diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/StringUtilsTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/StringUtilsTest.java index 024b3efe4..f4adcac49 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/StringUtilsTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/StringUtilsTest.java @@ -19,7 +19,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import org.eclipse.lemminx.utils.StringUtils; import org.junit.Assert; import org.junit.Test; diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/VersionHelperTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/VersionHelperTest.java index 4e3ab388b..0b3fb07b2 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/VersionHelperTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/VersionHelperTest.java @@ -17,7 +17,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.eclipse.lemminx.utils.VersionHelper; import org.junit.Test; public class VersionHelperTest { diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/XMLBuilderTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/XMLBuilderTest.java index 4180c8a77..aebe76173 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/XMLBuilderTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/XMLBuilderTest.java @@ -13,7 +13,6 @@ package org.eclipse.lemminx.utils; import org.eclipse.lemminx.settings.XMLFormattingOptions; -import org.eclipse.lemminx.utils.XMLBuilder; import org.junit.Assert; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/XMLPositionUtilityTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/XMLPositionUtilityTest.java index c0fb2dd46..e95b25356 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/XMLPositionUtilityTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/XMLPositionUtilityTest.java @@ -14,7 +14,6 @@ import org.eclipse.lemminx.commons.BadLocationException; import org.eclipse.lemminx.dom.DOMDocument; import org.eclipse.lemminx.dom.DOMParser; -import org.eclipse.lemminx.utils.XMLPositionUtility; import org.eclipse.lsp4j.Position; import org.junit.Assert; import org.junit.Test; diff --git a/pom.xml b/pom.xml index ce5e11eb5..5793d5cd1 100644 --- a/pom.xml +++ b/pom.xml @@ -18,13 +18,19 @@ - scm:git:git@github.com:angelozerr/lemminx.git + scm:git:git@github.com:eclipse/lemminx.git scm:git:git@github.com:eclipse/lemminx.git https://github.com/eclipse/lemminx org.eclipse.lemminx + + + cbi-release + https://repo.eclipse.org/content/repositories/cbi-releases/ + + @@ -178,12 +184,13 @@ eclipse-run + JavaSE-1.8 eclipse-4.10 p2 http://download.eclipse.org/eclipse/updates/4.10/R-4.10-201812060815/ - + From fc51c298ca1115e47442207524a47b5cf1b1d161 Mon Sep 17 00:00:00 2001 From: enxio Date: Mon, 9 Mar 2020 08:44:52 +0100 Subject: [PATCH 22/39] experimental --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4b9c18dee..5166bf1a4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,10 @@ -======= +*experimental* + +attempts to implement a different formatting strategy where not every tag is in a new line, but some are kept inline (see https://github.com/angelozerr/lsp4xml/issues/594). + +*experimental* + + **LemMinX** is a XML language specific implementation of the [Language Server Protocol](https://github.com/Microsoft/language-server-protocol) and can be used with any editor that supports the protocol, to offer good support for the **XML Language**. The server is based on: From 1b5b854805e1184f307a899b944cfc286adac288 Mon Sep 17 00:00:00 2001 From: enxio <31342498+enxio@users.noreply.github.com> Date: Mon, 9 Mar 2020 09:39:57 +0100 Subject: [PATCH 23/39] Format --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5166bf1a4..91000ac93 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,8 @@ -*experimental* +**experimental** +================ attempts to implement a different formatting strategy where not every tag is in a new line, but some are kept inline (see https://github.com/angelozerr/lsp4xml/issues/594). -*experimental* - - **LemMinX** is a XML language specific implementation of the [Language Server Protocol](https://github.com/Microsoft/language-server-protocol) and can be used with any editor that supports the protocol, to offer good support for the **XML Language**. The server is based on: From ba15a6e26f9273d75c5a36b45e9cc22efd6e8352 Mon Sep 17 00:00:00 2001 From: enxio <31342498+enxio@users.noreply.github.com> Date: Wed, 11 Mar 2020 13:37:39 +0100 Subject: [PATCH 24/39] pre-merge --- README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/README.md b/README.md index 48ec423e9..37a8dd003 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,3 @@ -**experimental** -================ - -attempts to implement a different formatting strategy where not every tag is in a new line, but some are kept inline (see https://github.com/angelozerr/lsp4xml/issues/594). - **LemMinX** is a XML language specific implementation of the [Language Server Protocol](https://github.com/Microsoft/language-server-protocol) and can be used with any editor that supports the protocol, to offer good support for the **XML Language**. The server is based on: From 3101d8fa8a92cc889ed3f031a1257b6c302ad194 Mon Sep 17 00:00:00 2001 From: enxio Date: Wed, 11 Mar 2020 13:41:42 +0100 Subject: [PATCH 25/39] merge --- Jenkinsfile | 2 +- README.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index e62c60072..31d1e8671 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -37,7 +37,7 @@ pipeline{ } steps { withMaven { - sh './mvnw deploy -B -Pci,generate-p2 -DskipTests' //don't clean to keep previous test results + sh './mvnw clean deploy -B -Pci,generate-p2 -DskipTests' } } } diff --git a/README.md b/README.md index 48ec423e9..c548ecfc1 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,10 @@ attempts to implement a different formatting strategy where not every tag is in a new line, but some are kept inline (see https://github.com/angelozerr/lsp4xml/issues/594). +XML Language Server (LemMinX) +=========================== +[![Build Status](https://ci.eclipse.org/lemminx/buildStatus/icon?job=lemminx%2Fmaster)](https://ci.eclipse.org/lemminx/job/lemminx/job/master/) + **LemMinX** is a XML language specific implementation of the [Language Server Protocol](https://github.com/Microsoft/language-server-protocol) and can be used with any editor that supports the protocol, to offer good support for the **XML Language**. The server is based on: From 7b9b7850fdd5ce61c51cdd2c734a50232bf16436 Mon Sep 17 00:00:00 2001 From: enxio Date: Thu, 16 Apr 2020 09:49:54 +0200 Subject: [PATCH 26/39] merge --- .../lemminx/commons/SnippetsBuilder.java | 20 ++++++- .../model/CMElementDeclaration.java | 8 +++ .../ContentModelCompletionParticipant.java | 46 ++++++++++++++- .../participants/DTDErrorCode.java | 2 +- .../contentmodel/utils/XMLGenerator.java | 37 +++++++++++- .../dtd/contentmodel/CMDTDDocument.java | 5 +- .../contentmodel/CMDTDElementDeclaration.java | 6 ++ .../xsd/contentmodel/CMXSDDocument.java | 2 +- .../contentmodel/CMXSDElementDeclaration.java | 17 +++++- .../eclipse/lemminx/utils/StringUtils.java | 33 +++++++---- .../contentmodel/DTDDiagnosticsTest.java | 2 +- .../XMLSchemaCompletionExtensionsTest.java | 56 ++++++++++++++++++- 12 files changed, 209 insertions(+), 25 deletions(-) diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/commons/SnippetsBuilder.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/commons/SnippetsBuilder.java index dcef5e042..1fdfe4c06 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/commons/SnippetsBuilder.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/commons/SnippetsBuilder.java @@ -46,9 +46,25 @@ public static void placeholders(int index, String text, StringBuilder snippets) } /** + * Returns the LSP choices snippets content. * - * @param index - * @param values + * @param index the snippet index. + * @param values the values for the choice. + * @return the LSP choices snippets content. + * + * @see https://github.com/Microsoft/language-server-protocol/blob/master/snippetSyntax.md#choice + */ + public static String choice(int index, Collection values) { + StringBuilder snippets = new StringBuilder(); + choice(index, values, snippets); + return snippets.toString(); + } + + /** + * Add LSP choices snippets in the given snippets content. + * + * @param index the snippet index. + * @param values the values for the choice. * @return * * @see https://github.com/Microsoft/language-server-protocol/blob/master/snippetSyntax.md#choice diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/model/CMElementDeclaration.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/model/CMElementDeclaration.java index bd9e78928..3fef55e48 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/model/CMElementDeclaration.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/model/CMElementDeclaration.java @@ -121,6 +121,14 @@ default String getName(String prefix) { */ Collection getEnumerationValues(); + /** + * Returns the documentation for the given enumeration value and null otherwise. + * + * @param value the enumeration value. + * @return the documentation for the given enumeration value and null otherwise. + */ + String getValueDocumentation(String value); + /** * Returns the owner document URI where the element is declared. * diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/participants/ContentModelCompletionParticipant.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/participants/ContentModelCompletionParticipant.java index 5125a546e..f88a924e9 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/participants/ContentModelCompletionParticipant.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/participants/ContentModelCompletionParticipant.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2018 Angelo ZERR + * Copyright (c) 2018-2020 Angelo ZERR * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v2.0 * which accompanies this distribution, and is available at @@ -13,6 +13,7 @@ package org.eclipse.lemminx.extensions.contentmodel.participants; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.Set; @@ -35,6 +36,7 @@ import org.eclipse.lsp4j.CompletionItemKind; import org.eclipse.lsp4j.InsertTextFormat; import org.eclipse.lsp4j.MarkupContent; +import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.Range; import org.eclipse.lsp4j.TextEdit; import org.w3c.dom.Document; @@ -334,4 +336,46 @@ private void fillAttributeValuesWithCMAttributeDeclarations(CMElementDeclaration } } + @Override + public void onXMLContent(ICompletionRequest request, ICompletionResponse response) throws Exception { + try { + ContentModelManager contentModelManager = request.getComponent(ContentModelManager.class); + DOMElement parentElement = request.getParentElement(); + if (parentElement != null) { + CMElementDeclaration elementDeclaration = contentModelManager.findCMElement(parentElement); + Collection values = elementDeclaration != null ? elementDeclaration.getEnumerationValues() + : Collections.emptyList(); + if (!values.isEmpty()) { + // Completion for xs:enumeration inside Element Text node + DOMDocument document = parentElement.getOwnerDocument(); + int startOffset = parentElement.getStartTagCloseOffset() + 1; + Position start = parentElement.getOwnerDocument().positionAt(startOffset); + Position end = request.getPosition(); + int endOffset = parentElement.getEndTagOpenOffset(); + if (endOffset > 0) { + end = document.positionAt(endOffset); + } + int completionOffset = request.getOffset(); + String tokenStart = StringUtils.getWhitespaces(document.getText(), startOffset, + completionOffset); + Range fullRange = new Range(start, end); + values.forEach(value -> { + CompletionItem item = new CompletionItem(); + item.setLabel(value); + String insertText = value; // request.getInsertAttrValue(value); + item.setLabel(value); + item.setKind(CompletionItemKind.Value); + item.setFilterText(tokenStart + insertText); + item.setTextEdit(new TextEdit(fullRange, insertText)); + MarkupContent documentation = XMLGenerator.createMarkupContent(elementDeclaration, value, + request); + item.setDocumentation(documentation); + response.addCompletionItem(item); + }); + } + } + } catch (CacheResourceDownloadingException e) { + // XML Schema, DTD is loading, ignore this error + } + } } \ No newline at end of file diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/participants/DTDErrorCode.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/participants/DTDErrorCode.java index 129da296b..657f2354f 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/participants/DTDErrorCode.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/participants/DTDErrorCode.java @@ -122,7 +122,7 @@ public static Range toLSPRange(XMLLocator location, DTDErrorCode code, Object[] return XMLPositionUtility.selectStartTagName(offset, document); } case MSG_ATTRIBUTE_NOT_DECLARED: { - return XMLPositionUtility.selectAttributeValueAt(getString(arguments[1]), offset, document); + return XMLPositionUtility.selectAttributeNameFromGivenNameAt(getString(arguments[1]), offset, document); } case MSG_FIXED_ATTVALUE_INVALID: { String attrName = getString(arguments[1]); diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/utils/XMLGenerator.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/utils/XMLGenerator.java index 4376108fc..3e454932c 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/utils/XMLGenerator.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/utils/XMLGenerator.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2018 Angelo ZERR + * Copyright (c) 2018-2020 Angelo ZERR * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v2.0 * which accompanies this distribution, and is available at @@ -21,8 +21,8 @@ import org.eclipse.lemminx.extensions.contentmodel.model.CMElementDeclaration; import org.eclipse.lemminx.settings.XMLFormattingOptions; import org.eclipse.lemminx.utils.MarkupContentFactory; -import org.eclipse.lemminx.utils.XMLBuilder; import org.eclipse.lemminx.utils.MarkupContentFactory.IMarkupKindSupport; +import org.eclipse.lemminx.utils.XMLBuilder; import org.eclipse.lsp4j.MarkupContent; import org.eclipse.lsp4j.MarkupKind; @@ -124,6 +124,20 @@ private int generate(CMElementDeclaration elementDeclaration, String prefix, int xml.selfCloseElement(); } else { xml.closeStartElement(); + Collection values = elementDeclaration.getEnumerationValues(); + if (!values.isEmpty()) { + // The Element Text node has xs:enumeration. + if (canSupportSnippets) { + // Generate LSP choice. + // Ex : ${1|Java,Node,XML|}$2$0" + snippetIndex++; + xml.addContent(SnippetsBuilder.choice(snippetIndex, values)); + } else { + // Generate the first item + // Ex : Java" + xml.addContent(values.iterator().next()); + } + } if (canSupportSnippets) { snippetIndex++; xml.addContent(SnippetsBuilder.tabstops(snippetIndex)); @@ -323,4 +337,23 @@ public static MarkupContent createMarkupContent(CMAttributeDeclaration cmAttribu } return null; } + + /** + * Returns a markup content for element text documentation and null otherwise. + * + * @param cmElement element declaration. + * @param textContent the text content. + * @param support markup kind support. + * + * @return a markup content for element text documentation and null otherwise. + */ + public static MarkupContent createMarkupContent(CMElementDeclaration cmElement, String textContent, + IMarkupKindSupport support) { + String documentation = XMLGenerator.generateDocumentation(cmElement.getValueDocumentation(textContent), + cmElement.getDocumentURI(), support.canSupportMarkupKind(MarkupKind.MARKDOWN)); + if (documentation != null) { + return MarkupContentFactory.createMarkupContent(documentation, MarkupKind.MARKDOWN, support); + } + return null; + } } diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/dtd/contentmodel/CMDTDDocument.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/dtd/contentmodel/CMDTDDocument.java index e11418371..50734b9e8 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/dtd/contentmodel/CMDTDDocument.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/dtd/contentmodel/CMDTDDocument.java @@ -160,8 +160,11 @@ public CMElementDeclaration findCMElement(DOMElement element, String namespace) } private CMElementDeclaration findElementDeclaration(String tag, String namespace) { + if (tag == null) { + return null; + } for (CMElementDeclaration cmElement : getElements()) { - if (cmElement.getName().equals(tag)) { + if (tag.equals(cmElement.getName())) { return cmElement; } } diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/dtd/contentmodel/CMDTDElementDeclaration.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/dtd/contentmodel/CMDTDElementDeclaration.java index 19b31d3da..0dd4bcc02 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/dtd/contentmodel/CMDTDElementDeclaration.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/dtd/contentmodel/CMDTDElementDeclaration.java @@ -14,6 +14,7 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -128,6 +129,11 @@ public boolean isEmpty() { @Override public Collection getEnumerationValues() { + return Collections.emptyList(); + } + + @Override + public String getValueDocumentation(String textContent) { return null; } diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xsd/contentmodel/CMXSDDocument.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xsd/contentmodel/CMXSDDocument.java index 61893b7fa..fdc1a68e4 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xsd/contentmodel/CMXSDDocument.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xsd/contentmodel/CMXSDDocument.java @@ -454,7 +454,7 @@ private static int getComplexTypeOffset(XSComplexTypeDefinition complexType, Sch // - fCTLocators array of locator // - fComplexTypeDecls array of XSComplexTypeDecl - // As it's not an API, we must use Java Reflection to get thoses 2 arrays + // As it's not an API, we must use Java Reflection to get those 2 arrays Field f = SchemaGrammar.class.getDeclaredField("fCTLocators"); f.setAccessible(true); SimpleLocator[] fCTLocators = (SimpleLocator[]) f.get(grammar); diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xsd/contentmodel/CMXSDElementDeclaration.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xsd/contentmodel/CMXSDElementDeclaration.java index a0171f6d2..2c9863201 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xsd/contentmodel/CMXSDElementDeclaration.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xsd/contentmodel/CMXSDElementDeclaration.java @@ -401,12 +401,24 @@ public boolean isEmpty() { @Override public Collection getEnumerationValues() { XSTypeDefinition typeDefinition = elementDeclaration.getTypeDefinition(); - if (typeDefinition != null && typeDefinition.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) { - return CMXSDDocument.getEnumerationValues((XSSimpleTypeDefinition) typeDefinition); + if (typeDefinition != null) { + XSSimpleTypeDefinition simpleDefinition = null; + if (typeDefinition.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) { + simpleDefinition = (XSSimpleTypeDefinition) typeDefinition; + } else if (typeDefinition.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) { + simpleDefinition = ((XSComplexTypeDefinition) typeDefinition).getSimpleType(); + } + return CMXSDDocument.getEnumerationValues(simpleDefinition); } return Collections.emptyList(); } + @Override + public String getValueDocumentation(String value) { + // FIXME: implement xsd:enumeration for Text node. + return null; + } + XSElementDeclaration getElementDeclaration() { return elementDeclaration; } @@ -416,5 +428,4 @@ public String getDocumentURI() { SchemaGrammar schemaGrammar = document.getOwnerSchemaGrammar(elementDeclaration); return CMXSDDocument.getSchemaURI(schemaGrammar); } - } diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/StringUtils.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/StringUtils.java index 4e94ced62..b56f34c66 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/StringUtils.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/StringUtils.java @@ -148,10 +148,21 @@ public static String normalizeSpace2(String str) { * @return the start whitespaces of the given line text. */ public static String getStartWhitespaces(String lineText) { + return getWhitespaces(lineText, 0, lineText.length()); + } + + /** + * Returns the whitespaces from the given range start/end of the given text. + * + * @param start the range start + * @param end the range end + * @param text the text + * @return the whitespaces from the given range start/end of the given text. + */ + public static String getWhitespaces(String text, int start, int end) { StringBuilder whitespaces = new StringBuilder(); - char[] chars = lineText.toCharArray(); - for (int i = 0; i < chars.length; i++) { - char c = chars[i]; + for (int i = start; i < end; i++) { + char c = text.charAt(i); if (Character.isWhitespace(c)) { whitespaces.append(c); } else { @@ -315,11 +326,10 @@ public static int getOffsetAfterWhitespace(String text, int endOffset) { } /** - * Returns the number of consecutive whitespace characters in front - * of text + * Returns the number of consecutive whitespace characters in front of text + * * @param text String of interest - * @return the number of consecutive whitespace characters in front - * of text + * @return the number of consecutive whitespace characters in front of text */ public static int getFrontWhitespaceLength(String text) { @@ -336,11 +346,10 @@ public static int getFrontWhitespaceLength(String text) { } /** - * Returns the number of consecutive whitespace characters from - * the end of text + * Returns the number of consecutive whitespace characters from the end of text + * * @param text String of interest - * @return the number of consecutive whitespace characters from - * the end of text + * @return the number of consecutive whitespace characters from the end of text */ public static int getTrailingWhitespaceLength(String text) { @@ -446,7 +455,7 @@ public static int findExprBeforeAt(String text, String expr, int offset) { } public static String getString(Object obj) { - if(obj != null) { + if (obj != null) { return obj.toString(); } return null; diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/DTDDiagnosticsTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/DTDDiagnosticsTest.java index c8f952a57..af41d4cef 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/DTDDiagnosticsTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/DTDDiagnosticsTest.java @@ -74,7 +74,7 @@ public void MSG_ATTRIBUTE_NOT_DECLARED() throws Exception { " Reminder\r\n" + // " Don't forget me this weekend\r\n" + // " "; - XMLAssert.testDiagnosticsFor(xml, d(10, 15, 17, DTDErrorCode.MSG_ATTRIBUTE_NOT_DECLARED)); + XMLAssert.testDiagnosticsFor(xml, d(10, 10, 14, DTDErrorCode.MSG_ATTRIBUTE_NOT_DECLARED)); } @Test diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSchemaCompletionExtensionsTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSchemaCompletionExtensionsTest.java index 5569de6fe..f25255aed 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSchemaCompletionExtensionsTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSchemaCompletionExtensionsTest.java @@ -13,6 +13,7 @@ package org.eclipse.lemminx.extensions.contentmodel; import static org.eclipse.lemminx.XMLAssert.c; +import static org.eclipse.lemminx.XMLAssert.r; import static org.eclipse.lemminx.XMLAssert.te; import java.io.IOException; @@ -220,7 +221,7 @@ public void noNamespaceSchemaLocationCompletion() throws BadLocationException { " <|"; // Completion only with Name XMLAssert.testCompletionFor(xml, null, "src/test/resources/Format.xml", 5 + 2 /* CDATA and Comments */, - c("OutOfBand", ""), c("ViewSelectedBy", ""), + c("OutOfBand", "false"), c("ViewSelectedBy", ""), c("End with ''", "/Configuration>"), c("End with ''", "/ViewDefinitions>"), c("End with ''", "/View>")); } @@ -275,6 +276,47 @@ public void completionOnAttributeValue2() throws BadLocationException { c("debit", "debit"), c("cash", "cash")); } + @Test + public void completionOnTextWithEnumeration() throws BadLocationException { + String xml = "\r\n" + + // + " \r\n" + // + " \r\n" + // + " |\r\n" + // + " "; + // Completion on skills Text node + // - without snippet + XMLAssert.testCompletionFor(xml, null, "src/test/resources/team.xml", null, + c("skill", "Java", r(3, 3, 3, 3), "skill")); + // - with snippet + testCompletionSnippetSupporytFor(xml, "src/test/resources/team.xml", null, + c("skill", "${1|Java,Node,XML|}$2$0", r(3, 3, 3, 3), "skill")); + + xml = "\r\n" + + // + " \r\n" + // + " \r\n" + // + " |\r\n" + // + " "; + // Completion on skill Text node + XMLAssert.testCompletionFor(xml, null, "src/test/resources/team.xml", null, // + c("Java", "Java", r(3, 10, 3, 10), "Java"), // + c("Node", "Node", r(3, 10, 3, 10), "Node"), // + c("XML", "XML", r(3, 10, 3, 10), "XML")); + + xml = "\r\n" + + // + " \r\n" + // + " \r\n" + // + " |\r\n" + // + " "; + // Completion on skill Text node + XMLAssert.testCompletionFor(xml, null, "src/test/resources/team.xml", null, // + c("Java", "Java", r(3, 10, 3, 11), " Java"), // + c("Node", "Node", r(3, 10, 3, 11), " Node"), // + c("XML", "XML", r(3, 10, 3, 11), " XML")); + } + @Test public void schemaLocationWithElementAndAttributeCompletion() throws BadLocationException { String xml = "\r\n" + // @@ -1019,4 +1061,16 @@ private void testCompletionMarkdownSupporytFor(String xml, CompletionItem... exp XMLAssert.testCompletionFor(new XMLLanguageService(), xml, "src/test/resources/catalogs/catalog.xml", null, null, null, completionSettings, expectedItems); } + + private void testCompletionSnippetSupporytFor(String xml, String fileURI, Integer expectedCount, + CompletionItem... expectedItems) throws BadLocationException { + XMLCompletionSettings completionSettings = new XMLCompletionSettings(); + CompletionCapabilities completionCapabilities = new CompletionCapabilities(); + CompletionItemCapabilities completionItem = new CompletionItemCapabilities(true); + completionItem.setDocumentationFormat(Arrays.asList(MarkupKind.MARKDOWN)); + completionCapabilities.setCompletionItem(completionItem); + completionSettings.setCapabilities(completionCapabilities); + XMLAssert.testCompletionFor(new XMLLanguageService(), xml, null, null, fileURI, null, completionSettings, + expectedItems); + } } \ No newline at end of file From 5558acda6c0afbc6564a40238c5d85a0cb9803b6 Mon Sep 17 00:00:00 2001 From: enxio Date: Tue, 21 Apr 2020 15:40:15 +0200 Subject: [PATCH 27/39] Merge --- .../org/eclipse/lemminx/dom/DOMElement.java | 22 + .../lemminx/services/XMLFormatter.java | 345 ++- .../settings/XMLFormattingOptions.java | 113 +- .../lemminx/services/XMLFormatterTest.java | 2598 ++++++++--------- 4 files changed, 1635 insertions(+), 1443 deletions(-) diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/dom/DOMElement.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/dom/DOMElement.java index 3fbe90e29..55196f5d9 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/dom/DOMElement.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/dom/DOMElement.java @@ -459,4 +459,26 @@ public void setIdAttributeNS(String arg0, String arg1, boolean arg2) throws DOME public void setIdAttributeNode(org.w3c.dom.Attr arg0, boolean arg1) throws DOMException { } + /** + * Returns true if the element is empty and false otherwise. + * + * @return true if the element is empty and false otherwise. + */ + public boolean isEmpty() { + if (!hasChildNodes()) { + return true; + } + for (DOMNode child : getChildren()) { + if (child.isText()) { + DOMText text = (DOMText) child; + if (!text.isWhitespace()) { + return false; + } + } else { + return false; + } + } + return true; + } + } diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java index 1a38b016b..1ec91d3c0 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java @@ -34,6 +34,7 @@ import org.eclipse.lemminx.dom.DTDDeclParameter; import org.eclipse.lemminx.services.extensions.XMLExtensionsRegistry; import org.eclipse.lemminx.settings.XMLFormattingOptions; +import org.eclipse.lemminx.settings.XMLFormattingOptions.EmptyElements; import org.eclipse.lemminx.utils.XMLBuilder; import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.Range; @@ -52,6 +53,7 @@ private static class XMLFormatterDocument { private final TextDocument textDocument; private final Range range; private final XMLFormattingOptions options; + private final EmptyElements emptyElements; private int startOffset; private int endOffset; @@ -67,11 +69,13 @@ public XMLFormatterDocument(TextDocument textDocument, Range range, XMLFormattin this.textDocument = textDocument; this.range = range; this.options = options; + this.emptyElements = options.getEmptyElements(); } /** - * Returns a List containing a single TextEdit, containing the newly formatted changes - * of this.textDocument + * Returns a List containing a single TextEdit, containing the newly formatted + * changes of this.textDocument + * * @return List containing a single TextEdit * @throws BadLocationException */ @@ -111,7 +115,8 @@ private void setupRangeFormatting(Range range) throws BadLocationException { if (containsTextWithinStartTag()) { adjustOffsetToStartTag(); rangeText = fullText.substring(this.startOffset, this.endOffset); - this.rangeDomDocument = DOMParser.getInstance().parse(rangeText, this.textDocument.getUri(), null, false); + this.rangeDomDocument = DOMParser.getInstance().parse(rangeText, this.textDocument.getUri(), null, + false); } this.xmlBuilder = new XMLBuilder(this.options, "", textDocument.lineDelimiter(startPosition.getLine())); @@ -355,139 +360,236 @@ private void format(DOMNode node) throws BadLocationException { } } } - // generate start element if (node.isElement()) { - DOMElement element = (DOMElement) node; - String tag = element.getTagName(); - if (element.hasEndTag() && !element.hasStartTag()) { - // bad element which have not start tag (ex: <\root>) - xmlBuilder.endElement(tag, element.isEndTagClosed()); + // Format Element + formatElement((DOMElement) node); + } else if (node.isCDATA()) { + // Format CDATA + formatCDATA((DOMCDATASection) node); + } else if (node.isComment()) { + // Format comment + formatComment((DOMComment) node); + } else if (node.isProcessingInstruction()) { + // Format processing instruction + formatProcessingInstruction(node); + } else if (node.isProlog()) { + // Format prolog + formatProlog(node); + } else if (node.isText()) { + // Format Text + formatText((DOMText) node); + } else if (node.isDoctype()) { + // Format document type + formatDocumentType((DOMDocumentType) node); + } + } else if (node.hasChildNodes()) { + // Other nodes kind like root + for (DOMNode child : node.getChildren()) { + format(child); + } + } + } + + /** + * Format the given DOM prolog + * + * @param node the DOM prolog to format. + */ + private void formatProlog(DOMNode node) { + addPrologToXMLBuilder(node, this.xmlBuilder); + this.xmlBuilder.linefeed(); + } + + /** + * Format the given DOM text node. + * + * @param textNode the DOM text node to format. + */ + private void formatText(DOMText textNode) { + // Generate content + String content = textNode.getData(); + xmlBuilder.addContent(content, textNode.isWhitespace(), textNode.hasSiblings(), textNode.getDelimiter(), + this.indentLevel); + } + + /** + * Format the given DOM document type. + * + * @param documentType the DOM document type to format. + */ + private void formatDocumentType(DOMDocumentType documentType) { + boolean isDTD = documentType.getOwnerDocument().isDTD(); + if (!isDTD) { + this.xmlBuilder.startDoctype(); + List params = documentType.getParameters(); + + for (DTDDeclParameter param : params) { + if (!documentType.isInternalSubset(param)) { + xmlBuilder.addParameter(param.getParameter()); } else { - xmlBuilder.startElement(tag, false); - if (element.hasAttributes()) { - // generate attributes - List attributes = element.getAttributeNodes(); - if (hasSingleAttributeInFullDoc(element)) { - DOMAttr singleAttribute = attributes.get(0); - xmlBuilder.addSingleAttribute(singleAttribute.getName(), - singleAttribute.getOriginalValue()); - } else { - for (DOMAttr attr : attributes) { - xmlBuilder.addAttribute(attr, this.indentLevel); - } - } - } + xmlBuilder.startDoctypeInternalSubset(); + xmlBuilder.linefeed(); + // level + 1 since the 'level' value is the doctype tag's level + formatDTD(documentType, this.indentLevel + 1, this.endOffset, this.xmlBuilder); + xmlBuilder.linefeed(); + xmlBuilder.endDoctypeInternalSubset(); + } + } + if (documentType.isClosed()) { + xmlBuilder.endDoctype(); + } + xmlBuilder.linefeed(); + } else { + formatDTD(documentType, 0, this.endOffset, this.xmlBuilder); + } + } + + /** + * Format the given DOM ProcessingIntsruction. + * + * @param element the DOM ProcessingIntsruction to format. + * + */ + private void formatProcessingInstruction(DOMNode node) { + addPIToXMLBuilder(node, this.xmlBuilder); + if (this.indentLevel == 0) { + this.xmlBuilder.linefeed(); + } + } + + /** + * Format the given DOM Comment + * + * @param element the DOM Comment to format. + * + */ + private void formatComment(DOMComment comment) { + this.xmlBuilder.startComment(comment); + this.xmlBuilder.addContentComment(comment.getData()); + this.xmlBuilder.endComment(); + if (this.indentLevel == 0) { + this.xmlBuilder.linefeed(); + } + } - if (element.isStartTagClosed()) { - xmlBuilder.closeStartElement(); + /** + * Format the given DOM CDATA + * + * @param element the DOM CDATA to format. + * + */ + private void formatCDATA(DOMCDATASection cdata) { + this.xmlBuilder.startCDATA(); + this.xmlBuilder.addContentCDATA(cdata.getData()); + this.xmlBuilder.endCDATA(); + } + + /** + * Format the given DOM element + * + * @param element the DOM element to format. + * + * @throws BadLocationException + */ + private void formatElement(DOMElement element) throws BadLocationException { + String tag = element.getTagName(); + if (element.hasEndTag() && !element.hasStartTag()) { + // bad element without start tag (ex: <\root>) + xmlBuilder.endElement(tag, element.isEndTagClosed()); + } else { + // generate start element + xmlBuilder.startElement(tag, false); + if (element.hasAttributes()) { + // generate attributes + List attributes = element.getAttributeNodes(); + if (hasSingleAttributeInFullDoc(element)) { + DOMAttr singleAttribute = attributes.get(0); + xmlBuilder.addSingleAttribute(singleAttribute.getName(), singleAttribute.getOriginalValue()); + } else { + for (DOMAttr attr : attributes) { + xmlBuilder.addAttribute(attr, this.indentLevel); } + } + } - boolean hasElements = false; - if (node.hasChildNodes()) { - // element has body + EmptyElements emptyElements = getEmptyElements(element); + switch (emptyElements) { + case expand: + // expand empty element: -> + xmlBuilder.closeStartElement(); + // end tag element is done, only if the element is closed + // the format, doesn't fix the close tag + this.xmlBuilder.endElement(tag, true); + break; + case collapse: + // collapse empty element: -> + this.xmlBuilder.selfCloseElement(); + break; + default: + if (element.isStartTagClosed()) { + xmlBuilder.closeStartElement(); + } + boolean hasElements = false; + if (element.hasChildNodes()) { + // element has body - this.indentLevel++; - //this.xmlBuilder.addContent("+>"); - for (DOMNode child : node.getChildren()) { - boolean textElement = !child.isText(); + this.indentLevel++; + for (DOMNode child : element.getChildren()) { + boolean textElement = !child.isText(); - hasElements = hasElements | textElement; + hasElements = hasElements | textElement; - format(child); - } - this.indentLevel--; - //this.xmlBuilder.addContent("<+"); + format(child); } - if (element.hasEndTag()) { - //this.xmlBuilder.addContent(""); - if (hasElements) { - //this.xmlBuilder.addContent("[trace-8]"); - if (!putTagInline(tag)) { - this.xmlBuilder.linefeed(); - this.xmlBuilder.indent(this.indentLevel); - } - } - // end tag element is done, only if the element is closed - // the format, doesn't fix the close tag - if (element.hasEndTag() && element.getEndTagOpenOffset() <= this.endOffset) { - //this.xmlBuilder.addContent("[trace-6b]"); - this.xmlBuilder.endElement(tag, element.isEndTagClosed()); - } else { - //this.xmlBuilder.addContent("[trace-6a]"); - this.xmlBuilder.selfCloseElement(); - } - //this.xmlBuilder.appendSpace(); - } else if (element.isSelfClosed()) { + this.indentLevel--; + } + if (element.hasEndTag()) { + if (hasElements) { + this.xmlBuilder.linefeed(); + this.xmlBuilder.indent(this.indentLevel); + } + // end tag element is done, only if the element is closed + // the format, doesn't fix the close tag + if (element.hasEndTag() && element.getEndTagOpenOffset() <= this.endOffset) { + this.xmlBuilder.endElement(tag, element.isEndTagClosed()); + } else { this.xmlBuilder.selfCloseElement(); - //this.xmlBuilder.addContent("[trace-7]"); } + } else if (element.isSelfClosed()) { + this.xmlBuilder.selfCloseElement(); } - return; + } + } + } - } else if (node.isCDATA()) { - DOMCDATASection cdata = (DOMCDATASection) node; - this.xmlBuilder.startCDATA(); - this.xmlBuilder.addContentCDATA(cdata.getData()); - this.xmlBuilder.endCDATA(); - } else if (node.isComment()) { - DOMComment comment = (DOMComment) node; - this.xmlBuilder.startComment(comment); - this.xmlBuilder.addContentComment(comment.getData()); - this.xmlBuilder.endComment(); - if (this.indentLevel == 0) { - this.xmlBuilder.linefeed(); - } - } else if (node.isProcessingInstruction()) { - addPIToXMLBuilder(node, this.xmlBuilder); - if (this.indentLevel == 0) { - this.xmlBuilder.linefeed(); - } - } else if (node.isProlog()) { - addPrologToXMLBuilder(node, this.xmlBuilder); - this.xmlBuilder.linefeed(); - } else if (node.isText()) { - DOMText textNode = (DOMText) node; - - // Generate content - String content = textNode.getData(); - //this.xmlBuilder.addContent("["+content+"]"); - this.xmlBuilder.addContent(content, textNode.isWhitespace(), textNode.hasSiblings(), - textNode.getDelimiter(), this.indentLevel); - return; - } else if (node.isDoctype()) { - boolean isDTD = node.getOwnerDocument().isDTD(); - DOMDocumentType documentType = (DOMDocumentType) node; - if (!isDTD) { - this.xmlBuilder.startDoctype(); - List params = documentType.getParameters(); - - for (DTDDeclParameter param : params) { - if (!documentType.isInternalSubset(param)) { - xmlBuilder.addParameter(param.getParameter()); - } else { - xmlBuilder.startDoctypeInternalSubset(); - xmlBuilder.linefeed(); - // level + 1 since the 'level' value is the doctype tag's level - formatDTD(documentType, this.indentLevel + 1, this.endOffset, this.xmlBuilder); - xmlBuilder.linefeed(); - xmlBuilder.endDoctypeInternalSubset(); + /** + * Return the option to use to generate empty elements. + * + * @param element the DOM element + * @return the option to use to generate empty elements. + */ + private EmptyElements getEmptyElements(DOMElement element) { + if (this.emptyElements != EmptyElements.ignore) { + if (element.isClosed() && element.isEmpty()) { + // Element is empty and closed + switch (this.emptyElements) { + case expand: + case collapse: { + if (this.options.isPreserveEmptyContent()) { + // preserve content + if (element.hasChildNodes()) { + // The element is empty and contains somes spaces which must be preserved + return EmptyElements.ignore; } } - if (documentType.isClosed()) { - xmlBuilder.endDoctype(); - } - xmlBuilder.linefeed(); - } else { - formatDTD(documentType, 0, this.endOffset, this.xmlBuilder); + return this.emptyElements; + } + default: + return this.emptyElements; } - return; - } - } else if (node.hasChildNodes()) { - // Other nodes kind like root - for (DOMNode child : node.getChildren()) { - format(child); } } + return EmptyElements.ignore; } private static boolean formatDTD(DOMDocumentType doctype, int level, int end, XMLBuilder xmlBuilder) { @@ -636,10 +738,11 @@ public XMLFormatter(XMLExtensionsRegistry extensionsRegistry) { } /** - * Returns a List containing a single TextEdit, containing the newly formatted changes - * of the document. + * Returns a List containing a single TextEdit, containing the newly formatted + * changes of the document. + * * @param textDocument document to perform formatting on - * @param range specified range in which formatting will be done + * @param range specified range in which formatting will be done * @return List containing a TextEdit with formatting changes */ public List format(TextDocument textDocument, Range range, diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/settings/XMLFormattingOptions.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/settings/XMLFormattingOptions.java index 17204da45..2090b2693 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/settings/XMLFormattingOptions.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/settings/XMLFormattingOptions.java @@ -23,9 +23,9 @@ * All defaults should be set here to eventually be overridden if needed. */ public class XMLFormattingOptions extends FormattingOptions { - + public static final String DEFAULT_QUOTATION = "\""; - + // All possible keys private static final String SPLIT_ATTRIBUTES = "splitAttributes"; private static final String JOIN_CDATA_LINES = "joinCDATALines"; @@ -40,18 +40,71 @@ public class XMLFormattingOptions extends FormattingOptions { // Values for QUOTATIONS public static final String DOUBLE_QUOTES_VALUE = "doubleQuotes"; public static final String SINGLE_QUOTES_VALUE = "singleQuotes"; + enum Quotations { doubleQuotes, singleQuotes - } + } + private static final String PRESERVE_EMPTY_CONTENT = "preserveEmptyContent"; + /** + * Options for formatting empty elements. + * + *
    + *
  • {@link #expand} : expand empty elements. With this option the following + * XML: + * + *
    +	 * {@code
    +	 * 
    +	 * }
    +	 * 
    + * + * will be formatted to : + * + *
    +	 * {@code
    +	 * 
    +	 * }
    +	 * 
    + * + *
  • + *
  • {@link #collapse} : collapse empty elements. With this option the + * following XML: + * + *
    +	 * {@code
    +	 * 
    +	 * }
    +	 * 
    + * + * will be formatted to : + * + *
    +	 * {@code
    +	 * 
    +	 * }
    +	 * 
    + * + *
  • + *
  • {@link #ignore} : keeps the original XML content for empty elements. + *
  • + *
+ * + */ + public static enum EmptyElements { + expand, collapse, ignore; + } + + private static final String EMPTY_ELEMENTS = "emptyElements"; + public XMLFormattingOptions() { this(false); } /** - * Create an XMLFormattingOptions instance with the option to initialize - * default values for all supported settings. + * Create an XMLFormattingOptions instance with the option to initialize default + * values for all supported settings. */ public XMLFormattingOptions(boolean initializeDefaults) { if (initializeDefaults) { @@ -59,8 +112,8 @@ public XMLFormattingOptions(boolean initializeDefaults) { } } - /** - * Necessary: Initialize default values in case client does not provide one + /** + * Necessary: Initialize default values in case client does not provide one */ public void initializeDefaultSettings() { this.setSplitAttributes(false); @@ -73,11 +126,12 @@ public void initializeDefaultSettings() { this.setQuotations(DOUBLE_QUOTES_VALUE); this.setPreserveEmptyContent(false); this.setPreservedNewlines(2); + this.setEmptyElement(EmptyElements.ignore); } public XMLFormattingOptions(int tabSize, boolean insertSpaces, boolean initializeDefaultSettings) { super(tabSize, insertSpaces); - if(initializeDefaultSettings) { + if (initializeDefaultSettings) { initializeDefaultSettings(); } } @@ -87,7 +141,7 @@ public XMLFormattingOptions(int tabSize, boolean insertSpaces) { } public XMLFormattingOptions(FormattingOptions options, boolean initializeDefaultSettings) { - if(initializeDefaultSettings) { + if (initializeDefaultSettings) { initializeDefaultSettings(); } merge(options); @@ -195,7 +249,8 @@ public void setQuotations(final String quotations) { /** * Returns the value of the format.quotations preference. * - * If invalid or null, the default is {@link XMLFormattingOptions#DOUBLE_QUOTES_VALUE}. + * If invalid or null, the default is + * {@link XMLFormattingOptions#DOUBLE_QUOTES_VALUE}. */ public String getQuotations() { final String value = this.getString(XMLFormattingOptions.QUOTATIONS); @@ -222,6 +277,7 @@ public String getQuotationAsString() { * If the quotations preference is a valid option. * * Keep up to date with new preferences. + * * @return */ private boolean isValidQuotations() { @@ -230,8 +286,10 @@ private boolean isValidQuotations() { } /** - * Checks if {@code quotation} equals the current value for {@code format.quotations}. - * @param quotation + * Checks if {@code quotation} equals the current value for + * {@code format.quotations}. + * + * @param quotation * @return */ public boolean isQuotations(String quotation) { @@ -239,8 +297,8 @@ public boolean isQuotations(String quotation) { return Objects.equals(value, quotation); } - public void setPreserveEmptyContent(final boolean spaceBeforeEmptyCloseTag) { - this.putBoolean(XMLFormattingOptions.PRESERVE_EMPTY_CONTENT, Boolean.valueOf(spaceBeforeEmptyCloseTag)); + public void setPreserveEmptyContent(final boolean preserveEmptyContent) { + this.putBoolean(XMLFormattingOptions.PRESERVE_EMPTY_CONTENT, Boolean.valueOf(preserveEmptyContent)); } public boolean isPreserveEmptyContent() { @@ -257,7 +315,7 @@ public void setPreservedNewlines(final int preservedNewlines) { } public int getPreservedNewlines() { - + final Number value = this.getNumber(XMLFormattingOptions.PRESERVED_NEWLINES); if ((value != null)) { return value.intValue(); @@ -266,17 +324,30 @@ public int getPreservedNewlines() { } } + public void setEmptyElement(EmptyElements emptyElement) { + this.putString(XMLFormattingOptions.EMPTY_ELEMENTS, emptyElement.name()); + } + + public EmptyElements getEmptyElements() { + String value = this.getString(XMLFormattingOptions.EMPTY_ELEMENTS); + if ((value != null)) { + try { + return EmptyElements.valueOf(value); + } catch (Exception e) { + } + } + return EmptyElements.ignore; + } + public XMLFormattingOptions merge(FormattingOptions formattingOptions) { formattingOptions.entrySet().stream().forEach(entry -> { String key = entry.getKey(); - if(!key.equals("tabSize") && !key.equals("insertSpaces")) { - this.put(entry.getKey(), entry.getValue()); - } - else { + if (!key.equals("tabSize") && !key.equals("insertSpaces")) { + this.put(entry.getKey(), entry.getValue()); + } else { this.putIfAbsent(entry.getKey(), entry.getValue()); } - } - ); + }); return this; } diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLFormatterTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLFormatterTest.java index f84a90352..29dab4cf7 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLFormatterTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLFormatterTest.java @@ -23,6 +23,7 @@ import org.eclipse.lemminx.dom.DOMDocument; import org.eclipse.lemminx.dom.DOMParser; import org.eclipse.lemminx.settings.XMLFormattingOptions; +import org.eclipse.lemminx.settings.XMLFormattingOptions.EmptyElements; import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.Range; import org.eclipse.lsp4j.TextEdit; @@ -71,20 +72,20 @@ public void singleEndTag() throws BadLocationException { String expected = ""; format(content, expected); } - + @Test public void endTagMissing() throws BadLocationException { - String content = "\r\n" + // + String content = "\r\n" + // " \r\n" + // - " \r\n" + // + " \r\n" + // ""; - String expected = "\r\n" + // + String expected = "\r\n" + // " \r\n" + // - " \r\n" + // + " \r\n" + // ""; format(content, expected); } - + @Test public void fullDocument() throws BadLocationException { String content = "
\n" + // @@ -122,177 +123,161 @@ public void range2() throws BadLocationException { @Test public void rangeChildrenFullSelection() throws BadLocationException { - String content = - "\n" + - " \n" + - " License Name\n" + - "| abcdefghijklmnop\n" + - " repo|\n" + - " \n" + - ""; - - String expected = - "\n" + - " \n" + - " License Name\n" + - " abcdefghijklmnop\n" + - " repo\n" + - " \n" + - ""; - + String content = "\n" + // + " \n" + // + " License Name\n" + // + "| abcdefghijklmnop\n" + // + " repo|\n" + // + " \n" + // + ""; + + String expected = "\n" + // + " \n" + // + " License Name\n" + // + " abcdefghijklmnop\n" + // + " repo\n" + // + " \n" + // + ""; + format(content, expected); } @Test public void rangeChildrenPartialSelection() throws BadLocationException { - String content = - "\n" + - " \n" + - " Licen|se Name\n" + - " abcdefghijklmnop\n" + - " repo|\n" + - " \n" + - ""; - - String expected = - "\n" + - " \n" + - " License Name\n" + - " abcdefghijklmnop\n" + - " repo\n" + - " \n" + - ""; - + String content = "\n" + // + " \n" + // + " Licen|se Name\n" + // + " abcdefghijklmnop\n" + // + " repo|\n" + // + " \n" + // + ""; + + String expected = "\n" + // + " \n" + // + " License Name\n" + // + " abcdefghijklmnop\n" + // + " repo\n" + // + " \n" + // + ""; + format(content, expected); } @Test public void rangeSelectAll() throws BadLocationException { - String content = - "\n" + - " \n" + - " License Name\n" + - " abcdefghijklmnop\n" + - " repo\n" + - " \n" + - " "; - - String expected = - "\n" + - " \n" + - " License Name\n" + - " abcdefghijklmnop\n" + - " repo\n" + - " \n" + - ""; - + String content = "\n" + // + " \n" + // + " License Name\n" + // + " abcdefghijklmnop\n" + // + " repo\n" + // + " \n" + // + " "; + + String expected = "\n" + // + " \n" + // + " License Name\n" + // + " abcdefghijklmnop\n" + // + " repo\n" + // + " \n" + // + ""; + format(content, expected); } @Test public void rangeSelectOnlyPartialStartTagAndChildren() throws BadLocationException { - String content = - "\n" + - " \n" + - " License Name\n" + - " abcdefghijklmnop\n" + - " repo|\n" + - " \n" + - ""; - - String expected = - "\n" + - " \n" + - " License Name\n" + - " abcdefghijklmnop\n" + - " repo\n" + - " \n" + - ""; - + String content = "\n" + // + " \n" + // + " License Name\n" + // + " abcdefghijklmnop\n" + // + " repo|\n" + // + " \n" + // + ""; + + String expected = "\n" + // + " \n" + // + " License Name\n" + // + " abcdefghijklmnop\n" + // + " repo\n" + // + " \n" + // + ""; + format(content, expected); } @Test public void rangeSelectOnlyFullStartTagAndChildren() throws BadLocationException { - String content = - "\n" + - " |\n" + - " License Name\n" + - " abcdefghijklmnop\n" + - " repo|\n" + - " \n" + - ""; - - String expected = - "\n" + - " \n" + - " License Name\n" + - " abcdefghijklmnop\n" + - " repo\n" + - " \n" + - ""; - + String content = "\n" + // + " |\n" + // + " License Name\n" + // + " abcdefghijklmnop\n" + // + " repo|\n" + // + " \n" + // + ""; + + String expected = "\n" + // + " \n" + // + " License Name\n" + // + " abcdefghijklmnop\n" + // + " repo\n" + // + " \n" + // + ""; + format(content, expected); } @Test public void rangeSelectOnlyPartialEndTagAndChildren() throws BadLocationException { - String content = - "\n" + - " \n" + - " License Name\n" + - " abcdefghijklmnop\n" + - " repo\n" + - " \n" + - ""; - - String expected = - "\n" + - " \n" + - " License Name\n" + - " abcdefghijklmnop\n" + - " repo\n" + - " \n" + - ""; - + String content = "\n" + // + " \n" + // + " License Name\n" + // + " abcdefghijklmnop\n" + // + " repo\n" + // + " \n" + // + ""; + + String expected = "\n" + // + " \n" + // + " License Name\n" + // + " abcdefghijklmnop\n" + // + " repo\n" + // + " \n" + // + ""; + format(content, expected); } @Test public void rangeSelectOnlyFullEndTagAndChildren() throws BadLocationException { - String content = - "\n" + - " \n" + - " License Name\n" + - " abcdefghijklmnop\n" + - " repo\n" + - " |\n" + - ""; - - String expected = - "\n" + - " \n" + - " License Name\n" + - " abcdefghijklmnop\n" + - " repo\n" + - " \n" + - ""; - + String content = "\n" + // + " \n" + // + " License Name\n" + // + " abcdefghijklmnop\n" + // + " repo\n" + // + " |\n" + // + ""; + + String expected = "\n" + // + " \n" + // + " License Name\n" + // + " abcdefghijklmnop\n" + // + " repo\n" + // + " \n" + // + ""; + format(content, expected); } - + @Test public void rangeSelectWithinText() throws BadLocationException { - String content = - "\n" + - " Lic|en|se\n" + - ""; - - String expected = - "\n" + - " License\n" + - ""; - + String content = "\n" + // + " Lic|en|se\n" + // + ""; + + String expected = "\n" + // + " License\n" + // + ""; + format(content, expected); } @@ -353,8 +338,7 @@ public void testPINoContent() throws BadLocationException { @Test public void testDefinedPIWithVariables() throws BadLocationException { String content = ""; - String expected = - "" + lineSeparator() + // + String expected = "" + lineSeparator() + // " " + lineSeparator() + // ""; format(content, expected); @@ -364,8 +348,7 @@ public void testDefinedPIWithVariables() throws BadLocationException { @Test public void testDefinedPIWithJustAttributeNames() throws BadLocationException { String content = ""; - String expected = - "" + lineSeparator() + // + String expected = "" + lineSeparator() + // " " + lineSeparator() + // ""; format(content, expected); @@ -374,8 +357,7 @@ public void testDefinedPIWithJustAttributeNames() throws BadLocationException { @Test public void testPIWithVariables() throws BadLocationException { String content = ""; - String expected = - "" + lineSeparator() + // + String expected = "" + lineSeparator() + // " " + lineSeparator() + // ""; format(content, expected); @@ -393,9 +375,7 @@ public void testSplitAttributesSingle() throws BadLocationException { @Test public void testSplitAttributes() throws BadLocationException { String content = ""; - String expected = - ""; XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setSplitAttributes(true); @@ -405,13 +385,12 @@ public void testSplitAttributes() throws BadLocationException { @Test public void testSplitAttributesNested() throws BadLocationException { String content = ""; - String expected = - "" + lineSeparator() + - " " + lineSeparator() + // + " " + lineSeparator() + + " bb=\"oo\">" + lineSeparator() + // ""; XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setSplitAttributes(true); @@ -421,9 +400,8 @@ public void testSplitAttributesNested() throws BadLocationException { @Test public void testNestedAttributesNoSplit() throws BadLocationException { String content = ""; - String expected = - "" + lineSeparator() + - " " + lineSeparator() + + String expected = "" + lineSeparator() + // + " " + lineSeparator() + // ""; XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setSplitAttributes(false); @@ -441,19 +419,17 @@ public void testSplitAttributesProlog() throws BadLocationException { @Test public void testSplitAttributesRangeOneLine() throws BadLocationException { - String content = - "\r\n" + - " sss\r\n" + - ""; + String content = "\r\n" + // + " sss\r\n" + // + ""; - String expected = - "\r\n" + - " sss\r\n" + - ""; + String expected = "\r\n" + // + " sss\r\n" + // + ""; XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setSplitAttributes(true); @@ -461,23 +437,22 @@ public void testSplitAttributesRangeOneLine() throws BadLocationException { } public void testSplitAttributesRangeMultipleLines() throws BadLocationException { - String content = - "\r\n" + - " sss\r\n" + - ""; - - String expected = - "\r\n" + - " sss\r\n" + - "";; + String content = "\r\n" + // + " sss\r\n" + // + ""; + + String expected = "\r\n" + // + " sss\r\n" + // + ""; + ; XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setSplitAttributes(true); @@ -486,16 +461,14 @@ public void testSplitAttributesRangeMultipleLines() throws BadLocationException @Test public void testUnclosedEndTagBracketTrailingElement() throws BadLocationException { - String content = - "" + lineSeparator() + - " content " + lineSeparator() + - ""; - String expected = - "" + lineSeparator() + - " content " + lineSeparator() + - ""; + String content = "" + lineSeparator() + // + " content " + lineSeparator() + // + ""; + String expected = "" + lineSeparator() + // + " content " + lineSeparator() + // + ""; format(content, expected); } @@ -519,8 +492,7 @@ public void testComment2() throws BadLocationException { @Test public void testCommentNested() throws BadLocationException { String content = ""; - String expected = - "" + lineSeparator() + // + String expected = "" + lineSeparator() + // " " + lineSeparator() + // ""; format(content, expected); @@ -540,28 +512,30 @@ public void testCommentNested2() throws BadLocationException { @Test public void testCommentMultiLineContent() throws BadLocationException { - String content = ""; + String content = ""; String expected = "" + lineSeparator() + // - " " + lineSeparator() + + " " + lineSeparator() + // ""; format(content, expected); } - @Test public void testJoinCDATALines() throws BadLocationException { - String content = - "" + lineSeparator() + - " "; - String expected = "" + lineSeparator() + " " + lineSeparator() + ""; + String content = "" + lineSeparator() + // + " "; + String expected = "" + lineSeparator() + // + " " + lineSeparator() + // + ""; XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setJoinCDATALines(true); format(content, expected, formattingOptions); @@ -569,13 +543,12 @@ public void testJoinCDATALines() throws BadLocationException { @Test public void testJoinCommentLines() throws BadLocationException { - String content = - ""; + String content = ""; String expected = "" + lineSeparator(); XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setJoinCommentLines(true); @@ -584,16 +557,14 @@ public void testJoinCommentLines() throws BadLocationException { @Test public void testUnclosedEndTagTrailingComment() throws BadLocationException { - String content = - "" + lineSeparator() + - " content " + lineSeparator() + - " "; - String expected = - "" + lineSeparator() + - " content " + lineSeparator() + - ""; + String content = "" + lineSeparator() + // + " content " + lineSeparator() + // + " "; + String expected = "" + lineSeparator() + // + " content " + lineSeparator() + // + ""; XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setJoinCommentLines(true); format(content, expected, formattingOptions); @@ -601,20 +572,18 @@ public void testUnclosedEndTagTrailingComment() throws BadLocationException { @Test public void testJoinCommentLinesNested() throws BadLocationException { - String content = - "" + lineSeparator() + - " " + lineSeparator() + - ""; - String expected = - "" + lineSeparator() + - " " + lineSeparator() + - ""; - + String content = "" + lineSeparator() + // + " " + lineSeparator() + // + ""; + String expected = "" + lineSeparator() + // + " " + lineSeparator() + // + ""; + XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setJoinCommentLines(true); format(content, expected, formattingOptions); @@ -622,15 +591,13 @@ public void testJoinCommentLinesNested() throws BadLocationException { @Test public void testCommentFormatSameLine() throws BadLocationException { - String content = - "" + lineSeparator() + - " Content" + lineSeparator() + - " "; - String expected = - "" + lineSeparator() + - " Content" + lineSeparator() + - " " + lineSeparator(); - + String content = "" + lineSeparator() + // + " Content" + lineSeparator() + // + " "; + String expected = "" + lineSeparator() + // + " Content" + lineSeparator() + // + " " + lineSeparator(); + XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setJoinCommentLines(true); format(content, expected, formattingOptions); @@ -638,79 +605,70 @@ public void testCommentFormatSameLine() throws BadLocationException { @Test public void testElementContentNotNormalized() throws BadLocationException { - String content = - "\r" + - " Content\r" + - " Content2\r" + - " Content3\r" + - " Content4\r" + - " Content5\r" + - ""; - String expected = - "\r" + - " Content\r" + - " Content2\r" + - " Content3\r" + - " Content4\r" + - " Content5\r" + - ""; - + String content = "\r" + // + " Content\r" + // + " Content2\r" + // + " Content3\r" + // + " Content4\r" + // + " Content5\r" + // + ""; + String expected = "\r" + // + " Content\r" + // + " Content2\r" + // + " Content3\r" + // + " Content4\r" + // + " Content5\r" + // + ""; + XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); format(content, expected, formattingOptions); } - @Test public void testContentFormatting2() throws BadLocationException { - String content = - "\r" + - " Content\r" + - " \r" + - " Content2\r" + - " Content3\r" + - " \r" + - ""; - String expected = - "\r" + - " Content\r" + - " \r" + - " Content2\r" + - " Content3\r" + - " \r" + - ""; - + String content = "\r" + // + " Content\r" + // + " \r" + // + " Content2\r" + // + " Content3\r" + // + " \r" + // + ""; + String expected = "\r" + // + " Content\r" + // + " \r" + // + " Content2\r" + // + " Content3\r" + // + " \r" + // + ""; + XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); format(content, expected, formattingOptions); } @Test public void testContentFormattingDontMoveEndTag() throws BadLocationException { - String content = - "\r" + - " Content\r" + - " \r" + - " Content2\r" + - " Content3 \r" + - ""; - String expected = - "\r" + - " Content\r" + - " \r" + - " Content2\r" + - " Content3 \r" + - ""; - + String content = "\r" + // + " Content\r" + // + " \r" + // + " Content2\r" + // + " Content3 \r" + // + ""; + String expected = "\r" + // + " Content\r" + // + " \r" + // + " Content2\r" + // + " Content3 \r" + // + ""; + XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); format(content, expected, formattingOptions); } @Test public void testContentFormatting3() throws BadLocationException { - String content = - " content "; - String expected = - " content "; - + String content = " content "; + String expected = " content "; + XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); format(content, expected, formattingOptions); } @@ -718,210 +676,193 @@ public void testContentFormatting3() throws BadLocationException { @Test public void testContentFormatting6() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - - String content = - "\r" + // + + String content = "\r" + // "\r" + // " Content\r" + // ""; - String expected = - "\r" + // + String expected = "\r" + // "\r" + // " Content\r" + // ""; format(content, expected, formattingOptions); - - content = - "\r\n" + // + + content = "\r\n" + // "\r\n" + // " Content\r\n" + // ""; - expected = - "\r\n" + // + expected = "\r\n" + // "\r\n" + // " Content\r\n" + // ""; format(content, expected, formattingOptions); } - @Test public void testSelfCloseTagSpace() throws BadLocationException { + @Test + public void testSelfCloseTagSpace() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setSpaceBeforeEmptyCloseTag(true); - - String content = - "\r" + // + + String content = "\r" + // " \r" + // ""; - String expected = - "\r" + // + String expected = "\r" + // " \r" + // ""; format(content, expected, formattingOptions); } - @Test public void testSelfCloseTagAlreadyHasSpace() throws BadLocationException { + @Test + public void testSelfCloseTagAlreadyHasSpace() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setSpaceBeforeEmptyCloseTag(true); - - String content = - "\r" + // + + String content = "\r" + // " \r" + // ""; - String expected = - "\r" + // + String expected = "\r" + // " \r" + // ""; format(content, expected, formattingOptions); } - @Test public void testSelfCloseTagSpaceFalse() throws BadLocationException { + @Test + public void testSelfCloseTagSpaceFalse() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setSpaceBeforeEmptyCloseTag(false); - - String content = - "\r" + // + + String content = "\r" + // " \r" + // ""; - String expected = - "\r" + // + String expected = "\r" + // " \r" + // ""; format(content, expected, formattingOptions); } - @Test public void testSelfCloseTagSpaceFalseAlreadyHasSpace() throws BadLocationException { + @Test + public void testSelfCloseTagSpaceFalseAlreadyHasSpace() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setSpaceBeforeEmptyCloseTag(false); - - String content = - "\r" + // + + String content = "\r" + // " \r" + // ""; - String expected = - "\r" + // + String expected = "\r" + // " \r" + // ""; format(content, expected, formattingOptions); } - - @Test public void testDontAddClosingBracket() throws BadLocationException { + @Test + public void testDontAddClosingBracket() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setSpaceBeforeEmptyCloseTag(false); - - String content = - "\r" + // + + String content = "\r" + // " "; - String expected = - "\r" + // + String expected = "\r" + // " "; format(content, expected, formattingOptions); } - @Test public void testEndTagMissingCloseBracket() throws BadLocationException { + @Test + public void testEndTagMissingCloseBracket() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setSpaceBeforeEmptyCloseTag(false); - - String content = - "\r" + // + + String content = "\r" + // " Value "; - String expected = - "\r" + // + String expected = "\r" + // " Value "; format(content, expected, formattingOptions); } - @Test public void testPreserveEmptyContentTag() throws BadLocationException { + @Test + public void testPreserveEmptyContentTag() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setPreserveEmptyContent(true); - - String content = - "\r" + // + + String content = "\r" + // " " + // ""; - String expected = - "\r" + // + String expected = "\r" + // " " + // ""; format(content, expected, formattingOptions); } - @Test public void testDontPreserveEmptyContentTag() throws BadLocationException { + @Test + public void testDontPreserveEmptyContentTag() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setPreserveEmptyContent(false); - - String content = - "\r" + // + + String content = "\r" + // " " + // ""; - String expected = - ""; + String expected = ""; format(content, expected, formattingOptions); } - @Test public void testPreserveTextContent() throws BadLocationException { + @Test + public void testPreserveTextContent() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setPreserveEmptyContent(true); - - String content = - "\r" + // + + String content = "\r" + // " aaa " + // ""; - String expected = - "\r" + // + String expected = "\r" + // " aaa " + // ""; format(content, expected, formattingOptions); } - @Test public void testPreserveTextContent2() throws BadLocationException { + @Test + public void testPreserveTextContent2() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setPreserveEmptyContent(false); - - String content = - "\r" + // + + String content = "\r" + // " aaa " + // ""; - String expected = - "\r" + // + String expected = "\r" + // " aaa " + // ""; format(content, expected, formattingOptions); } - @Test public void testPreserveEmptyContentTagWithSiblings() throws BadLocationException { + @Test + public void testPreserveEmptyContentTagWithSiblings() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setPreserveEmptyContent(true); - - String content = - "\r" + // + + String content = "\r" + // " " + // " " + // " " + // ""; - String expected = - "\r" + // + String expected = "\r" + // " \r" + // ""; format(content, expected, formattingOptions); } - @Test public void testPreserveEmptyContentTagWithSiblingContent() throws BadLocationException { + @Test + public void testPreserveEmptyContentTagWithSiblingContent() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setPreserveEmptyContent(true); - - String content = - "\r" + // + + String content = "\r" + // " zz " + // " tt" + // " " + // ""; - String expected = - "\r" + // + String expected = "\r" + // " zz\r" + // " \r" + // " tt\r" + // @@ -929,18 +870,17 @@ public void testContentFormatting6() throws BadLocationException { format(content, expected, formattingOptions); } - @Test public void testDontPreserveEmptyContentTagWithSiblingContent() throws BadLocationException { + @Test + public void testDontPreserveEmptyContentTagWithSiblingContent() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setPreserveEmptyContent(false); - - String content = - "\r" + // + + String content = "\r" + // " zz " + // " tt" + // " " + // ""; - String expected = - "\r" + // + String expected = "\r" + // " zz\r" + // " \r" + // " tt\r" + // @@ -948,18 +888,17 @@ public void testContentFormatting6() throws BadLocationException { format(content, expected, formattingOptions); } - @Test public void testPreserveEmptyContentTagWithSiblingWithComment() throws BadLocationException { + @Test + public void testPreserveEmptyContentTagWithSiblingWithComment() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setPreserveEmptyContent(true); - - String content = - "\r" + // + + String content = "\r" + // " zz " + // " tt " + // " " + // ""; - String expected = - "\r" + // + String expected = "\r" + // " zz\r" + // " \r" + // " tt \r" + // @@ -967,18 +906,17 @@ public void testContentFormatting6() throws BadLocationException { format(content, expected, formattingOptions); } - @Test public void testDontPreserveEmptyContentTagWithSiblingWithComment() throws BadLocationException { + @Test + public void testDontPreserveEmptyContentTagWithSiblingWithComment() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setPreserveEmptyContent(false); - - String content = - "\r" + // + + String content = "\r" + // " zz " + // " tt " + // " " + // ""; - String expected = - "\r" + // + String expected = "\r" + // " zz\r" + // " \r" + // " tt \r" + // @@ -986,102 +924,96 @@ public void testContentFormatting6() throws BadLocationException { format(content, expected, formattingOptions); } - @Test public void testPreserveEmptyContentWithJoinContentLines() throws BadLocationException { + @Test + public void testPreserveEmptyContentWithJoinContentLines() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setPreserveEmptyContent(true); formattingOptions.setJoinContentLines(true); - - String content = - "\n" + // + + String content = "\n" + // " zz \n" + // " zz \n" + // " \n" + // ""; - String expected = - "\n" + // + String expected = "\n" + // " zz zz\n" + // " \n" + // ""; format(content, expected, formattingOptions); } - @Test public void testJoinContentLinesTrue() throws BadLocationException { + @Test + public void testJoinContentLinesTrue() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setPreserveEmptyContent(false); formattingOptions.setJoinContentLines(true); - - String content = - "\n" + // + + String content = "\n" + // " zz \n" + // " zz " + // ""; - String expected = - "zz zz"; + String expected = "zz zz"; format(content, expected, formattingOptions); } - @Test public void testJoinContentLinesTrue2() throws BadLocationException { + @Test + public void testJoinContentLinesTrue2() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setPreserveEmptyContent(false); formattingOptions.setJoinContentLines(true); - - String content = - "zz zz zz"; - String expected = - "zz zz zz"; + + String content = "zz zz zz"; + String expected = "zz zz zz"; format(content, expected, formattingOptions); } - @Test public void testJoinContentLinesFalse() throws BadLocationException { + @Test + public void testJoinContentLinesFalse() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setPreserveEmptyContent(false); formattingOptions.setJoinContentLines(false); - - String content = - "\n" + // + + String content = "\n" + // " zz \n" + // " zz " + // ""; - String expected = - "\n" + // + String expected = "\n" + // " zz \n" + // " zz " + // ""; format(content, expected, formattingOptions); } - @Test public void testJoinContentLinesWithSiblingElementTrue() throws BadLocationException { + @Test + public void testJoinContentLinesWithSiblingElementTrue() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setPreserveEmptyContent(false); formattingOptions.setJoinContentLines(true); - - String content = - "\n" + // + + String content = "\n" + // " zz \n" + // " zz \n" + // " \n" + // ""; - String expected = - "\n" + // + String expected = "\n" + // " zz zz\n" + // " \n" + // ""; format(content, expected, formattingOptions); } - @Test public void testJoinContentLinesWithSiblingElementFalse() throws BadLocationException { + @Test + public void testJoinContentLinesWithSiblingElementFalse() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setPreserveEmptyContent(false); formattingOptions.setJoinContentLines(false); - - String content = - "\n" + // + + String content = "\n" + // " zz \n" + // " zz \n" + // " \n" + // ""; - String expected = - "\n" + // + String expected = "\n" + // " zz \n" + // " zz\n" + // " \n" + // @@ -1089,1146 +1021,1212 @@ public void testContentFormatting6() throws BadLocationException { format(content, expected, formattingOptions); } - @Test public void testEndTagMissingCloseBracket2() throws BadLocationException { + @Test + public void testEndTagMissingCloseBracket2() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setSpaceBeforeEmptyCloseTag(false); formattingOptions.setSplitAttributes(true); - - String content = - "\n" + - " \n" + - " sssi\n" + - " \n" + // + " \n" + // + " sssi\n" + // + " "; - String expected = - "\n" + - " \n" + - " sssi\n" + - " \n" + // + " \n" + // + " sssi\n" + // + " "; format(content, expected, formattingOptions); } - - @Test public void testDoctypeNoInternalSubset() throws BadLocationException { - XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - - String content = - "\r\n" + - "\r\n" + - " Fred\r\n" + - "\r\n" + - " Jani\r\n" + - "\r\n" + - " Reminder\r\n" + - " \r\n" + - " Don't forget me this weekend\r\n" + + + @Test + public void testDoctypeNoInternalSubset() throws BadLocationException { + XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); + + String content = "\r\n" + // + "\r\n" + // + " Fred\r\n" + // + "\r\n" + // + " Jani\r\n" + // + "\r\n" + // + " Reminder\r\n" + // + " \r\n" + // + " Don't forget me this weekend\r\n" + // ""; - String expected = - "\r\n" + - "\r\n" + - " Fred\r\n" + - "\r\n" + - " Jani\r\n" + - "\r\n" + - " Reminder\r\n" + - "\r\n" + - " Don't forget me this weekend\r\n" + + String expected = "\r\n" + // + "\r\n" + // + " Fred\r\n" + // + "\r\n" + // + " Jani\r\n" + // + "\r\n" + // + " Reminder\r\n" + // + "\r\n" + // + " Don't forget me this weekend\r\n" + // ""; format(content, expected, formattingOptions); } - @Test + @Test public void testDoctypeNoInternalSubsetNoNewlines() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setPreservedNewlines(0); - - String content = - "\r\n" + - "\r\n" + - " Fred\r\n" + - "\r\n" + - " Jani\r\n" + - "\r\n" + - " Reminder\r\n" + - " \r\n" + - " Don't forget me this weekend\r\n" + + + String content = "\r\n" + // + "\r\n" + // + " Fred\r\n" + // + "\r\n" + // + " Jani\r\n" + // + "\r\n" + // + " Reminder\r\n" + // + " \r\n" + // + " Don't forget me this weekend\r\n" + // ""; - String expected = - "\r\n" + - "\r\n" + - " Fred\r\n" + - " Jani\r\n" + - " Reminder\r\n" + - " Don't forget me this weekend\r\n" + + String expected = "\r\n" + // + "\r\n" + // + " Fred\r\n" + // + " Jani\r\n" + // + " Reminder\r\n" + // + " Don't forget me this weekend\r\n" + // ""; format(content, expected, formattingOptions); } - - @Test public void testDoctypeInternalSubset() throws BadLocationException { - XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - - String content = - "\r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - "]>\r\n" + - "\r\n" + - " Fred\r\n" + - "\r\n" + - "\r\n" + - " Jani\r\n" + - " \r\n" + - " Reminder\r\n" + - " Don't forget me this weekend\r\n" + + + @Test + public void testDoctypeInternalSubset() throws BadLocationException { + XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); + + String content = "\r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + "]>\r\n" + // + "\r\n" + // + " Fred\r\n" + // + "\r\n" + // + "\r\n" + // + " Jani\r\n" + // + " \r\n" + // + " Reminder\r\n" + // + " Don't forget me this weekend\r\n" + // ""; - String expected = - "\r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - "]>\r\n" + - "\r\n" + - " Fred\r\n" + - "\r\n" + - "\r\n" + - " Jani\r\n" + - "\r\n" + - " Reminder\r\n" + - " Don't forget me this weekend\r\n" + + String expected = "\r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + "]>\r\n" + // + "\r\n" + // + " Fred\r\n" + // + "\r\n" + // + "\r\n" + // + " Jani\r\n" + // + "\r\n" + // + " Reminder\r\n" + // + " Don't forget me this weekend\r\n" + // ""; format(content, expected, formattingOptions); } - @Test public void testDoctypeInternalSubsetNoNewlines() throws BadLocationException { + @Test + public void testDoctypeInternalSubsetNoNewlines() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setPreservedNewlines(0); - String content = - "\r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - "]>\r\n" + - "\r\n" + - " Fred\r\n" + - "\r\n" + - "\r\n" + - " Jani\r\n" + - " \r\n" + - " Reminder\r\n" + - " Don't forget me this weekend\r\n" + + String content = "\r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + "]>\r\n" + // + "\r\n" + // + " Fred\r\n" + // + "\r\n" + // + "\r\n" + // + " Jani\r\n" + // + " \r\n" + // + " Reminder\r\n" + // + " Don't forget me this weekend\r\n" + // ""; - String expected = - "\r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - "]>\r\n" + - "\r\n" + - " Fred\r\n" + - " Jani\r\n" + - " Reminder\r\n" + - " Don't forget me this weekend\r\n" + + String expected = "\r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + "]>\r\n" + // + "\r\n" + // + " Fred\r\n" + // + " Jani\r\n" + // + " Reminder\r\n" + // + " Don't forget me this weekend\r\n" + // ""; format(content, expected, formattingOptions); } - - @Test public void testDoctypeInternalDeclSpacesBetweenParameters() throws BadLocationException { - XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - - String content = - "\r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - "]>\r\n" + - "\r\n" + - " Fred\r\n" + - " Jani\r\n" + - " Reminder\r\n" + - " Don't forget me this weekend\r\n" + + + @Test + public void testDoctypeInternalDeclSpacesBetweenParameters() throws BadLocationException { + XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); + + String content = "\r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + "]>\r\n" + // + "\r\n" + // + " Fred\r\n" + // + " Jani\r\n" + // + " Reminder\r\n" + // + " Don't forget me this weekend\r\n" + // " "; - String expected = - "\r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - "]>\r\n" + - "\r\n" + - " Fred\r\n" + - " Jani\r\n" + - " Reminder\r\n" + - " Don't forget me this weekend\r\n" + + String expected = "\r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + "]>\r\n" + // + "\r\n" + // + " Fred\r\n" + // + " Jani\r\n" + // + " Reminder\r\n" + // + " Don't forget me this weekend\r\n" + // ""; format(content, expected, formattingOptions); } - - @Test public void testDoctypeInternalWithAttlist() throws BadLocationException { - XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - - String content = - "\r\n" + - "\r\n" + - " \r\n" + - "\r\n" + - " \r\n" + - "\r\n" + - "]>\r\n" + - "\r\n" + - "\r\n" + - " \r\n" + - " Fred\r\n" + + + @Test + public void testDoctypeInternalWithAttlist() throws BadLocationException { + XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); + + String content = "\r\n" + // + "\r\n" + // + " \r\n" + // + "\r\n" + // + " \r\n" + // + "\r\n" + // + "]>\r\n" + // + "\r\n" + // + "\r\n" + // + " \r\n" + // + " Fred\r\n" + // ""; - String expected = - "\r\n" + - " \r\n" + - " \r\n" + - "]>\r\n" + - "\r\n" + - "\r\n" + - "\r\n" + - " Fred\r\n" + + String expected = "\r\n" + // + " \r\n" + // + " \r\n" + // + "]>\r\n" + // + "\r\n" + // + "\r\n" + // + "\r\n" + // + " Fred\r\n" + // ""; format(content, expected, formattingOptions); } - - @Test public void testDoctypeInternalAllDecls() throws BadLocationException { - XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - - String content = - "\r\n" + - "\r\n" + - " \r\n" + - "\r\n" + - " \r\n" + - "\r\n" + - " \r\n" + - "]>\r\n" + + + @Test + public void testDoctypeInternalAllDecls() throws BadLocationException { + XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); + + String content = "\r\n" + // + "\r\n" + // + " \r\n" + // + "\r\n" + // + " \r\n" + // + "\r\n" + // + " \r\n" + // + "]>\r\n" + // ""; - String expected = - "\r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - "]>\r\n" + + String expected = "\r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + "]>\r\n" + // ""; format(content, expected, formattingOptions); } - - @Test public void testDoctypeInternalWithComments() throws BadLocationException { - XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - - String content = - "\r\n" + - "\r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - "]>\r\n" + + + @Test + public void testDoctypeInternalWithComments() throws BadLocationException { + XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); + + String content = "\r\n" + // + "\r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + "]>\r\n" + // ""; - String expected = - "\r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - "]>\r\n" + + String expected = "\r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + "]>\r\n" + // ""; format(content, expected, formattingOptions); } - - @Test public void testDoctypeInternalWithText() throws BadLocationException { - XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - - String content = - "\r\n" + - "\r\n" + - "\r\n" + - " garbageazg df\r\n" + - " gdf\r\n" + - "garbageazgdfg\r\n" + - " df\r\n" + - " gd\r\n" + - "\r\n" + - "\r\n" + - " \r\n" + - " \r\n" + - " \r\n" + + + @Test + public void testDoctypeInternalWithText() throws BadLocationException { + XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); + + String content = "\r\n" + // + "\r\n" + // + "\r\n" + // + " garbageazg df\r\n" + // + " gdf\r\n" + // + "garbageazgdfg\r\n" + // + " df\r\n" + // + " gd\r\n" + // + "\r\n" + // + "\r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // "]>"; - String expected = - "\r\n" + - " garbageazg df\r\n" + - " gdf\r\n" + - "garbageazgdfg\r\n" + - " df\r\n" + - " gd\r\n" + - " \r\n" + + String expected = "\r\n" + // + " garbageazg df\r\n" + // + " gdf\r\n" + // + "garbageazgdfg\r\n" + // + " df\r\n" + // + " gd\r\n" + // + " \r\n" + // "]>\r\n"; format(content, expected, formattingOptions); } - - @Test public void testDTDMultiParameterAttlist() throws BadLocationException { + + @Test + public void testDTDMultiParameterAttlist() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - - String content = - "\r\n"; - String expected = - ""; + String expected = ""; format(content, expected, formattingOptions, "test.dtd"); } - - @Test public void testDTDIndentation() throws BadLocationException { - XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - - String content = - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + + + @Test + public void testDTDIndentation() throws BadLocationException { + XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); + + String content = " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // " "; - String expected = - "\r\n" + - "\r\n" + - "\r\n" + + String expected = "\r\n" + // + "\r\n" + // + "\r\n" + // ""; format(content, expected, formattingOptions, "test.dtd"); } - - @Test public void testDTDNotEndBrackets() throws BadLocationException { + + @Test + public void testDTDNotEndBrackets() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - - String content = - "\r\n" + - "\r\n" + - "\r\n" + - " \r\n" + - "\r\n" + - " asdasd\r\n" + - " asd\r\n" + - "\r\n" + - "\r\n" + - "\r\n" + + + @Test + public void testDTDUnknownDeclNameAndText() throws BadLocationException { + XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); + + String content = "\r\n" + // + "\r\n" + // + "\r\n" + // + " \r\n" + // + "\r\n" + // + " asdasd\r\n" + // + " asd\r\n" + // + "\r\n" + // + "\r\n" + // + "\r\n" + // ""; - String expected = - "\r\n" + - "\r\n" + - "asdasd\r\n" + - " asd\r\n" + - "\r\n" + - "\r\n" + + String expected = "\r\n" + // + "\r\n" + // + "asdasd\r\n" + // + " asd\r\n" + // + "\r\n" + // + "\r\n" + // ""; format(content, expected, formattingOptions, "test.dtd"); } - - @Test + + @Test public void testAllDoctypeParameters() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - - String content = - "\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" + - " sdsd\r\n" + - "\r\n" + - " \r\n" + - " \r\n" + - " er\r\n" + - " dd\r\n" + - " \r\n" + + + String content = "\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" + // + " sdsd\r\n" + // + "\r\n" + // + " \r\n" + // + " \r\n" + // + " er\r\n" + // + " dd\r\n" + // + " \r\n" + // ""; - String expected = - "\r\n" + - "\r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - "]>\r\n" + - "\r\n" + - " sdsd\r\n" + - "\r\n" + - " \r\n" + - "\r\n" + - " er\r\n" + - " dd\r\n" + - " \r\n" + + String expected = "\r\n" + // + "\r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + "]>\r\n" + // + "\r\n" + // + " sdsd\r\n" + // + "\r\n" + // + " \r\n" + // + "\r\n" + // + " er\r\n" + // + " dd\r\n" + // + " \r\n" + // ""; format(content, expected, formattingOptions); } - - @Test public void testDTDElementContentWithAsterisk() throws BadLocationException { + + @Test + public void testDTDElementContentWithAsterisk() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - - String content = - ""; - String expected = - ""; + + String content = ""; + String expected = ""; format(content, expected, formattingOptions, "test.dtd", false); } - - @Test public void testDoctypeSingleLineFormat() throws BadLocationException { + + @Test + public void testDoctypeSingleLineFormat() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - - String content = - "]>\r\n" + + + String content = "]>\r\n" + // ""; - String expected = - "\r\n" + - " \r\n" + - "]>\r\n" + + String expected = "\r\n" + // + " \r\n" + // + "]>\r\n" + // ""; format(content, expected, formattingOptions); } - - @Test public void testDoctypeInvalidParameter() throws BadLocationException { + + @Test + public void testDoctypeInvalidParameter() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - - String content = - "\r\n" + - " \r\n" + + + String content = "\r\n" + // + " \r\n" + // "]>"; - String expected = - "\r\n" + - " \r\n" + + String expected = "\r\n" + // + " \r\n" + // "]>\r\n"; format(content, expected, formattingOptions); } - - @Test public void testDoctypeInvalidParameterUnclosed() throws BadLocationException { + + @Test + public void testDoctypeInvalidParameterUnclosed() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - - String content = - "\r\n" + - " \r\n" + - "]\r\n" + - "\r\n" + - "\r\n" + + + String content = "\r\n" + // + " \r\n" + // + "]\r\n" + // + "\r\n" + // + "\r\n" + // ""; - String expected = - "\r\n" + - " \r\n" + - "]\r\n" + + String expected = "\r\n" + // + " \r\n" + // + "]\r\n" + // ""; format(content, expected, formattingOptions); } - - @Test + + @Test public void testUnclosedSystemId() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - - String content = - "\r\n" + - "\r\n" + - " \r\n" + - "]>\r\n" + - "\r\n" + + + String content = "\r\n" + // + "\r\n" + // + " \r\n" + // + "]>\r\n" + // + "\r\n" + // ""; - String expected = - "\r\n" + - "\r\n" + - " \r\n" + - "]>\r\n" + - "\r\n" + + String expected = "\r\n" + // + "\r\n" + // + " \r\n" + // + "]>\r\n" + // + "\r\n" + // ""; format(content, expected, formattingOptions); } - - @Test + + @Test public void testUnclosedPublicId() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - - String content = - "\r\n" + - "\r\n" + - " \r\n" + - "]>\r\n" + - "\r\n" + + + String content = "\r\n" + // + "\r\n" + // + " \r\n" + // + "]>\r\n" + // + "\r\n" + // ""; - String expected = - "\r\n" + - "\r\n" + - " \r\n" + - "]>\r\n" + - "\r\n" + + String expected = "\r\n" + // + "\r\n" + // + " \r\n" + // + "]>\r\n" + // + "\r\n" + // ""; format(content, expected, formattingOptions); } - - @Test + + @Test public void testCommentAfterMissingClosingBracket() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - - String content = - "\r\n" + - "]>\r\n" + - "\r\n" + + + String content = "\r\n" + // + "]>\r\n" + // + "\r\n" + // ""; - String expected = - "\r\n" + - "]>\r\n" + - "\r\n" + + String expected = "\r\n" + // + "]>\r\n" + // + "\r\n" + // ""; format(content, expected, formattingOptions); } - @Test + @Test public void testHTMLDTD() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - - String content = - "\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" + + + String content = "\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" + // "%HTML4.dtd;"; - String expected = - "\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" + + String expected = "\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" + // "%HTML4.dtd;"; format(content, expected, formattingOptions, "test.dtd"); } - - @Test + + @Test public void testXMLInDTDFile() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - - String content = - "\r\n" + - "\r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + + + String content = "\r\n" + // + "\r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // ""; - String expected = - "\r\n" + - "\r\n" + - "\r\n" + - "\r\n" + - "\r\n" + - "\r\n" + + String expected = "\r\n" + // + "\r\n" + // + "\r\n" + // + "\r\n" + // + "\r\n" + // + "\r\n" + // ""; format(content, expected, formattingOptions, "test.dtd"); } - - @Test + + @Test public void testBadDTDFile() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - - String content = - "\r\n" + - "\r\n" + - "]]>\r\n" + - "\r\n" + + + String content = "\r\n" + // + "\r\n" + // + "]]>\r\n" + // + "\r\n" + // ""; - String expected = - "\r\n" + - "]]>\r\n" + + String expected = "\r\n" + // + "]]>\r\n" + // ""; format(content, expected, formattingOptions, "test.dtd"); } - - @Test + + @Test public void testIncompleteAttlistInternalDecl() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - - String content = - "\r\n" + - "\r\n" + + + String content = "\r\n" + // + "\r\n" + // ""; - String expected = - "\r\n" + + String expected = "\r\n" + // ""; format(content, expected, formattingOptions, "test.dtd"); } - @Test + @Test public void testUseDoubleQuotesFromDoubleQuotes() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setQuotations(XMLFormattingOptions.DOUBLE_QUOTES_VALUE); - - String content = - " "; - String expected = - ""; + + String content = " "; + String expected = ""; format(content, expected, formattingOptions); } - @Test + @Test public void testUseInvalidValueFromDoubleQuotes() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setQuotations("INVALID_VALUE"); - - String content = - " "; - String expected = - ""; + + String content = " "; + String expected = ""; format(content, expected, formattingOptions); } - @Test + @Test public void testUseSingleQuotesFromSingleQuotes() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setQuotations(XMLFormattingOptions.SINGLE_QUOTES_VALUE); - String content = - " "; - String expected = - ""; + String content = " "; + String expected = ""; format(content, expected, formattingOptions); } - @Test + @Test public void testUseSingleQuotesFromDoubleQuotes() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setQuotations(XMLFormattingOptions.SINGLE_QUOTES_VALUE); - - String content = - " "; - String expected = - ""; + + String content = " "; + String expected = ""; format(content, expected, formattingOptions); } - @Test + @Test public void testUseDoubleQuotesFromSingleQuotes() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - - String content = - " "; - String expected = - ""; + + String content = " "; + String expected = ""; format(content, expected, formattingOptions); } - @Test + @Test public void testUseSingleQuotesNoQuotes() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setQuotations(XMLFormattingOptions.SINGLE_QUOTES_VALUE); - String content = - " "; - String expected = - ""; + String content = " "; + String expected = ""; format(content, expected, formattingOptions); } - @Test + @Test public void testUseSingleQuotesNoQuotesSplit() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setQuotations(XMLFormattingOptions.SINGLE_QUOTES_VALUE); formattingOptions.setSplitAttributes(true); - String content = - " "; - String expected = - ""; + String content = " "; + String expected = ""; format(content, expected, formattingOptions); } - @Test + @Test public void testAttValueOnlyStartQuote() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setQuotations(XMLFormattingOptions.SINGLE_QUOTES_VALUE); - String content = - " "; - String expected = - " "; + String content = " "; + String expected = " "; format(content, expected, formattingOptions); } - @Test + @Test public void testUseDoubleQuotesMultipleAttributes() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - - String content = - " "; - String expected = - ""; + + String content = " "; + String expected = ""; format(content, expected, formattingOptions); } - @Test + @Test public void testUseSingleQuotesMultipleAttributes() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setQuotations(XMLFormattingOptions.SINGLE_QUOTES_VALUE); - String content = - " "; - String expected = - ""; + String content = " "; + String expected = ""; format(content, expected, formattingOptions); } - @Test + @Test public void testUseDoubleQuotesMultipleAttributesSplit() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setSplitAttributes(true); - - String content = - " \n"; - String expected = - ""; + + String content = " \n"; + String expected = ""; format(content, expected, formattingOptions); } - @Test + @Test public void testUseSingleQuotesMultipleAttributesSplit() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setSplitAttributes(true); formattingOptions.setQuotations(XMLFormattingOptions.SINGLE_QUOTES_VALUE); - String content = - " \n"; - String expected = - ""; + String content = " \n"; + String expected = ""; format(content, expected, formattingOptions); } - @Test + @Test public void testAttributeNameTouchingPreviousValue() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setQuotations(XMLFormattingOptions.SINGLE_QUOTES_VALUE); formattingOptions.setSplitAttributes(true); - - String content = - "\r\n" + - " \r\n" + + + String content = "\r\n" + // + " \r\n" + // ""; - String expected = - "\r\n" + - " \r\n" + + String expected = "\r\n" + // + " \r\n" + // ""; format(content, expected, formattingOptions); } @Test public void testAttributeNameValueTwoLines() throws BadLocationException { - String content = - "\r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - ""; - String expected = - "\r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - ""; + String content = "\r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + ""; + String expected = "\r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + ""; format(content, expected); } @Test public void testAttributeNameValueMultipleLines() throws BadLocationException { - String content = - "\r\n" + - " |\r\n" + - " \r\n" + - " \r\n" + - ""; - String expected = - "\r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - ""; + String content = "\r\n" + // + " |\r\n" + // + " \r\n" + // + " \r\n" + // + ""; + String expected = "\r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + ""; format(content, expected); } @Test public void testAttributeNameValueMultipleLinesWithChild() throws BadLocationException { - String content = - "\r\n" + - " |\r\n" + - " \r\n" + - ""; - String expected = - "\r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - ""; + String content = "\r\n" + // + " |\r\n" + // + " \r\n" + // + ""; + String expected = "\r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + ""; format(content, expected); } @Test public void testAttributeNameValueMultipleLinesWithChildrenSiblings() throws BadLocationException { - String content = - "\r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " |\r\n" + - ""; - String expected = - "\r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - ""; + String content = "\r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " |\r\n" + // + ""; + String expected = "\r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + ""; format(content, expected); } - - - @Test + @Test public void testPreserveNewlines() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - String content = - "\r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + + String content = "\r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // ""; - String expected = - "\r\n" + - " \r\n" + - "\r\n" + - "\r\n" + + String expected = "\r\n" + // + " \r\n" + // + "\r\n" + // + "\r\n" + // ""; format(content, expected, formattingOptions); } - @Test + @Test public void testPreserveNewlines3Max() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); formattingOptions.setPreservedNewlines(3); - String content = - "\r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + + String content = "\r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // ""; - String expected = - "\r\n" + - " \r\n" + - "\r\n" + - "\r\n" + - "\r\n" + + String expected = "\r\n" + // + " \r\n" + // + "\r\n" + // + "\r\n" + // + "\r\n" + // ""; format(content, expected, formattingOptions); } - @Test + @Test public void testPreserveNewlines2() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - String content = - "\r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + + String content = "\r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // ""; - String expected = - "\r\n" + - " \r\n" + - "\r\n" + - "\r\n" + + String expected = "\r\n" + // + " \r\n" + // + "\r\n" + // + "\r\n" + // ""; format(content, expected, formattingOptions); } - @Test + @Test public void testPreserveNewlinesBothSides() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - String content = - "\r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + + String content = "\r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // + " \r\n" + // ""; - String expected = - "\r\n" + - "\r\n" + - "\r\n" + - " \r\n" + - "\r\n" + - "\r\n" + + String expected = "\r\n" + // + "\r\n" + // + "\r\n" + // + " \r\n" + // + "\r\n" + // + "\r\n" + // ""; format(content, expected, formattingOptions); } - @Test + @Test public void testPreserveNewlinesBothSidesMultipleTags() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - String content = - "\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" + + String content = "\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" + // ""; - String expected = - "\r\n" + - "\r\n" + - "\r\n" + - " \r\n" + - "\r\n" + - "\r\n" + - " \r\n" + - "\r\n" + - "\r\n" + + String expected = "\r\n" + // + "\r\n" + // + "\r\n" + // + " \r\n" + // + "\r\n" + // + "\r\n" + // + " \r\n" + // + "\r\n" + // + "\r\n" + // ""; format(content, expected, formattingOptions); } - @Test + @Test public void testPreserveNewlinesSingleLine() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - String content = - "\r\n" + - " \r\n" + - " \r\n" + + String content = "\r\n" + // + " \r\n" + // + " \r\n" + // ""; - String expected = - "\r\n" + - " \r\n" + - "\r\n" + + String expected = "\r\n" + // + " \r\n" + // + "\r\n" + // ""; format(content, expected, formattingOptions); } - @Test + @Test public void testPreserveNewlines4() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - String content = - "\r\n" + - " \r\n" + + String content = "\r\n" + // + " \r\n" + // ""; - String expected = - "\r\n" + - " \r\n" + + String expected = "\r\n" + // + " \r\n" + // ""; format(content, expected, formattingOptions); } - @Test + @Test public void testNoSpacesOnNewLine() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - String content = - "\r\n" + - " \r\n" + - "\r\n" + - "\r\n" + - " \r\n" + - "\r\n" + - "\r\n" + - " \r\n" + - "\r\n" + - "\r\n" + - ""; - String expected = - "\r\n" + - " \r\n" + - "\r\n" + - "\r\n" + - ""; - format(content, expected, formattingOptions); - } - - - @Test + String content = "\r\n" + // + " \r\n" + // + "\r\n" + // + "\r\n" + // + " \r\n" + // + "\r\n" + // + "\r\n" + // + " \r\n" + // + "\r\n" + // + "\r\n" + // + ""; + String expected = "\r\n" + // + " \r\n" + // + "\r\n" + // + "\r\n" + // + ""; + format(content, expected, formattingOptions); + } + + // ------------ Tests with format empty elements settings + + @Test + public void expandEmptyElements() throws BadLocationException { + XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); + formattingOptions.setEmptyElement(EmptyElements.expand); + + String content = ""; + String expected = ""; + format(content, expected, formattingOptions); + + content = ""; + format(content, expected, formattingOptions); + } + + @Test + public void collapseEmptyElements() throws BadLocationException { + XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); + formattingOptions.setEmptyElement(EmptyElements.collapse); + + String content = ""; + String expected = ""; + format(content, expected, formattingOptions); + + content = "\r\n" + // + ""; + format(content, expected, formattingOptions); + + content = " "; + format(content, expected, formattingOptions); + + content = " X "; + expected = " X "; + format(content, expected, formattingOptions); + + content = " "; + expected = "" + lineSeparator() + // + " " + lineSeparator() + // + ""; + format(content, expected, formattingOptions); + } + + @Test + public void ignoreEmptyElements() throws BadLocationException { + XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); + formattingOptions.setEmptyElement(EmptyElements.ignore); + + String content = ""; + format(content, content, formattingOptions); + + content = ""; + format(content, content, formattingOptions); + } + + @Test + public void expandEmptyElementsAndPreserveEmptyContent() throws BadLocationException { + XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); + formattingOptions.setEmptyElement(EmptyElements.expand); + formattingOptions.setPreserveEmptyContent(true); + + String content = "\r\n" + // + " \r\n" + // + "\r\n" + // + "\r\n" + // + "\r\n" + // + "\r\n" + // + "\r\n" + // + " \r\n" + // + " \r\n" + // + ""; + String expected = "\r\n" + // + " \r\n" + // + "\r\n" + // + "\r\n" + // + "\r\n" + // + "\r\n" + // + "\r\n" + // + " \r\n" + // + " \r\n" + // + ""; + format(content, expected, formattingOptions); + + content = "\r\n" + // + " \r\n" + // + ""; + expected = "\r\n" + // + " \r\n" + // + ""; + format(content, expected, formattingOptions); + } + + @Test + public void collapseEmptyElementsAndPreserveEmptyContent() throws BadLocationException { + XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); + formattingOptions.setEmptyElement(EmptyElements.collapse); + formattingOptions.setPreserveEmptyContent(true); + + String content = "\r\n" + // + " \r\n" + // + "\r\n" + // + "\r\n" + // + "\r\n" + // + "\r\n" + // + "\r\n" + // + " \r\n" + // + " \r\n" + // + ""; + String expected = "\r\n" + // + " \r\n" + // + "\r\n" + // + "\r\n" + // + "\r\n" + // + "\r\n" + // + "\r\n" + // + " \r\n" + // + " \r\n" + // + ""; + format(content, expected, formattingOptions); + + content = "\r\n" + // + " \r\n" + // + ""; + expected = "\r\n" + // + " \r\n" + // + ""; + format(content, expected, formattingOptions); + } + + @Test + public void collapseEmptyElementsInRange() throws BadLocationException { + XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); + formattingOptions.setEmptyElement(EmptyElements.collapse); + + // Range doesn't cover the b element, collapse cannot be done + String content = "\r\n" + // + "<|b>\r\n" + // + " | \r\n" + // + "\r\n" + // + ""; + String expected = "\r\n" + // + " \r\n" + // + "\r\n" + // + ""; + format(content, expected, formattingOptions); + + // Range covers the b element, collapse is done + content = "\r\n" + // + "<|b>\r\n" + // + " \r\n" + // + "\r\n" + // + ""; + expected = "\r\n" + // + " \r\n" + // + ""; + format(content, expected, formattingOptions); + + } + + @Test public void testTemplate() throws BadLocationException { XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); - - String content = - ""; - String expected = - ""; + + String content = ""; + String expected = ""; format(content, expected, formattingOptions); } - - - //-------------------------Tools----------------------------------------- + // -------------------------Tools----------------------------------------- private static void format(String unformatted, String actual) throws BadLocationException { format(unformatted, actual, createDefaultFormattingOptions()); @@ -2238,15 +2236,15 @@ private static void format(String unformatted, String expected, XMLFormattingOpt throws BadLocationException { format(unformatted, expected, formattingOptions, "test://test.html"); } - + private static void format(String unformatted, String expected, XMLFormattingOptions formattingOptions, String uri) throws BadLocationException { format(unformatted, expected, formattingOptions, uri, true); } - private static void format(String unformatted, String expected, XMLFormattingOptions formattingOptions, String uri, Boolean considerRangeFormat) - throws BadLocationException { - + private static void format(String unformatted, String expected, XMLFormattingOptions formattingOptions, String uri, + Boolean considerRangeFormat) throws BadLocationException { + Range range = null; int rangeStart = considerRangeFormat ? unformatted.indexOf('|') : -1; int rangeEnd = considerRangeFormat ? unformatted.lastIndexOf('|') : -1; @@ -2263,7 +2261,7 @@ private static void format(String unformatted, String expected, XMLFormattingOpt TextDocument document = new TextDocument(unformatted, uri); XMLLanguageService languageService = new XMLLanguageService(); List edits = languageService.format(document, range, formattingOptions); - + String formatted = edits.stream().map(edit -> edit.getNewText()).collect(Collectors.joining("")); Range textEditRange = edits.get(0).getRange(); @@ -2274,12 +2272,10 @@ private static void format(String unformatted, String expected, XMLFormattingOpt formatted = unformatted.substring(0, textEditStartOffset) + formatted + unformatted.substring(textEditEndOffset - 1, unformatted.length()); } - + assertEquals(expected, formatted); } - - private static XMLFormattingOptions createDefaultFormattingOptions() { return new XMLFormattingOptions(2, true); } From 8d26ce01b6e35cb497a0ecfa7109441fdc0c527b Mon Sep 17 00:00:00 2001 From: enxio Date: Thu, 23 Apr 2020 08:18:39 +0200 Subject: [PATCH 28/39] update link to issue --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5f9708d6a..03ef25c88 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ **experimental** ================ -attempts to implement a different formatting strategy where not every tag is in a new line, but some are kept inline (see https://github.com/angelozerr/lsp4xml/issues/594). +attempts to implement a different formatting strategy where not every tag is in a new line, but some are kept inline (see https://github.com/eclipse/lemminx/issues/594). XML Language Server (LemMinX) =========================== From 2c247abfb105c692180d79fcd44a7670519d1e8b Mon Sep 17 00:00:00 2001 From: enxio Date: Wed, 29 Apr 2020 10:28:48 +0200 Subject: [PATCH 29/39] Fix --- .../src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java index 316c77410..9c8df56b6 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java @@ -237,7 +237,7 @@ public XMLBuilder addContent(String text) { return addContent(text, false, false, null); } - public XMLBuilder addContent(String text, Boolean isWhitespaceContent, Boolean hasSiblings, String delimiter, int level) { + public XMLBuilder addContent(String text, Boolean isWhitespaceContent, Boolean hasSiblings, String delimiter) { if (isWhitespaceContent) { // whoah: terriable, but this one seems to preserve single space. if (text.length() == 1) { From df3180b18e8707f674b011b554a17fa758a335f2 Mon Sep 17 00:00:00 2001 From: enxio Date: Tue, 12 May 2020 12:02:11 +0200 Subject: [PATCH 30/39] Fix formatting hiccup due to recent merge. --- .../main/java/org/eclipse/lemminx/services/XMLFormatter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java index 1d7037f0b..1aa77ff25 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java @@ -557,7 +557,7 @@ private void formatElement(DOMElement element) throws BadLocationException { this.indentLevel--; } if (element.hasEndTag()) { - if (hasElements) { + if (hasElements && !putTagInline(tag)) { this.xmlBuilder.linefeed(); this.xmlBuilder.indent(this.indentLevel); } From a7fb9d1e8a512c304ce66d7da927b042c5cb4086 Mon Sep 17 00:00:00 2001 From: enxio Date: Wed, 13 May 2020 16:05:56 +0200 Subject: [PATCH 31/39] organize imports and make usage of the static ones --- .../src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java index f1e3900c2..d8023cca0 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java @@ -253,7 +253,7 @@ public XMLBuilder addContent(String text, Boolean isWhitespaceContent, Boolean h if(isJoinContentLines()) { // ATSEC //xml.append("A:"); - text = StringUtils.normalizeSpace2(text); + text = normalizeSpace2(text); } else if(hasSiblings) { //xml.append("B:"); text = text.trim(); From 0f5eec8f2e6048b9d77c15722743e965d78634c5 Mon Sep 17 00:00:00 2001 From: enxio Date: Tue, 9 Jun 2020 08:24:10 +0200 Subject: [PATCH 32/39] Undo. --- .../main/java/org/eclipse/lemminx/services/XMLFormatter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java index b5d2b1ecc..413a5d408 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java @@ -320,7 +320,7 @@ private void format(DOMNode node) throws BadLocationException { // this.xmlBuilder.addContent("+SIBL+"); // } // } - doLineFeed = !node.getOwnerDocument().isDTD() && + doLineFeed = //!node.getOwnerDocument().isDTD() && !(node.isComment() && ((DOMComment) node).isCommentSameLineEndTag()) && ( !node.isText() || From 2202f4b089783d977b26a38dcf9a92916df57544 Mon Sep 17 00:00:00 2001 From: enxio Date: Mon, 20 Jul 2020 11:31:47 +0200 Subject: [PATCH 33/39] XXX: Trailing WS trim messed up formatting... Re-Check in next release. --- .../src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java index 4c9aaf94e..5087d5c4e 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java @@ -285,7 +285,8 @@ public XMLBuilder addContent(String text, Boolean isWhitespaceContent, Boolean h // xml.append("C:"); } if (isTrimTrailingWhitespace()) { - text = trimTrailingSpacesEachLine(text); + // XXX: Investigate, the setting shoud be false... + // text = trimTrailingSpacesEachLine(text); } //xml.append("-["+text+"]-"); xml.append(text); From ba6d789e994550a6ef480e18482de0cb15a602a3 Mon Sep 17 00:00:00 2001 From: enxio Date: Mon, 20 Jul 2020 11:47:32 +0200 Subject: [PATCH 34/39] typo --- .../src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java index 5087d5c4e..cddc0d623 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java @@ -285,7 +285,7 @@ public XMLBuilder addContent(String text, Boolean isWhitespaceContent, Boolean h // xml.append("C:"); } if (isTrimTrailingWhitespace()) { - // XXX: Investigate, the setting shoud be false... + // XXX: Investigate, the setting shoulÌd be false... // text = trimTrailingSpacesEachLine(text); } //xml.append("-["+text+"]-"); From 136199731bb6b2a85334208426f3917ad8aec160 Mon Sep 17 00:00:00 2001 From: enxio Date: Wed, 22 Jul 2020 15:09:10 +0200 Subject: [PATCH 35/39] added footnote to list of tags to be put in line --- .../eclipse/lemminx/services/XMLFormatter.java | 17 +++++++++-------- .../org/eclipse/lemminx/utils/XMLBuilder.java | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java index a9887534d..23475e2f5 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java @@ -175,6 +175,7 @@ private boolean putTagInline(String tag) { tag.equals("show-page")|| tag.equals("show-id")|| tag.equals("show-label")|| + tag.equals("footnote")|| tag.equals("show-title")); } @@ -578,11 +579,11 @@ private void formatElement(DOMElement element) throws BadLocationException { /** * Formats the start tag's closing bracket (>) according to * {@code XMLFormattingOptions#isPreserveAttrLineBreaks()} - * + * * {@code XMLFormattingOptions#isPreserveAttrLineBreaks()}: * If true, must add a newline + indent before the closing bracket if the last attribute of the element * and the closing bracket are in different lines. - * + * * @param element * @throws BadLocationException */ @@ -599,11 +600,11 @@ private void formatElementStartTagCloseBracket(DOMElement element) throws BadLoc /** * Formats the self-closing tag (/>) according to * {@code XMLFormattingOptions#isPreserveAttrLineBreaks()} - * + * * {@code XMLFormattingOptions#isPreserveAttrLineBreaks()}: * If true, must add a newline + indent before the self-closing tag if the last attribute of the element * and the closing bracket are in different lines. - * + * * @param element * @throws BadLocationException */ @@ -619,7 +620,7 @@ private void formatElementStartTagSelfCloseBracket(DOMElement element) throws Ba this.xmlBuilder.indent(this.indentLevel); } } - + this.xmlBuilder.selfCloseElement(); } @@ -645,10 +646,10 @@ private void formatAttributes(DOMElement element) throws BadLocationException { /** * Returns true if first offset and second offset belong * in the same line of the document - * + * * If current formatting is range formatting, the provided offsets * must be ranged offsets (offsets relative to the formatting range) - * + * * @param first the first offset * @param second the second offset * @return true if first offset and second offset belong @@ -679,7 +680,7 @@ private DOMAttr getLastAttribute(DOMElement element) { /** * Returns true if the provided element has one attribute * in the fullDomDocument (not the rangeDomDocument) - * + * * @param element * @return true if the provided element has one attribute * in the fullDomDocument (not the rangeDomDocument) diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java index cddc0d623..ee8602bbd 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java @@ -285,7 +285,7 @@ public XMLBuilder addContent(String text, Boolean isWhitespaceContent, Boolean h // xml.append("C:"); } if (isTrimTrailingWhitespace()) { - // XXX: Investigate, the setting shoulÌd be false... + // XXX: Investigate, the setting should be false by default... // text = trimTrailingSpacesEachLine(text); } //xml.append("-["+text+"]-"); From d8b553bcf7d00cf5eba1c63746bd6cdf5493340e Mon Sep 17 00:00:00 2001 From: enxio Date: Mon, 21 Sep 2020 16:56:24 +0200 Subject: [PATCH 36/39] Fix NPE in putTagInline(), a check for null was added. --- .../main/java/org/eclipse/lemminx/services/XMLFormatter.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java index b006e116b..373858bc6 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java @@ -159,6 +159,9 @@ private boolean containsTextWithinStartTag() { } // ATSEC private boolean putTagInline(String tag) { + if (tag == null) { + return false; + } return (tag.equals("b")|| tag.equals("bibref")|| tag.equals("color")|| From 0fb8a565306c8ca81eb5411e88e271c005e80fc5 Mon Sep 17 00:00:00 2001 From: enxio Date: Mon, 9 Nov 2020 13:49:00 +0100 Subject: [PATCH 37/39] Respect configuration "files.trimTrailingWhitespace". Setting this to true might mess up our formatting. --- .../src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java index cba2c8a1f..8af74034c 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java @@ -312,8 +312,7 @@ public XMLBuilder addContent(String text, Boolean isWhitespaceContent, Boolean h // xml.append("C:"); } if (isTrimTrailingWhitespace()) { - // XXX: Investigate, the setting should be false by default... - // text = trimTrailingSpacesEachLine(text); + text = trimTrailingSpacesEachLine(text); } //xml.append("-["+text+"]-"); xml.append(text); From 51ce0286b4743832564f368649c318f16965ce94 Mon Sep 17 00:00:00 2001 From: enxio Date: Thu, 12 Nov 2020 13:50:13 +0100 Subject: [PATCH 38/39] Make and is now formatted inline and o there is no linebreak before 0 && doLineFeed) { // add new line + indent if (!node.isChildOfOwnerDocument() || node.getPreviousNonTextSibling() != null) { From 4229ab23e62530eec37ad5d5b02585e1c7e60bcd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 3 Nov 2022 07:51:24 +0000 Subject: [PATCH 39/39] Bump maven-release-plugin from 3.0.0-M1 to 3.0.0-M7 Bumps [maven-release-plugin](https://github.com/apache/maven-release) from 3.0.0-M1 to 3.0.0-M7. - [Release notes](https://github.com/apache/maven-release/releases) - [Commits](https://github.com/apache/maven-release/compare/maven-release-3.0.0-M1...maven-release-3.0.0-M7) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-release-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f2967a518..cfae8a27f 100644 --- a/pom.xml +++ b/pom.xml @@ -185,7 +185,7 @@ org.apache.maven.plugins maven-release-plugin - 3.0.0-M6 + 3.0.0-M7 @{project.version} -DskipTests=true -Dcbi.jarsigner.skip=false -Pci,generate-p2