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

Formatter incorrectly breaks short lines in POM XML. #1216

Closed
garretwilson opened this issue May 20, 2023 · 13 comments
Closed

Formatter incorrectly breaks short lines in POM XML. #1216

garretwilson opened this issue May 20, 2023 · 13 comments

Comments

@garretwilson
Copy link

garretwilson commented May 20, 2023

I'm using Eclipse EE 2023-03 on Windows 10. I have this Maven pom.xml file. It has the following lines:

### Configurable Properties
`binSourceDirectory`
: The source directory for scripts; defaults to `${project.basedir}/src/bin`.
`binOutputDirectory`
: The output directory for scripts; defaults to `${project.build.directory}/bin`

I have "Max line width" set to 999 in the configuration.

I use Ctrl+Shift+F to format the file. The lines above are changed to:

### Configurable Properties
`binSourceDirectory`
: The source directory for scripts; defaults to
`${project.basedir}/src/bin`.
`binOutputDirectory`
: The output directory for scripts; defaults to `${project.build.directory}/bin`

You'll note that the second line was split after "defaults to", seemingly for no reason all.

It also incorrectly wraps this line:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

The result is:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

Neither of these lines should have been wrapped, because neither of them are anywhere near 999 characters in length.

@garretwilson
Copy link
Author

The formatter is making crazy decisions. It takes this:

				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-failsafe-plugin</artifactId>
					<version>2.22.2</version>
				</plugin>

and produces this:

				<plugin>
					<groupId>
						org.apache.maven.plugins</groupId>
					<artifactId>maven-failsafe-plugin</artifactId>
					<version>2.22.2</version>
				</plugin>

It takes this:

							<tag>
								<name>return</name>
							</tag>
							<tag>
								<name>throws</name>
							</tag>
							<tag>
								<name>since</name>
							</tag>

and produces this:

							<tag>
								<name>return</name>
							</tag>
							<tag>
								<name>
									throws</name>
							</tag>
							<tag>
								<name>since</name>
							</tag>

What? (See how it split <name>throws</name>.) These are seemingly completely arbitrary line breaks. This really makes the formatter unusable.

@angelozerr
Copy link
Contributor

Is not the same issue than #1205 ?

@vrubezhny
Copy link
Contributor

I think yes, it's the same as #1205.

@garretwilson Please consider updating to M2E-Core 2.3.0 (https://download.eclipse.org/technology/m2e/snapshots/2.3.0/) and WWD 1.1.0 (https://download.eclipse.org/wildwebdeveloper/releases/1.1.0/) together in order to fix the issue.

Feel free to re-open in case of issue still persists after upgrading.

@garretwilson
Copy link
Author

Is not the same issue than #1205 ?

Does #1205 refer to adding line breaks to short lines? I couldn't find that. Which comment in that ticket are you referring to?

@vrubezhny I can see your comment in that ticket:

Formatting happens to be applied only to the selected region and doesn't break the <version> tags unless I set Max line with < 70 in preferences (when editing your example POM XML):

But in my case I have the max line width set to 999.

@vrubezhny
Copy link
Contributor

@garretwilson Sure. But in my case I have a different set of versions for WWD/Lemminx/TM4E/LSP4E/whatever else.

Yes, it is possible that, for example, formatting the <version> element will result into placing the value on the next line due to the too small value of max with preference, but it's something that you can configure and it works as expected for me using the latest versions.

@garretwilson
Copy link
Author

… it works as expected for me using the latest versions.

You're saying that the version you are using did not wrap the pom.xml I linked to in the description?

@vrubezhny
Copy link
Contributor

You're saying that the version you are using did not wrap the pom.xml I linked to in the description?

That's exactly what I said. If Max line width preference is properly configured the formatting doesn't reformat the version, groupid, artifactid tag contents.

And yes. Using the versions I mentioned above and max line length == 999 the POM file you have pointed to (https://github.com/globalmentor/globalmentor-root/blob/bce5bdbac7797b5b9114a72e5da2f4d76f3e24a7/pom.xml) is formatted, but not a single version. groupid nor artifactid element is reformatted. The diff result is the following:

 $ diff ~/projects/runtime-wwd/large-pom/pom.xml ~/projects/runtime-wwd/large-pom/pom-reformatted.xml 
57c57,58
< <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
---
> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> 	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1011c1012
< </project>
\ No newline at end of file
---
> </project>

There was a similar issue in 2023-03 and it was fixed. Please update to the latest versions and give it a try .
Please see #1216 (comment) for the links to the versions recommended for installation, or wait for the upcoming 2023-06 release.

@garretwilson
Copy link
Author

garretwilson commented Jun 7, 2023

I updated to Eclipse EE 2023-06 RC1. Unfortunately even line width set to 999, the formatter changes

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

to

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

In addition, just normal editing of the file in Eclipse EE 2023-06 RC1 will hang for a couple of seconds (i.e. my cursor will just stop and not respond to the keyboard), every few seconds. (Note that this happens sporadically, and I can't always reproduce it. It may be related to eclipse-tm4e/tm4e#544. Or not.)

Should I file a new bug, or would you like to reopen this one, as it still isn't fixed?

@garretwilson
Copy link
Author

Note that the Red Hat XML Language Support extension on VS Code (which I understand to use the same underlying library—is that correct?) correctly does not wrap the line mentioned when the max line length is set to e.g. 0. See redhat-developer/vscode-xml#901. However on Eclipse EE 2023-06 RC1 the formatter still wraps the line mentioned above, even if I set the line length to 0 or to 999.

@angelozerr
Copy link
Contributor

Note that the Red Hat XML Language Support extension on VS Code (which I understand to use the same underlying library—is that correct?)

Indeed vscode-xml and wildwebdeveloper uses the same XML language server https://github.com/eclipse/lemminx

However on Eclipse EE 2023-06 RC1 the formatter still wraps the line mentioned above, even if I set the line length to 0 or to 999.

It should have the same behavior than vscode-xml perhaps wildwebdeloper doesn't use the same version of lemminx?

@vrubezhny
Copy link
Contributor

At the moment WWD uses Lemminx v.0.25.0 (the latest released one as of today).

@angelozerr
Copy link
Contributor

Thats strange.

@garretwilson
Copy link
Author

garretwilson commented Sep 12, 2023

Does anyone know why this issue was closed? As I mentioned above, this wasn't fixed in 2023-06 RC1. And now I'm on 2023-09 RC1, and it's still not fixed.

Even though I have a max line length set to 999, it still wraps the following line:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

to this:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

You can test with this pom.xml.

Do I need to open another ticket? (I'm not sure why; this ticket was never fixed, so it should never have been closed.)

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

No branches or pull requests

3 participants