Class XMLFormattingOptions

java.lang.Object
org.eclipse.lemminx.settings.LSPFormattingOptions
org.eclipse.lemminx.settings.XMLFormattingOptions

public class XMLFormattingOptions extends LSPFormattingOptions
This class is the root of all formatting settings. It is necessary to update this class for any new additions. All defaults should be set here to eventually be overridden if needed.
  • Field Details

    • DEFAULT_QUOTATION

      public static final String DEFAULT_QUOTATION
      See Also:
    • DEFAULT_PRESERVER_NEW_LINES

      public static final int DEFAULT_PRESERVER_NEW_LINES
      See Also:
    • DEFAULT_TAB_SIZE

      public static final int DEFAULT_TAB_SIZE
      See Also:
    • DEFAULT_ENFORCE_QUOTE_STYLE

      public static final EnforceQuoteStyle DEFAULT_ENFORCE_QUOTE_STYLE
    • DEFAULT_PRESERVE_ATTR_LINE_BREAKS

      public static final boolean DEFAULT_PRESERVE_ATTR_LINE_BREAKS
      See Also:
    • DEFAULT_TRIM_TRAILING_SPACES

      public static final boolean DEFAULT_TRIM_TRAILING_SPACES
      See Also:
    • DEFAULT_SPLIT_ATTRIBUTES_INDENT_SIZE

      public static final int DEFAULT_SPLIT_ATTRIBUTES_INDENT_SIZE
      See Also:
    • DEFAULT_XSI_SCHEMA_LOCATION_SPLIT

      public static final String DEFAULT_XSI_SCHEMA_LOCATION_SPLIT
    • DEFAULT_CLOSING_BRACKET_NEW_LINE

      public static final boolean DEFAULT_CLOSING_BRACKET_NEW_LINE
      See Also:
    • DEFAULT_PRESERVE_SPACE

      public static final List<String> DEFAULT_PRESERVE_SPACE
  • Constructor Details

    • XMLFormattingOptions

      public XMLFormattingOptions()
      Create an XMLFormattingOptions instance with the option to initialize default values for all supported settings.
    • XMLFormattingOptions

      public XMLFormattingOptions(int tabSize, boolean insertSpaces, boolean initializeDefaultSettings)
    • XMLFormattingOptions

      public XMLFormattingOptions(int tabSize, boolean insertSpaces)
    • XMLFormattingOptions

      public XMLFormattingOptions(org.eclipse.lsp4j.FormattingOptions options, boolean initializeDefaultSettings)
    • XMLFormattingOptions

      public XMLFormattingOptions(org.eclipse.lsp4j.FormattingOptions options)
  • Method Details

    • getSplitAttributes

      public XMLFormattingOptions.SplitAttributes getSplitAttributes()
    • setSplitAttributes

      public void setSplitAttributes(XMLFormattingOptions.SplitAttributes splitAttributes)
    • isJoinCDATALines

      public boolean isJoinCDATALines()
    • setJoinCDATALines

      public void setJoinCDATALines(boolean joinCDATALines)
    • isFormatComments

      public boolean isFormatComments()
    • setFormatComments

      public void setFormatComments(boolean formatComments)
    • isJoinCommentLines

      public boolean isJoinCommentLines()
    • setJoinCommentLines

      public void setJoinCommentLines(boolean joinCommentLines)
    • isJoinContentLines

      public boolean isJoinContentLines()
    • setJoinContentLines

      public void setJoinContentLines(boolean joinContentLines)
    • isLegacy

      public boolean isLegacy()
      Returns true if the legacy formatter must be used and false otherwise.
      Returns:
      true if the legacy formatter must be used and false otherwise.
    • setLegacy

      public void setLegacy(boolean legacy)
      Set true if the legacy formatter must be used and false otherwise.
      Parameters:
      legacy - true if the legacy formatter must be used and false otherwise.
    • setMaxLineWidth

      public void setMaxLineWidth(int maxLineWidth)
      Sets the value of max line width.
      Parameters:
      maxLineWidth - the new value for max line width.
    • getMaxLineWidth

      public int getMaxLineWidth()
      Returns the value of max line width or zero if it was set to a negative value
      Returns:
      the value of max line width or zero if it was set to a negative value
    • isEnabled

      public boolean isEnabled()
    • setEnabled

      public void setEnabled(boolean enabled)
    • setSpaceBeforeEmptyCloseTag

      public void setSpaceBeforeEmptyCloseTag(boolean spaceBeforeEmptyCloseTag)
    • isSpaceBeforeEmptyCloseTag

      public boolean isSpaceBeforeEmptyCloseTag()
    • setPreserveEmptyContent

      public void setPreserveEmptyContent(boolean preserveEmptyContent)
    • isPreserveEmptyContent

      public boolean isPreserveEmptyContent()
    • setPreservedNewlines

      public void setPreservedNewlines(int preservedNewlines)
    • getPreservedNewlines

      public int getPreservedNewlines()
    • setEmptyElement

      public void setEmptyElement(XMLFormattingOptions.EmptyElements emptyElement)
    • getEmptyElements

      public XMLFormattingOptions.EmptyElements getEmptyElements()
    • setEnforceQuoteStyle

      public void setEnforceQuoteStyle(EnforceQuoteStyle enforce)
    • getEnforceQuoteStyle

      public EnforceQuoteStyle getEnforceQuoteStyle()
    • setPreserveAttributeLineBreaks

      public void setPreserveAttributeLineBreaks(boolean preserveAttributeLineBreaks)
      Sets the value of preserveAttrLineBreaks
    • isPreserveAttributeLineBreaks

      public boolean isPreserveAttributeLineBreaks()
      Returns the value of preserveAttrLineBreaks.

      Only effective when splitAttributes is a preserve mode (preserve or preserve-aligned). Force/auto modes control line breaks themselves and override this setting.

      Use case (preserve + preserveAttributeLineBreaks=true):

       <foo attr1="a"
         attr2="b">  → line breaks preserved, indented with level+1
       

      Use case (preserve-aligned + preserveAttributeLineBreaks=true):

       <foo attr1="a"
            attr2="b">  → line breaks preserved, aligned with first attr
       
      Returns:
      the value of preserveAttrLineBreaks
    • setSplitAttributesIndentSize

      public void setSplitAttributesIndentSize(int splitAttributesIndentSize)
      Sets the value of splitAttributesIndentSize
      Parameters:
      splitAttributesIndentSize - the new value for splitAttributesIndentSize
    • getSplitAttributesIndentSize

      public int getSplitAttributesIndentSize()
      Returns the value of splitAttributesIndentSize or zero if it was set to a negative value
      Returns:
      the value of splitAttributesIndentSize or zero if it was set to a negative value
    • getClosingBracketNewLine

      public boolean getClosingBracketNewLine()
      Returns the value of closingBracketNewLine or false if it was set to null A setting for enabling the XML formatter to move the closing bracket of a tag with at least 2 attributes to a new line.
      Returns:
      the value of closingBracketNewLine or false if it was set to null
    • setClosingBracketNewLine

      public void setClosingBracketNewLine(boolean closingBracketNewLine)
      Sets the value of closingBracketNewLine
      Parameters:
      closingBracketNewLine - the new value for closingBracketNewLine
    • setPreserveSpace

      public void setPreserveSpace(List<String> preserveSpace)
      Sets the element name list which must preserve space.
      Parameters:
      preserveSpace - the element name list which must preserve space.
    • getPreserveSpace

      public List<String> getPreserveSpace()
      Returns the element name list which must preserve space.
      Returns:
      the element name list which must preserve space.
    • getMixedContent

      public XMLFormattingOptions.MixedContent getMixedContent()
      Returns the mixed content formatting mode.

      Use case: xml.format.mixedContent=preserve keeps <p> text <b>bold</b> more </p> unchanged.

      Returns:
      the mixed content mode (defaults to normalize).
    • setMixedContent

      public void setMixedContent(XMLFormattingOptions.MixedContent mixedContent)
      Sets the mixed content formatting mode.
      Parameters:
      mixedContent - the mode to set.
    • getBlockElements

      public List<String> getBlockElements()
      Returns the element name list treated as block in mixed content.

      Use case: with blockElements=["div","set"], <p> text <div>block</div> </p> puts <div> on its own line, while <b> stays inline.

      When null or empty, no elements are block — all elements are inline (backward-compatible default).

      Returns:
      the block element name list, or null if no elements are block.
    • setBlockElements

      public void setBlockElements(List<String> blockElements)
      Sets the element name list treated as block in mixed content.
      Parameters:
      blockElements - the element name list, or null to treat all elements as inline (default).
    • isBlockElement

      public boolean isBlockElement(String tagName)
      Returns true if the given element name is a block element in mixed content.

      When getBlockElements() is null or empty, no elements are block — all are inline (backward-compatible behavior). null and [] are equivalent — both mean "not configured".

      Only effective in reflow mode. In normalize mode, the block/inline distinction is not used.

      Use cases (with mixedContent=reflow):

      • blockElements=null or []: no block elements → <p> text <b>bold</b> <div>x</div> </p> stays on one line.
      • blockElements=["div"]: only <div> is block → <div> gets its own line, <b> stays inline.
      Parameters:
      tagName - the element tag name to check.
      Returns:
      true if the element is block.
    • isGrammarAwareFormatting

      public boolean isGrammarAwareFormatting()
    • setGrammarAwareFormatting

      public void setGrammarAwareFormatting(boolean grammarAwareFormatting)
    • getProfiles

      public List<XMLFormattingProfile> getProfiles()
      Returns the formatting profiles for per-document settings overrides.

      Use case: a workspace with DocBook and Maven POM files can define profiles with different format settings for each document type. The first matching profile wins.

      Returns:
      the profiles, or null if none are configured.
      See Also:
    • setProfiles

      public void setProfiles(List<XMLFormattingProfile> profiles)
      Sets the formatting profiles.
      Parameters:
      profiles - the profiles.
    • getXsiSchemaLocationSplit

      public String getXsiSchemaLocationSplit()
    • setXsiSchemaLocationSplit

      public void setXsiSchemaLocationSplit(String xsiSchemaLocationSplit)
    • merge

      public XMLFormattingOptions merge(XMLFormattingOptions formattingOptions)
    • merge

      public XMLFormattingOptions merge(org.eclipse.lsp4j.FormattingOptions formattingOptions)
    • getFormatElementCategory

      public FormatElementCategory getFormatElementCategory(DOMElement element)