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

Support xsiSchemaLocationSplit setting with experimental formatter #1252

Merged
merged 1 commit into from
Jul 29, 2022

Conversation

JessicaJHee
Copy link
Contributor

Fixes #1246

Signed-off-by: Jessica He jhe@redhat.com

@JessicaJHee
Copy link
Contributor Author

JessicaJHee commented Jul 14, 2022

I believe some of the tests require this setting to get the correct result:

settings.getFormattingSettings().setPreserveEmptyContent(true);

This will prevent the empty content from getting deleted like here:

I can either work on the other setting first or change the test so that it's not dependent on the other setting?

@angelozerr angelozerr closed this Jul 14, 2022
@datho7561 datho7561 reopened this Jul 15, 2022
@angelozerr
Copy link
Contributor

@JessicaJHee for this kind of formatting you need to do that with an implementation of IformmatingParticipant. I suggest that you see how old formatter uses this participant. You woll need to add or update the signature of the participant to support edits

@angelozerr
Copy link
Contributor

@JessicaJHee if you think it is better to work on another settings before doing this pr dont hesîtate to do that

@JessicaJHee
Copy link
Contributor Author

@JessicaJHee for this kind of formatting you need to do that with an implementation of IformmatingParticipant. I suggest that you see how old formatter uses this participant. You woll need to add or update the signature of the participant to support edits

I didn't use this because I thought for the new formatter, the idea is to avoid using XMLBuilder by adding/removing spaces instead of rewriting the xml content? But if my understanding is wrong, I will try again and use XSIFormatterParticipant/IFormatterParticipant.

Copy link
Contributor

@rgrunber rgrunber left a comment

Choose a reason for hiding this comment

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

I noticed that formatting as onElement and then back to onPair doesn't work.

@rgrunber
Copy link
Contributor

Whoops, just saw Angelo's other comments. My guess is you need to go into DOMAttributeFormatter#formatAttribute(..) and instead of plugging your own code, set up the IFormatterParticipants being contributed and get the proposed text edits of each one. You would be calling some new (default) method of IFormatterParticipant that is returning a text edit (and has no XMLBuilder).

With that in place the task just becomes implementing the new method in XSIFormatterParticipant based on the old logic.

@angelozerr feel free to correct me if any of this is wrong.

@angelozerr
Copy link
Contributor

Indeed @rgrunber it was my idea. the formatter participant could have à New method with edits as parameter. Once experimental formatter will replace the old formatter we will able to remove the method with xmlbuilder.

@JessicaJHee
Copy link
Contributor Author

Still fixing up a few things before this commit is ready for review!

@JessicaJHee JessicaJHee marked this pull request as ready for review July 19, 2022 18:39
@JessicaJHee JessicaJHee force-pushed the issue1246 branch 2 times, most recently from 5f8f594 to d574533 Compare July 21, 2022 19: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.

Great work, Jessica!

@datho7561
Copy link
Contributor

Wait actually, some of the tests fail on my computer. Can you take a look again and see if anything odd is happening for you?

@datho7561
Copy link
Contributor

Wait actually, some of the tests fail on my computer. Can you take a look again and see if anything odd is happening for you?

Well, it works well for me now. No idea what changed

@angelozerr
Copy link
Contributor

angelozerr commented Jul 25, 2022

I think given that the behaviour of the existing formatter is to line up the URLs even when splitAttributes is disabled, it would be a good idea to ensure that this PR is able to do that.

It seems that the PR requires that splitAttributes is set to true https://github.com/eclipse/lemminx/pull/1252/files#diff-c0186ecdc200d591a9caa3dadf037073d77443cee30423e92600647efbf3fddbR337

You should remove this seetings and it should work without splitAttributes. With the current PR if you remove the line code https://github.com/eclipse/lemminx/pull/1252/files#diff-c0186ecdc200d591a9caa3dadf037073d77443cee30423e92600647efbf3fddbR337 tests fail.

@JessicaJHee
Copy link
Contributor Author

It seems that the PR requires that splitAttributes is set to true https://github.com/eclipse/lemminx/pull/1252/files#diff-c0186ecdc200d591a9caa3dadf037073d77443cee30423e92600647efbf3fddbR337

I already have these three tests for the case where split attribute is set to false:

xsiSchemaLocationSplitOnElementWithoutSplitAttribute()
xsiSchemaLocationSplitOnPairWithoutSplitAttribute()
xsiSchemaLocationSplitOnElementWithTabsWithoutSplitAttribute()

Is the idea to force split attribute to true when schema location split is set to either onPair or onElement?

@angelozerr
Copy link
Contributor

I already have these three tests for the case where split attribute is set to false:

I think you should not have specific test with split attributes to true. The xsi settings (which format the attribute value of xsi:schemaLocation) should be totally independant from splitAttribute (which format attribute name location).

https://github.com/eclipse/lemminx/pull/1252/files#diff-c0186ecdc200d591a9caa3dadf037073d77443cee30423e92600647efbf3fddbR337

Is the idea to force split attribute to true when schema location split is set to either onPair or onElement?

Even if looks like the same behavior, we should distinguish them. SplitAttribute format the attribute name location, although xsi settings is for attribute value of xsi:schemaLocation.

@datho7561
Copy link
Contributor

datho7561 commented Jul 25, 2022

I already have these three tests for the case where split attribute is set to false:

I think you should not have specific test with split attributes to true.

Why not? If I understand correctly, the behaviour should be different, since you need to indent the schemaLocation entries a different amount. eg.

<?xml version="1.0" encoding="UTF-8"?>
<aaa xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://google.ca my-file.xsd
                                                                               https://stackoverflow.yaml my-other-schema.xsd
                                                                               https://github.com my-github-schema.xsd">
    <bbb> Hello</bbb>
    <ccc />
</aaa>

If you were to indent to the same level as you would do with splitAttributes: "true", then the entries don't line up.

@angelozerr
Copy link
Contributor

Good catch @datho7561. Lets keep tests with Split attributes. But the main tests should be done with no Split attributes.

@JessicaJHee JessicaJHee force-pushed the issue1246 branch 2 times, most recently from d466a48 to 774ef58 Compare July 26, 2022 21:21
@angelozerr
Copy link
Contributor

After playing with the PR, I noticed that it is important to support too https://github.com/redhat-developer/vscode-xml/blob/main/docs/Formatting.md#xmlformatpreserveattributelinebreaks

If xml.format.splitAttribute is set to false, and xml.format.preserveAttributeLineBreaks is set to true, it doesn't format correctly the XML.

I think we should have a test with xsiSchemaLocationSplitOnElementWithTabsWithPreserverAttributeLineBreaks which is a copy/paste of xsiSchemaLocationSplitOnElementWithTabsWithSplitAttribute by relacing https://github.com/eclipse/lemminx/pull/1252/files#diff-c0186ecdc200d591a9caa3dadf037073d77443cee30423e92600647efbf3fddbR298 with

settings.getFormattingSettings().setPreserveAttributeLineBreaks(true);

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.

Works really well. Thanks, Jessica!

@datho7561 datho7561 merged commit 8acc320 into eclipse:main Jul 29, 2022
@JessicaJHee JessicaJHee deleted the issue1246 branch July 29, 2022 18:42
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.

Support xml.format.xsiSchemaLocationSplit setting with experimental formatter
4 participants