From a0f51a1dbc5ac6efb8eb661d98a9dc377ff4f467 Mon Sep 17 00:00:00 2001 From: Jessica He Date: Wed, 26 Jul 2023 11:33:33 -0400 Subject: [PATCH] Add alignWithFirstAttr option to xml.format.splitAttributes Signed-off-by: Jessica He --- .../participants/XSIFormatterParticipant.java | 14 +- .../format/DOMAttributeFormatter.java | 29 +++- .../services/format/DOMElementFormatter.java | 29 +++- .../DOMProcessingInstructionFormatter.java | 2 +- .../format/XMLFormatterDocumentOld.java | 3 +- .../settings/XMLFormattingOptions.java | 27 ++- .../org/eclipse/lemminx/utils/XMLBuilder.java | 9 +- .../xsi/XSIFormatterLegacyTest.java | 3 +- .../extensions/xsi/XSIFormatterTest.java | 159 +++++++++++++++++- .../format/XMLFormatterLegacyTest.java | 45 ++--- .../format/XMLFormatterWithRangeTest.java | 5 +- .../settings/XMLFormatterQuoteStyleTest.java | 9 +- .../XMLFormatterSplitAttributesTest.java | 82 +++++++-- .../XMLFormatterWhitespaceSettingTest.java | 53 +++++- .../format/wtp/XMLFormattingPreferences.java | 6 +- .../lemminx/settings/SettingsTest.java | 5 +- 16 files changed, 392 insertions(+), 88 deletions(-) diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xsi/participants/XSIFormatterParticipant.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xsi/participants/XSIFormatterParticipant.java index b9e27e4b7..ab75a3519 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xsi/participants/XSIFormatterParticipant.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xsi/participants/XSIFormatterParticipant.java @@ -22,6 +22,7 @@ import org.eclipse.lemminx.services.format.XMLFormatterDocument; import org.eclipse.lemminx.services.format.XMLFormattingConstraints; import org.eclipse.lemminx.settings.XMLFormattingOptions; +import org.eclipse.lemminx.settings.XMLFormattingOptions.SplitAttributes; import org.eclipse.lemminx.utils.StringUtils; import org.eclipse.lemminx.utils.XMLBuilder; import org.eclipse.lsp4j.TextEdit; @@ -188,9 +189,14 @@ public boolean formatAttributeValue(DOMAttr attr, XMLFormatterDocument formatter int indentSpaceOffset; int startOfLineOffset = formatterDocument.getLineAtOffset(attr.getOwnerElement().getStart()); - if (formattingOptions.isSplitAttributes()) { - indentSpaceOffset = (attrValueStart + 1) - attr.getNodeAttrName().getStart() - + formattingOptions.getSplitAttributesIndentSize() * tabSize; + if (formattingOptions.getSplitAttributes() != SplitAttributes.preserve) { + if (formattingOptions.getSplitAttributes() == SplitAttributes.splitNewLine) { + indentSpaceOffset = (attrValueStart + 1) - attr.getNodeAttrName().getStart() + + formattingOptions.getSplitAttributesIndentSize() * tabSize; + } else { + indentSpaceOffset = (attrValueStart + 1) - attr.getNodeAttrName().getStart() + + attr.getOwnerElement().getTagName().length() + 2; + } } else if (formattingOptions.isPreserveAttributeLineBreaks()) { indentSpaceOffset = attrValueStart - formatterDocument.getOffsetWithPreserveLineBreaks(startOfLineOffset, attrValueStart, tabSize, formattingOptions.isInsertSpaces()); @@ -212,7 +218,7 @@ public boolean formatAttributeValue(DOMAttr attr, XMLFormatterDocument formatter availableLineWidth -= i - lastAttrValueTermIndex; lastAttrValueTermIndex = i; if (availableLineWidth < 0 && formatterDocument.isMaxLineWidthSupported() - && !formattingOptions.isSplitAttributes()) { + && formattingOptions.getSplitAttributes() == SplitAttributes.preserve) { indentSpaceOffset = (attrValueStart + 1) - attr.getNodeAttrName().getStart() + (parentConstraints.getIndentLevel() + 1) * tabSize; } diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/DOMAttributeFormatter.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/DOMAttributeFormatter.java index 2f6e597f3..ef1b88e75 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/DOMAttributeFormatter.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/DOMAttributeFormatter.java @@ -14,7 +14,9 @@ import java.util.List; import org.eclipse.lemminx.dom.DOMAttr; +import org.eclipse.lemminx.dom.DOMElement; import org.eclipse.lemminx.settings.EnforceQuoteStyle; +import org.eclipse.lemminx.settings.XMLFormattingOptions.SplitAttributes; import org.eclipse.lemminx.utils.StringUtils; import org.eclipse.lsp4j.TextEdit; @@ -33,6 +35,7 @@ public DOMAttributeFormatter(XMLFormatterDocument formatterDocument) { } public void formatAttribute(DOMAttr attr, int prevOffset, boolean singleAttribute, boolean useSettings, + boolean isFirstAttr, XMLFormattingConstraints parentConstraints, List edits) { int indentLevel = parentConstraints.getIndentLevel(); // 1) format before attribute name : indent left of the attribute name @@ -44,10 +47,14 @@ public void formatAttribute(DOMAttr attr, int prevOffset, boolean singleAttribut if (isPreserveAttributeLineBreaks() && hasLineBreak(prevOffset, attr.getStart())) { replaceLeftSpacesWithIndentation(indentLevel + 1, prevOffset, attr.getStart(), true, edits); alreadyIndented = true; - } else if (isSplitAttributes() && !singleAttribute) { + } else if (getSplitAttributes() == SplitAttributes.splitNewLine && !singleAttribute) { replaceLeftSpacesWithIndentation(indentLevel + getSplitAttributesIndentSize(), prevOffset, attr.getStart(), true, edits); alreadyIndented = true; + } else if (getSplitAttributes() == SplitAttributes.alignWithFirstAttr && !isFirstAttr) { + replaceLeftSpacesWithIndentationWithOffsetSpaces(getFirstAttrOffset(attr.getOwnerElement(), indentLevel), prevOffset, + attr.getStart(), edits); + alreadyIndented = true; } } @@ -74,7 +81,7 @@ public void formatAttribute(DOMAttr attr, int prevOffset, boolean singleAttribut int availableLineWidth = parentConstraints.getAvailableLineWidth(); if (isPreserveAttributeLineBreaks() && hasLineBreak(prevOffset, attr.getStart())) { availableLineWidth = getMaxLineWidth() - getTabSize() * (indentLevel + 1); - } else if (isSplitAttributes() && !singleAttribute) { + } else if (getSplitAttributes() == SplitAttributes.splitNewLine && !singleAttribute) { availableLineWidth = getMaxLineWidth() - getTabSize() * (indentLevel + getSplitAttributesIndentSize()); } else { @@ -93,7 +100,7 @@ public void formatAttribute(DOMAttr attr, int prevOffset, boolean singleAttribut int from = prevOffset; int to = attr.getStart(); if (isMaxLineWidthSupported() && parentConstraints.getAvailableLineWidth() < 0 - && !isSplitAttributes()) { + && getSplitAttributes() == SplitAttributes.preserve) { replaceLeftSpacesWithIndentation(indentLevel + 1, from, to, true, edits); int attrValuelength = attr.getValue() != null ? attr.getValue().length() : 0; parentConstraints.setAvailableLineWidth( @@ -129,6 +136,13 @@ public void formatAttribute(DOMAttr attr, int prevOffset, boolean singleAttribut } } + private int getFirstAttrOffset(DOMElement ownerElement, int indentLevel) { + return getTabSize() * indentLevel + ownerElement.getTagName().length() + 2 /* + * +1 for '<', +1 for space between + * element name and first attr name + */; + } + private void formatAttributeValue(DOMAttr attr, XMLFormattingConstraints parentConstraints, List edits) { formatterDocument.formatAttributeValue(attr, parentConstraints, edits); } @@ -137,6 +151,11 @@ private void replaceQuoteWithPreferred(int from, int to, List edits) { formatterDocument.replaceQuoteWithPreferred(from, to, edits); } + private void replaceLeftSpacesWithIndentationWithOffsetSpaces(int spaceCount, int from, int to, + List edits) { + formatterDocument.replaceLeftSpacesWithIndentationWithOffsetSpaces(spaceCount, from, to, true, edits); + } + private void replaceLeftSpacesWithOneSpace(int from, int to, List edits) { formatterDocument.replaceLeftSpacesWithOneSpace(from, to, edits); } @@ -150,8 +169,8 @@ private void removeLeftSpaces(int from, int to, List edits) { formatterDocument.removeLeftSpaces(from, to, edits); } - private boolean isSplitAttributes() { - return formatterDocument.getSharedSettings().getFormattingSettings().isSplitAttributes(); + private SplitAttributes getSplitAttributes() { + return formatterDocument.getSharedSettings().getFormattingSettings().getSplitAttributes(); } private int getSplitAttributesIndentSize() { diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/DOMElementFormatter.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/DOMElementFormatter.java index 5b302a7d0..481899246 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/DOMElementFormatter.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/DOMElementFormatter.java @@ -19,6 +19,7 @@ import org.eclipse.lemminx.dom.DOMNode; import org.eclipse.lemminx.settings.SharedSettings; import org.eclipse.lemminx.settings.XMLFormattingOptions.EmptyElements; +import org.eclipse.lemminx.settings.XMLFormattingOptions.SplitAttributes; import org.eclipse.lemminx.utils.StringUtils; import org.eclipse.lsp4j.TextEdit; @@ -214,9 +215,12 @@ private int formatAttributes(DOMElement element, XMLFormattingConstraints parent // . int prevOffset = element.getOffsetAfterStartTag(); boolean singleAttribute = attributes.size() == 1; + boolean isFirstAttr = true; for (DOMAttr attr : attributes) { // Format current attribute - attributeFormatter.formatAttribute(attr, prevOffset, singleAttribute, true, parentConstraints, edits); + attributeFormatter.formatAttribute(attr, prevOffset, singleAttribute, true, isFirstAttr, + parentConstraints, edits); + isFirstAttr = false; // set the previous offset with end of the current attribute: // edits) { @@ -398,6 +408,11 @@ private void replaceLeftSpacesWithIndentationPreservedNewLines(int spaceStart, i edits); } + private void replaceLeftSpacesWithIndentationWithOffsetSpaces(int spaceCount, int from, int to, + List edits) { + formatterDocument.replaceLeftSpacesWithIndentationWithOffsetSpaces(spaceCount, from, to, true, edits); + } + private void removeLeftSpaces(int from, int to, List edits) { formatterDocument.removeLeftSpaces(from, to, edits); } @@ -439,8 +454,8 @@ private boolean isPreserveAttributeLineBreaks() { return formatterDocument.getSharedSettings().getFormattingSettings().isPreserveAttributeLineBreaks(); } - private boolean isSplitAttributes() { - return formatterDocument.getSharedSettings().getFormattingSettings().isSplitAttributes(); + private SplitAttributes getSplitAttributes() { + return formatterDocument.getSharedSettings().getFormattingSettings().getSplitAttributes(); } private int getSplitAttributesIndentSize() { diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/DOMProcessingInstructionFormatter.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/DOMProcessingInstructionFormatter.java index afcbf02da..98012bfe0 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/DOMProcessingInstructionFormatter.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/DOMProcessingInstructionFormatter.java @@ -57,7 +57,7 @@ public void formatProcessingInstruction(DOMProcessingInstruction processingInstr List attributes = processingInstruction.getAttributeNodes(); boolean singleAttribute = attributes.size() == 1; for (DOMAttr attr : attributes) { - attributeFormatter.formatAttribute(attr, prevOffset, singleAttribute, false, parentConstraints, edits); + attributeFormatter.formatAttribute(attr, prevOffset, singleAttribute, false, false, parentConstraints, edits); prevOffset = attr.getEnd(); } } diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/XMLFormatterDocumentOld.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/XMLFormatterDocumentOld.java index 8ecaa03ae..2bc44b5f7 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/XMLFormatterDocumentOld.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/XMLFormatterDocumentOld.java @@ -34,6 +34,7 @@ import org.eclipse.lemminx.services.extensions.format.IFormatterParticipant; import org.eclipse.lemminx.settings.SharedSettings; import org.eclipse.lemminx.settings.XMLFormattingOptions.EmptyElements; +import org.eclipse.lemminx.settings.XMLFormattingOptions.SplitAttributes; import org.eclipse.lemminx.utils.XMLBuilder; import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.Range; @@ -554,7 +555,7 @@ private void formatAttributes(DOMElement element) throws BadLocationException { prevOffset = attr.getEnd(); } if ((this.sharedSettings.getFormattingSettings().getClosingBracketNewLine() - && this.sharedSettings.getFormattingSettings().isSplitAttributes()) && !isSingleAttribute) { + && this.sharedSettings.getFormattingSettings().getSplitAttributes() == SplitAttributes.splitNewLine) && !isSingleAttribute) { xmlBuilder.linefeed(); // Indent by tag + splitAttributesIndentSize to match with attribute indent // level 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 b344fb9b8..e29de51b9 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 @@ -59,7 +59,11 @@ public class XMLFormattingOptions extends org.eclipse.lemminx.settings.LSPFormat private boolean legacy; private int maxLineWidth; - private boolean splitAttributes; + public static enum SplitAttributes { + preserve, splitNewLine, alignWithFirstAttr; + } + + private String splitAttributes; private boolean joinCDATALines; private boolean formatComments; private boolean joinCommentLines; @@ -150,7 +154,7 @@ private void initializeDefaultSettings() { super.setTabSize(DEFAULT_TAB_SIZE); super.setInsertSpaces(true); super.setTrimFinalNewlines(true); - this.setSplitAttributes(false); + this.setSplitAttributes(SplitAttributes.preserve); this.setJoinCDATALines(false); this.setFormatComments(true); this.setJoinCommentLines(false); @@ -193,12 +197,19 @@ public XMLFormattingOptions(FormattingOptions options) { this(options, true); } - public boolean isSplitAttributes() { - return splitAttributes; + public SplitAttributes getSplitAttributes() { + String value = splitAttributes; + if ((value != null)) { + try { + return SplitAttributes.valueOf(value); + } catch (Exception e) { + } + } + return SplitAttributes.preserve; } - public void setSplitAttributes(final boolean splitAttributes) { - this.splitAttributes = splitAttributes; + public void setSplitAttributes(SplitAttributes splitAttributes) { + this.splitAttributes = splitAttributes.name(); } public boolean isJoinCDATALines() { @@ -347,7 +358,7 @@ public void setPreserveAttributeLineBreaks(final boolean preserveAttributeLineBr * @return the value of preserveAttrLineBreaks */ public boolean isPreserveAttributeLineBreaks() { - if (this.isSplitAttributes()) { + if (this.getSplitAttributes() != SplitAttributes.preserve) { // splitAttributes overrides preserveAttrLineBreaks return false; } @@ -438,7 +449,7 @@ public XMLFormattingOptions merge(XMLFormattingOptions formattingOptions) { setTrimTrailingWhitespace(formattingOptions.isTrimTrailingWhitespace()); setLegacy(formattingOptions.isLegacy()); setMaxLineWidth(formattingOptions.getMaxLineWidth()); - setSplitAttributes(formattingOptions.isSplitAttributes()); + setSplitAttributes(formattingOptions.getSplitAttributes()); setJoinCDATALines(formattingOptions.isJoinCDATALines()); setFormatComments(formattingOptions.isFormatComments()); setJoinCommentLines(formattingOptions.isJoinCommentLines()); 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 7058244e9..1d2029e71 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 @@ -24,6 +24,7 @@ import org.eclipse.lemminx.services.extensions.format.IFormatterParticipant; import org.eclipse.lemminx.settings.EnforceQuoteStyle; import org.eclipse.lemminx.settings.SharedSettings; +import org.eclipse.lemminx.settings.XMLFormattingOptions.SplitAttributes; /** * XML content builder utilities. @@ -171,7 +172,7 @@ public XMLBuilder addPrologAttribute(DOMAttr attr) { * @return */ public XMLBuilder addAttribute(String name, String value, int level, boolean surroundWithQuotes) { - if (isSplitAttributes()) { + if (getSplitAttributes()== SplitAttributes.splitNewLine) { linefeed(); indent(level + sharedSettings.getFormattingSettings().getSplitAttributesIndentSize()); } else { @@ -187,7 +188,7 @@ public XMLBuilder addAttribute(DOMAttr attr, int level) { } private XMLBuilder addAttribute(DOMAttr attr, int level, boolean surroundWithQuotes) { - if (isSplitAttributes()) { + if (getSplitAttributes()== SplitAttributes.splitNewLine) { linefeed(); indent(level + sharedSettings.getFormattingSettings().getSplitAttributesIndentSize()); } else { @@ -529,8 +530,8 @@ private boolean isJoinCDATALines() { return sharedSettings.getFormattingSettings().isJoinCDATALines(); } - private boolean isSplitAttributes() { - return sharedSettings.getFormattingSettings().isSplitAttributes(); + private SplitAttributes getSplitAttributes() { + return sharedSettings.getFormattingSettings().getSplitAttributes(); } private boolean isInsertSpaces() { diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/xsi/XSIFormatterLegacyTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/xsi/XSIFormatterLegacyTest.java index 851dc9f8e..14e2bae26 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/xsi/XSIFormatterLegacyTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/xsi/XSIFormatterLegacyTest.java @@ -18,6 +18,7 @@ import org.eclipse.lemminx.commons.BadLocationException; import org.eclipse.lemminx.extensions.xsi.settings.XSISchemaLocationSplit; import org.eclipse.lemminx.settings.SharedSettings; +import org.eclipse.lemminx.settings.XMLFormattingOptions.SplitAttributes; import org.junit.jupiter.api.Test; /** @@ -180,7 +181,7 @@ private static SharedSettings createSettings() { SharedSettings settings = new SharedSettings(); settings.getFormattingSettings().setInsertSpaces(true); settings.getFormattingSettings().setTabSize(2); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); settings.getFormattingSettings().setPreserveEmptyContent(true); settings.getFormattingSettings().setLegacy(true); return settings; diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/xsi/XSIFormatterTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/xsi/XSIFormatterTest.java index dc8de4755..1cc25d0ab 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/xsi/XSIFormatterTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/xsi/XSIFormatterTest.java @@ -19,6 +19,7 @@ import org.eclipse.lemminx.commons.BadLocationException; import org.eclipse.lemminx.extensions.xsi.settings.XSISchemaLocationSplit; import org.eclipse.lemminx.settings.SharedSettings; +import org.eclipse.lemminx.settings.XMLFormattingOptions.SplitAttributes; import org.eclipse.lsp4j.TextEdit; import org.junit.jupiter.api.Test; @@ -89,7 +90,7 @@ public void xsiSchemaLocationSplitNoneWithDefaultMaxLineWidth() throws BadLocati @Test public void xsiSchemaLocationSplitOnElement() throws BadLocationException { SharedSettings settings = createSettings(); - settings.getFormattingSettings().setSplitAttributes(false); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.preserve); settings.getFormattingSettings().setPreserveAttributeLineBreaks(false); settings.getFormattingSettings().setMaxLineWidth(0); XSISchemaLocationSplit.setSplit(XSISchemaLocationSplit.onElement, settings.getFormattingSettings()); @@ -163,7 +164,7 @@ public void xsiSchemaLocationSplitOnElementWithPreserveLineBreaks() throws BadLo @Test public void xsiSchemaLocationSplitOnElementWithSplitAttribute() throws BadLocationException { SharedSettings settings = createSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); XSISchemaLocationSplit.setSplit(XSISchemaLocationSplit.onElement, settings.getFormattingSettings()); String content = "\r\n" + // "\r\n" + // + " "; + String expected = "\r\n" + // + " "; + assertFormat(content, expected, settings, + te(1, 6, 2, 4, " "), // + te(2, 55, 3, 4, "\r\n "), // + te(3, 57, 4, 4, "\r\n "), // + te(4, 59, 5, 4, "\r\n "), // + te(5, 24, 6, 8, ""), // + te(6, 51, 6, 52, "\r\n "), // + te(6, 112, 7, 8, "\r\n "), // + te(7, 50, 7, 51, "\r\n ")); + assertFormat(expected, expected, settings); + } + @Override public String toString() { return "XSIFormatterNewTest []"; @@ -199,7 +234,7 @@ public String toString() { @Test public void xsiSchemaLocationSplitOnPairWithNoMaxLineWidth() throws BadLocationException { SharedSettings settings = createSettings(); - settings.getFormattingSettings().setSplitAttributes(false); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.preserve); settings.getFormattingSettings().setPreserveAttributeLineBreaks(false); settings.getFormattingSettings().setMaxLineWidth(0); XSISchemaLocationSplit.setSplit(XSISchemaLocationSplit.onPair, settings.getFormattingSettings()); @@ -224,7 +259,7 @@ public void xsiSchemaLocationSplitOnPairWithNoMaxLineWidth() throws BadLocationE @Test public void xsiSchemaLocationSplitOnPairWithDefaultMaxLineWidth() throws BadLocationException { SharedSettings settings = createSettings(); - settings.getFormattingSettings().setSplitAttributes(false); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.preserve); settings.getFormattingSettings().setPreserveAttributeLineBreaks(false); settings.getFormattingSettings().setMaxLineWidth(80); XSISchemaLocationSplit.setSplit(XSISchemaLocationSplit.onPair, settings.getFormattingSettings()); @@ -251,7 +286,7 @@ public void xsiSchemaLocationSplitOnPairWithDefaultMaxLineWidth() throws BadLoca @Test public void xsiSchemaLocationSplitOnPairWithSplitAttribute() throws BadLocationException { SharedSettings settings = createSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); XSISchemaLocationSplit.setSplit(XSISchemaLocationSplit.onPair, settings.getFormattingSettings()); String content = "\r\n" + // "\r\n" + // + "\r\n" + + // + "\r\n" + // + ""; + String expected = "\r\n" + // + "\r\n" + + // + "\r\n" + // + ""; + assertFormat(content, expected, settings, + te(1, 6, 2, 4, " "), // + te(2, 55, 3, 4, "\r\n "), // + te(3, 57, 4, 4, "\r\n "), // + te(4, 59, 5, 4, "\r\n "), // + te(5, 24, 6, 8, ""), // + te(6, 112, 7, 8, "\r\n ")); + assertFormat(expected, expected, settings); + } + @Test public void xsiSchemaLocationSplitOnPairWithPreserveLineBreaksWithNoMaxLineWidth() throws BadLocationException { SharedSettings settings = createSettings(); @@ -341,7 +413,7 @@ public void xsiSchemaLocationSplitOnPairWithPreserveLineBreaksWithDefaultMaxLine @Test public void xsiSchemaLocationSplitOnPairWasElement() throws BadLocationException { SharedSettings settings = createSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); XSISchemaLocationSplit.setSplit(XSISchemaLocationSplit.onPair, settings.getFormattingSettings()); String content = "\r\n" + // "\r\n" + // + " "; + String expected = "\r\n" + // + " "; + assertFormat(content, expected, settings, + te(1, 6, 2, 4, " "), // + te(2, 55, 3, 4, "\r\n "), // + te(3, 57, 4, 4, "\r\n "), // + te(4, 59, 5, 4, "\r\n "), // + te(5, 67, 6, 24, " "), // + te(6, 84, 7, 24, "\r\n "), // + te(7, 66, 8, 24, " ")); + assertFormat(expected, expected, settings); + } + @Test public void xsiSchemaLocationEmpty() throws BadLocationException { SharedSettings settings = createSettings(); @@ -503,7 +607,7 @@ public void xsiSchemaLocationSplitOnElementWithTabsWithSplitAttribute() throws B SharedSettings settings = createSettings(); settings.getFormattingSettings().setTabSize(4); settings.getFormattingSettings().setInsertSpaces(false); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); XSISchemaLocationSplit.setSplit(XSISchemaLocationSplit.onElement, settings.getFormattingSettings()); String content = "\r\n" + // "\r\n" + // + "\r\n" + + // + "\r\n" + // + ""; + String expected = "\r\n" + // + "\r\n" + // + "\r\n" + // + ""; + assertFormat(content, expected, settings, + te(1, 6, 2, 4, " "), // + te(2, 55, 3, 4, "\r\n\t "), // + te(3, 57, 4, 4, "\r\n\t "), // + te(4, 59, 5, 4, "\r\n\t "), // + te(5, 24, 6, 8, ""), // + te(6, 51, 6, 52, "\r\n\t\t\t\t\t\t "), // + te(6, 112, 7, 8, "\r\n\t\t\t\t\t\t "), // + te(7, 50, 7, 51, "\r\n\t\t\t\t\t\t ")); + assertFormat(expected, expected, settings); + } + @Test public void xsiSchemaLocationSplitOnElementWithTabsWithPreserveLineBreaksOnSomeWithNoMaxLineWidth() throws BadLocationException { diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/format/XMLFormatterLegacyTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/format/XMLFormatterLegacyTest.java index 5a718e151..82ed4300e 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/format/XMLFormatterLegacyTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/format/XMLFormatterLegacyTest.java @@ -21,6 +21,7 @@ import org.eclipse.lemminx.settings.QuoteStyle; import org.eclipse.lemminx.settings.SharedSettings; import org.eclipse.lemminx.settings.XMLFormattingOptions.EmptyElements; +import org.eclipse.lemminx.settings.XMLFormattingOptions.SplitAttributes; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -415,7 +416,7 @@ public void testSplitAttributesSingle() throws BadLocationException { String content = ""; String expected = ""; SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); assertFormat(content, expected, settings); } @@ -425,7 +426,7 @@ public void testSplitAttributes() throws BadLocationException { String expected = ""; SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); assertFormat(content, expected, settings); } @@ -440,7 +441,7 @@ public void testSplitAttributesNested() throws BadLocationException { " bb=\"oo\">" + lineSeparator() + // ""; SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); assertFormat(content, expected, settings); } @@ -451,7 +452,7 @@ public void testNestedAttributesNoSplit() throws BadLocationException { " " + lineSeparator() + // ""; SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(false); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.preserve); assertFormat(content, expected, settings); } @@ -460,7 +461,7 @@ public void testSplitAttributesProlog() throws BadLocationException { String content = ""; String expected = ""; SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); assertFormat(content, expected, settings); } @@ -479,7 +480,7 @@ public void testSplitAttributesRangeOneLine() throws BadLocationException { ""; SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); assertFormat(content, expected, settings); } @@ -502,7 +503,7 @@ public void testSplitAttributesRangeMultipleLines() throws BadLocationException ; SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); assertFormat(content, expected, settings); } @@ -1114,7 +1115,7 @@ public void testJoinContentLinesWithSiblingElementFalse() throws BadLocationExce public void testEndTagMissingCloseBracket2() throws BadLocationException { SharedSettings settings = new SharedSettings(); settings.getFormattingSettings().setSpaceBeforeEmptyCloseTag(false); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); String content = ""; assertFormat(content, expected, settings); @@ -1831,7 +1832,7 @@ public void testUseSingleQuotesMultipleAttributes() throws BadLocationException @Test public void testUseDoubleQuotesMultipleAttributesSplit() throws BadLocationException { SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); settings.getFormattingSettings().setEnforceQuoteStyle(EnforceQuoteStyle.preferred); String content = " \n"; @@ -1843,7 +1844,7 @@ public void testUseDoubleQuotesMultipleAttributesSplit() throws BadLocationExcep @Test public void testUseSingleQuotesMultipleAttributesSplit() throws BadLocationException { SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); settings.getPreferences().setQuoteStyle(QuoteStyle.singleQuotes); settings.getFormattingSettings().setEnforceQuoteStyle(EnforceQuoteStyle.preferred); String content = " \n"; @@ -1922,7 +1923,7 @@ public void testAttributeNameTouchingPreviousValue() throws BadLocationException SharedSettings settings = new SharedSettings(); settings.getPreferences().setQuoteStyle(QuoteStyle.singleQuotes); settings.getFormattingSettings().setEnforceQuoteStyle(EnforceQuoteStyle.preferred); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); String content = "\r\n" + // " \r\n" + // @@ -2980,7 +2981,7 @@ public void preserveAttributeLineBreaksRangeFormattingWithEndTag3() throws BadLo @Test public void splitAttributesIndentSize0() throws BadLocationException { SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); settings.getFormattingSettings().setSplitAttributesIndentSize(0); String content = "\n"; @@ -2994,7 +2995,7 @@ public void splitAttributesIndentSize0() throws BadLocationException { @Test public void splitAttributesIndentSizeNegative() throws BadLocationException { SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); settings.getFormattingSettings().setSplitAttributesIndentSize(-1); String content = "\n"; @@ -3008,7 +3009,7 @@ public void splitAttributesIndentSizeNegative() throws BadLocationException { @Test public void splitAttributesIndentSize1() throws BadLocationException { SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); settings.getFormattingSettings().setSplitAttributesIndentSize(1); String content = "\n"; @@ -3022,7 +3023,7 @@ public void splitAttributesIndentSize1() throws BadLocationException { @Test public void splitAttributesIndentSizeDefault() throws BadLocationException { SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); String content = "\n"; String expected = ""; SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); assertFormat(content, expected, settings, // te(2, 9, 2, 14, ""), // te(2, 15, 2, 26, "")); @@ -324,7 +325,7 @@ public void testSplitAttributesRangeMultipleLines() throws BadLocationException ""; SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); assertFormat(content, expected, settings, // te(1, 7, 2, 8, "\r\n "), // te(2, 11, 2, 18, ""), // diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/format/settings/XMLFormatterQuoteStyleTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/format/settings/XMLFormatterQuoteStyleTest.java index 3e7d7c3d5..2b17e28d0 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/format/settings/XMLFormatterQuoteStyleTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/format/settings/XMLFormatterQuoteStyleTest.java @@ -19,6 +19,7 @@ import org.eclipse.lemminx.settings.EnforceQuoteStyle; import org.eclipse.lemminx.settings.QuoteStyle; import org.eclipse.lemminx.settings.SharedSettings; +import org.eclipse.lemminx.settings.XMLFormattingOptions.SplitAttributes; import org.eclipse.lsp4j.TextEdit; import org.junit.jupiter.api.Test; @@ -144,7 +145,7 @@ public void testUseSingleQuotesNoQuotes() throws BadLocationException { public void testUseSingleQuotesNoQuotesSplit() throws BadLocationException { SharedSettings settings = new SharedSettings(); settings.getPreferences().setQuoteStyle(QuoteStyle.singleQuotes); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); String content = " "; String expected = " "; assertFormat(content, expected, settings, // @@ -208,7 +209,7 @@ public void testUseSingleQuotesMultipleAttributes() throws BadLocationException @Test public void testUseDoubleQuotesMultipleAttributesSplit() throws BadLocationException { SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); settings.getFormattingSettings().setEnforceQuoteStyle(EnforceQuoteStyle.preferred); String content = " \n"; @@ -231,7 +232,7 @@ public void testUseDoubleQuotesMultipleAttributesSplit() throws BadLocationExcep @Test public void testUseSingleQuotesMultipleAttributesSplit() throws BadLocationException { SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); settings.getPreferences().setQuoteStyle(QuoteStyle.singleQuotes); settings.getFormattingSettings().setEnforceQuoteStyle(EnforceQuoteStyle.preferred); String content = " \n"; @@ -399,7 +400,7 @@ public void testAttributeNameTouchingPreviousValue() throws BadLocationException SharedSettings settings = new SharedSettings(); settings.getPreferences().setQuoteStyle(QuoteStyle.singleQuotes); settings.getFormattingSettings().setEnforceQuoteStyle(EnforceQuoteStyle.preferred); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); String content = "\r\n" + // " \r\n" + // diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/format/settings/XMLFormatterSplitAttributesTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/format/settings/XMLFormatterSplitAttributesTest.java index f64d8954d..ef691ac46 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/format/settings/XMLFormatterSplitAttributesTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/format/settings/XMLFormatterSplitAttributesTest.java @@ -18,6 +18,7 @@ import org.eclipse.lemminx.XMLAssert; import org.eclipse.lemminx.commons.BadLocationException; import org.eclipse.lemminx.settings.SharedSettings; +import org.eclipse.lemminx.settings.XMLFormattingOptions.SplitAttributes; import org.eclipse.lsp4j.TextEdit; import org.junit.jupiter.api.Test; @@ -30,7 +31,7 @@ public class XMLFormatterSplitAttributesTest extends AbstractCacheBasedTest { @Test public void splitAttributesIndentSize0() throws BadLocationException { SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); settings.getFormattingSettings().setSplitAttributesIndentSize(0); String content = "\n"; @@ -48,10 +49,51 @@ public void splitAttributesIndentSize0() throws BadLocationException { assertFormat(expected, expected, settings); } + @Test + public void splitAttributesIndentSize0AlignWithFirstAttr() throws BadLocationException { + SharedSettings settings = new SharedSettings(); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.alignWithFirstAttr); + settings.getFormattingSettings().setSplitAttributesIndentSize(0); + + String content = "\n"; + String expected = ""; + + assertFormat(content, expected, settings, // + te(0, 5, 0, 7, " "), // + te(0, 12, 0, 13, "\n "), // + te(0, 18, 0, 19, "\n "), // + te(0, 24, 0, 24, " "), // + te(0, 26, 1, 0, "")); + assertFormat(expected, expected, settings); + } + + @Test + public void splitAttributesIndentSize0AlignWithFirstAttrSplit() throws BadLocationException { + SharedSettings settings = new SharedSettings(); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.alignWithFirstAttr); + settings.getFormattingSettings().setSplitAttributesIndentSize(0); + + String content = ""; + String expected = ""; + + assertFormat(content, expected, settings, // + te(0, 5, 1, 4, " "), // + te(1, 9, 2, 4, "\n "), // + te(2, 9, 3, 4, "\n ")); + assertFormat(expected, expected, settings); + } + @Test public void splitAttributesIndentSizeNegative() throws BadLocationException { SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); settings.getFormattingSettings().setSplitAttributesIndentSize(-1); String content = "\n"; @@ -72,7 +114,7 @@ public void splitAttributesIndentSizeNegative() throws BadLocationException { @Test public void splitAttributesIndentSize1() throws BadLocationException { SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); settings.getFormattingSettings().setSplitAttributesIndentSize(1); String content = "\n"; @@ -93,7 +135,7 @@ public void splitAttributesIndentSize1() throws BadLocationException { @Test public void splitAttributesIndentSizeDefault() throws BadLocationException { SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); String content = "\n"; String expected = "" + lineSeparator() + // ""; SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); assertFormat(content, expected, settings, // te(0, 2, 0, 3, lineSeparator() + " "), // te(0, 10, 0, 11, lineSeparator() + " "), // @@ -134,6 +176,26 @@ public void testSplitAttributesNested() throws BadLocationException { assertFormat(expected, expected, settings); } + @Test + public void testSplitAttributesNestedAlignWithFirstAttr() throws BadLocationException { + String content = ""; + String expected = "" + lineSeparator() + // + " " + lineSeparator() + // + ""; + SharedSettings settings = new SharedSettings(); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.alignWithFirstAttr); + assertFormat(content, expected, settings, // + te(0, 10, 0, 11, lineSeparator() + " "), // + te(0, 19, 0, 19, lineSeparator() + " "), // + te(0, 29, 0, 30, lineSeparator() + " "), // + te(0, 32, 0, 33, ""), // + te(0, 34, 0, 35, ""), // + te(0, 44, 0, 44, lineSeparator())); + assertFormat(expected, expected, settings); + } + @Test public void testNestedAttributesNoSplit() throws BadLocationException { String content = ""; @@ -141,7 +203,7 @@ public void testNestedAttributesNoSplit() throws BadLocationException { " " + lineSeparator() + // ""; SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(false); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.preserve); assertFormat(content, expected, settings, // te(0, 19, 0, 19, lineSeparator() + " "), // te(0, 32, 0, 33, ""), // @@ -155,7 +217,7 @@ public void testSplitAttributesProlog() throws BadLocationException { String content = ""; String expected = content; SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); assertFormat(content, expected, settings); } @@ -164,7 +226,7 @@ public void testSplitAttributesSingle() throws BadLocationException { String content = ""; String expected = content; SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); assertFormat(content, expected, settings); } @@ -175,7 +237,7 @@ public void testSplitAttributes() throws BadLocationException { " k1=\"v1\"" + lineSeparator() + // " k2=\"v2\">"; SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); assertFormat(content, expected, settings, // te(0, 2, 0, 3, lineSeparator() + " "), // te(0, 10, 0, 11, lineSeparator() + " ")); @@ -186,7 +248,7 @@ public void testSplitAttributes() throws BadLocationException { public void testEndTagMissingCloseBracket2() throws BadLocationException { SharedSettings settings = new SharedSettings(); settings.getFormattingSettings().setSpaceBeforeEmptyCloseTag(false); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); String content = ""; + assertFormat(content, expected, settings, // + te(0, 8, 0, 9, lineSeparator() + " "), // + te(0, 14, 0, 14, lineSeparator() + " ")); + assertFormat(expected, expected, settings); + } + + @Test + public void testClosingBracketNewLineWithAlignWithFirstAttrNested() throws BadLocationException { + SharedSettings settings = new SharedSettings(); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.alignWithFirstAttr); + settings.getFormattingSettings().setClosingBracketNewLine(true); + String content = "\n" + // + " \n" + // + ""; + String expected = "\n" + // + " \n" + // + ""; + assertFormat(content, expected, settings, // + te(0, 8, 0, 9, "\n "), // + te(0, 14, 0, 14, "\n "), // + te(1, 10, 1, 11, "\n "), // + te(1, 16, 1, 16, "\n ")); + assertFormat(expected, expected, settings); + } + @Test public void testClosingBracketNewLineWithoutSplitAttributes() throws BadLocationException { SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(false); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.preserve); settings.getFormattingSettings().setClosingBracketNewLine(true); String content = ""; String expected = ""; @@ -506,7 +545,7 @@ public void testClosingBracketNewLineWithoutSplitAttributes() throws BadLocation @Test public void testClosingBracketNewLineWithSingleAttribute() throws BadLocationException { SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); settings.getFormattingSettings().setSplitAttributesIndentSize(0); settings.getFormattingSettings().setClosingBracketNewLine(true); String content = ""; @@ -518,7 +557,7 @@ public void testClosingBracketNewLineWithSingleAttribute() throws BadLocationExc @Test public void testClosingBracketNewLineWithChildElementIndent() throws BadLocationException { SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); settings.getFormattingSettings().setSplitAttributesIndentSize(0); settings.getFormattingSettings().setClosingBracketNewLine(true); String content = "" + lineSeparator() + " " + lineSeparator() + ""; @@ -534,7 +573,7 @@ public void testClosingBracketNewLineWithChildElementIndent() throws BadLocation @Test public void testClosingBracketNewLineWithPreserveEmptyContent() throws BadLocationException { SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); settings.getFormattingSettings().setSplitAttributesIndentSize(0); settings.getFormattingSettings().setPreserveEmptyContent(true); settings.getFormattingSettings().setClosingBracketNewLine(true); @@ -552,7 +591,7 @@ public void testClosingBracketNewLineWithPreserveEmptyContent() throws BadLocati @Test public void testClosingBracketNewLineWithPreserveEmptyContentSingleAttribute() throws BadLocationException { SharedSettings settings = new SharedSettings(); - settings.getFormattingSettings().setSplitAttributes(true); + settings.getFormattingSettings().setSplitAttributes(SplitAttributes.splitNewLine); settings.getFormattingSettings().setSplitAttributesIndentSize(0); settings.getFormattingSettings().setPreserveEmptyContent(true); settings.getFormattingSettings().setClosingBracketNewLine(true); diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/format/wtp/XMLFormattingPreferences.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/format/wtp/XMLFormattingPreferences.java index 8c3ffaa69..ffe133e7d 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/format/wtp/XMLFormattingPreferences.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/format/wtp/XMLFormattingPreferences.java @@ -26,7 +26,7 @@ public XMLFormattingPreferences() { // Line width: [72] super.setMaxLineWidth(72); // [] Split multiple attributes each on new line - super.setSplitAttributes(false); + super.setSplitAttributes(SplitAttributes.preserve); // [] Align final bracket in multi-line element tags // ??? // [] Preserve whitespace in tags with PCDATA contents @@ -59,9 +59,9 @@ public void setClearAllBlankLines(boolean clearAllBlankLines) { public void setIndentMultipleAttributes(boolean indentMultipleAttributes) { if (indentMultipleAttributes) { - super.setSplitAttributes(true); + super.setSplitAttributes(SplitAttributes.splitNewLine); } else { - super.setSplitAttributes(false); + super.setSplitAttributes(SplitAttributes.preserve); } } 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 85ae60bfc..43d4b73bb 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 @@ -27,6 +27,7 @@ import org.eclipse.lemminx.client.ExtendedClientCapabilities; import org.eclipse.lemminx.extensions.contentmodel.settings.ContentModelSettings; import org.eclipse.lemminx.extensions.contentmodel.settings.SchemaEnabled; +import org.eclipse.lemminx.settings.XMLFormattingOptions.SplitAttributes; import org.eclipse.lemminx.settings.capabilities.InitializationOptionsExtendedClientCapabilities; import org.eclipse.lemminx.utils.FilesUtils; import org.eclipse.lemminx.utils.JSONUtility; @@ -198,9 +199,9 @@ public void formatSettings() { public void formatSettingsOverride() { XMLFormattingOptions options = new XMLFormattingOptions(); options.setPreserveAttributeLineBreaks(true); - options.setSplitAttributes(false); + options.setSplitAttributes(SplitAttributes.preserve); assertTrue(options.isPreserveAttributeLineBreaks()); - options.setSplitAttributes(true); + options.setSplitAttributes(SplitAttributes.splitNewLine); // overridden assertFalse(options.isPreserveAttributeLineBreaks());