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

Improve text formatting for experimental formatter #1336

Merged

Conversation

JessicaJHee
Copy link
Contributor

Fixes #1331

Signed-off-by: Jessica He [email protected]

@datho7561 datho7561 self-requested a review October 18, 2022 13:19
@JessicaJHee JessicaJHee force-pushed the improve-text-formatting branch from 213e8cd to 2e21a02 Compare October 18, 2022 16:47
@JessicaJHee JessicaJHee force-pushed the improve-text-formatting branch from 2e21a02 to dac1d9f Compare October 19, 2022 13:27
Copy link
Contributor

@datho7561 datho7561 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am good with this change. Thanks Jessica! I think we discussed waiting until after the release to make this change though.

@datho7561
Copy link
Contributor

@angelozerr what do you think about this change? Jessica wanted to wait until after the release before merging it, but I think it should be good to go now.

@angelozerr
Copy link
Contributor

I'm really sorry @JessicaJHee @datho7561 to not have reviewed the PR -(

When I see tests, it seems we are different from Oxygen formatter, right? It doesn't follow the behavior described in https://github.com/redhat-developer/vscode-xml/blob/main/docs/Formatting.md#xmlformatexperimental ?

@angelozerr
Copy link
Contributor

angelozerr commented Oct 24, 2022

I wonder if this PR should cover the usecase:

<foo>
	<bar>
					</bar>
</foo>

to indent correctly bar

<foo>
	<bar>
	</bar>
</foo>

but perhaps teh Oxygen behavior doesn't allow that?

@JessicaJHee
Copy link
Contributor Author

When I see tests, it seems we are different from Oxygen formatter, right? It doesn't follow the behavior described in https://github.com/redhat-developer/vscode-xml/blob/main/docs/Formatting.md#xmlformatexperimental ?

Yes it is a bit different when it comes to text formatting since oxygen will always join text content/ normalize the space between text content by default. It is more similar to IntelliJ. I waned to see how you feel about the changes since it is quite different from before. There are a lot of cases to consider but I think with this PR it would be easier to discuss how we want the behavior for text formatting to be like!

I wonder if this PR should cover the usecase:

<foo>
	<bar>
					</bar>
</foo>

to indent correctly bar

<foo>
	<bar>
	</bar>
</foo>

but perhaps teh Oxygen behavior doesn't allow that?

I wasn't sure because in this case we normalize the space if the content is empty (contains only white space and new lines). Unfortunately I don't have access to try oxygen anymore.
https://github.com/eclipse/lemminx/blob/037589a61986a348f3acd5849f900406e28211cb/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/format/experimental/XMLFormatterPreserveEmptyContentTest.java#L45

@angelozerr
Copy link
Contributor

Yes it is a bit different when it comes to text formatting since oxygen will always join text content/ normalize the space between text content by default. It is more similar to IntelliJ. I waned to see how you feel about the changes since it is quite different from before. There are a lot of cases to consider but I think with this PR it would be easier to discuss how we want the behavior for text formatting to be like!

Indeed we need to specify more teh behavior of the formatting. My wish is to have the IJ and Oxygen behavior both (with a new settings).

I think it is important to preserve Oxygen behavior, because it fixed #594 (I suggest that you read all comments). If we could provide a new settings which format ala IJ, it should be very nice.

I wasn't sure because in this case we normalize the space if the content is empty (contains only white space and new lines).

IMHO I think we should take care of this usecase (setting a la IJ).

@JessicaJHee JessicaJHee force-pushed the improve-text-formatting branch from dac1d9f to be6d79d Compare October 25, 2022 19:25
@JessicaJHee
Copy link
Contributor Author

After reading the previous issue on this, I think it makes sense to set joinContentLines = true by default so we have the same behavior as oxygen. We could have the behavior I have in this PR when joinContentLines = false (more similar to IJ)? We still have preserveEmptyContent for when the user does not want the spaces modified within tags.

I have added a few tests that relate to the sample provided in the issue mentioned in XMLFormatterMaxLineWithTest.java - mixedText()

For the case empty tags, perhaps we could add a setting (something like 'normalizeSpaceInEmptyElement') if necessary?

@datho7561
Copy link
Contributor

joinContentLines = true by default so we have the same behavior as oxygen

I think that this is a good idea. The Oxygen formatter handles mixed content very well, so using this behaviour by default is a good idea.

IMHO I think we should take care of this usecase (setting a la IJ). (angelo)
For the case empty tags, perhaps we could add a setting (something like 'normalizeSpaceInEmptyElement') if necessary? (jessica)

What should the default behaviour be for empty tags? I think it would be nice to completely remove the content (eg. <aaa></aaa>) unless preserveEmptyContent is enabled. I don't know what oxygen's default behaviour is, but this is what Intellij does.

@JessicaJHee JessicaJHee force-pushed the improve-text-formatting branch 2 times, most recently from d531592 to 8ed23a6 Compare October 26, 2022 19:47
@JessicaJHee JessicaJHee force-pushed the improve-text-formatting branch from 8ed23a6 to 17d54be Compare October 26, 2022 22:12
@angelozerr angelozerr merged commit 719bf9d into eclipse-lemminx:main Oct 27, 2022
@angelozerr
Copy link
Contributor

Impressive @JessicaJHee ! Thanks so much. Now we should update vscode-xml doc.

@JessicaJHee JessicaJHee deleted the improve-text-formatting branch October 27, 2022 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve text content formatting in experimental formatter
3 participants