forked from eclipse/lemminx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide basic experimental formatter which supports invalid XML
Fixes eclipse#1195 Signed-off-by: azerr <azerr@redhat.com>
- Loading branch information
1 parent
6113791
commit a950ec2
Showing
24 changed files
with
5,286 additions
and
823 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...clipse/lemminx/extensions/contentmodel/participants/ContentModelFormatterParticipant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.eclipse.lemminx.extensions.contentmodel.participants; | ||
|
||
import java.util.Collection; | ||
|
||
import org.eclipse.lemminx.dom.DOMElement; | ||
import org.eclipse.lemminx.extensions.contentmodel.model.CMDocument; | ||
import org.eclipse.lemminx.extensions.contentmodel.model.CMElementDeclaration; | ||
import org.eclipse.lemminx.extensions.contentmodel.model.ContentModelManager; | ||
import org.eclipse.lemminx.services.extensions.format.IFormatterParticipant; | ||
import org.eclipse.lemminx.services.format.FormatElementCategory; | ||
import org.eclipse.lemminx.services.format.XMLFormattingConstraints; | ||
import org.eclipse.lemminx.settings.SharedSettings; | ||
|
||
public class ContentModelFormatterParticipant implements IFormatterParticipant { | ||
|
||
private static final String GRAMMAR_AWARE_FORMATTING = "grammarAwareFormatting"; | ||
|
||
private final ContentModelManager contentModelManager; | ||
|
||
public ContentModelFormatterParticipant(ContentModelManager contentModelManager) { | ||
this.contentModelManager = contentModelManager; | ||
} | ||
|
||
@Override | ||
public FormatElementCategory getFormatElementCategory(DOMElement element, | ||
XMLFormattingConstraints parentConstraints, SharedSettings sharedSettings) { | ||
Boolean enabled = sharedSettings.getFormattingSettings().getBoolean(GRAMMAR_AWARE_FORMATTING); | ||
if (enabled != null && !enabled) { | ||
return null; | ||
} | ||
|
||
Collection<CMDocument> cmDocuments = contentModelManager.findCMDocument(element); | ||
for (CMDocument cmDocument : cmDocuments) { | ||
CMElementDeclaration cmElement = cmDocument.findCMElement(element); | ||
if (cmElement != null) { | ||
if (cmElement.isStringType()) { | ||
return FormatElementCategory.PreserveSpace; | ||
} | ||
if (cmElement.isMixedContent()) { | ||
return FormatElementCategory.MixedContent; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.