Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve invalid content while formatting #1041

Closed
angelozerr opened this issue May 19, 2021 · 2 comments
Closed

Preserve invalid content while formatting #1041

angelozerr opened this issue May 19, 2021 · 2 comments
Assignees
Labels
bug Something isn't working formatting This issue or enhancement is related to formatting support
Milestone

Comments

@angelozerr
Copy link
Contributor

angelozerr commented May 19, 2021

When formatting is done with invalid content theinvalid content is lost.

For instance given this XML content:

<a=

After formatting we lose the invalid content =

<a

There are several issues with this problem:

and a PR which tries to fix the problem with invalid content inside tag element #766

Today the formatting process load the XML content to format in a DOM Document and the DOM document is visited and we generate the XML content according DOM node type. At the end of the process we return ONE TextEdit which contains the generates XML string.

I think it's not the right way. Indeed after studying the formatting support in the WTP XML Editor (which preserve invalid content), the right way is to create several TextEdits (instead of one textedit) when a format must be done (ex : we create a TextEdit to format a start tag element to indent it, create N TextEdit to format N start tag element to indent them).

See https://github.com/kingargyle/wtp-sourceediting/blob/master/plugins/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/formatter/DefaultXMLPartitionFormatter.java from WTP which uses this strategy.

It's a lot of work, but IMHO I think we should do that to have a clean XML formatter.

@angelozerr angelozerr added formatting This issue or enhancement is related to formatting support bug Something isn't working labels May 19, 2021
angelozerr added a commit to angelozerr/lemminx that referenced this issue May 20, 2021
angelozerr added a commit to angelozerr/lemminx that referenced this issue May 20, 2021
@angelozerr angelozerr self-assigned this May 26, 2021
@clementnuss
Copy link

fully agree with this issue, this is a "killer" for me at the moment, as I have to disable xml formatting altogether for the (many) documents where I use macros that insert credentials in xml fields.
these "macros" are not recognized by lemminx and replaced with null fields instead of being ignored.
commenting here to show the interest and to get notified of future improvements :)

angelozerr added a commit to angelozerr/lemminx that referenced this issue Apr 3, 2022
angelozerr added a commit to angelozerr/lemminx that referenced this issue Apr 6, 2022
angelozerr added a commit to angelozerr/lemminx that referenced this issue Apr 7, 2022
angelozerr added a commit to angelozerr/lemminx that referenced this issue Apr 9, 2022
angelozerr added a commit to angelozerr/lemminx that referenced this issue Apr 14, 2022
@angelozerr angelozerr added this to the 0.21.0 milestone Jun 29, 2022
@angelozerr
Copy link
Contributor Author

This issue should be fixed by the experimental formatter https://github.com/redhat-developer/vscode-xml/blob/master/docs/Formatting.md#xmlformatexperimental

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working formatting This issue or enhancement is related to formatting support
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants