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

POM XML formatter sometimes gets confused with normal XML and hallucinates errors #1251

Open
garretwilson opened this issue Jun 16, 2023 · 7 comments

Comments

@garretwilson
Copy link

I'm using Eclipse EE 2023-06 with Java 17 on Windows 10.

Sometimes when I'm editing a POM, the new XML editor will get confused and show an error. The error will look like this:

Multiple markers at this line
- Non-parseable POM …/pom.xml: expected START_TAG or END_TAG not TEXT (position: TEXT seen ...</dependency>\r\n\r\n\r\n:\r\n\r\n\t\t\t<d... @120:6)
- Element 'dependencies' cannot contain text content.
The content type is defined as element-only.

Code:

(That's all. Really. There is nothing after "Code:".)

However there is no problem in the XML file. It looks like this. (Note that I am indenting using tabs.)

			<dependency>
				<groupId>net.sf.saxon</groupId>
				<artifactId>Saxon-HE</artifactId>
				<version>12.2</version>
			</dependency>

The error is shown on the first e of <dependency>.

This happens when I open an existing pom and do something like this:

  1. Paste some string, such as the artifact coordinates, on an empty line so I can use it later.
  2. Copy a <dependency> section from above.
  3. Edit the pasted section with the new coordinates.
  4. Delete the temporary line I added.

If I close the file and reopen it, the same error appears, but a different line is indicated; now it indicates the v of <version>.

If I delete the entire <dependency> section, then the error jumps to the section after that.

Arg, now I even did a Git "replace with HEAD" to remove all changes. When I close the file there is no error. When I open the file, it there's there is this imaginary error. Now even with the file I started with (which showed no errors) before making any changes!

Wow the only way I found around this was to exit Eclipse completely, come back in, and paste the entire section you see above. No typing allowed, because one never knows when it will start seeing imaginary errors again!

@garretwilson garretwilson changed the title POM XML formatter sometimes gets confused with normal XML and hallucinates newlines POM XML formatter sometimes gets confused with normal XML and hallucinates errors Jun 16, 2023
@angelozerr
Copy link
Contributor

Non-parseable POM …/pom.xml: expected START_TAG or END_TAG not TEXT (position: TEXT seen ...\r\n\r\n\r\n:\r\n\r\n\t\t\t<d... @120:6)

I suspect that it is an error from https://github.com/eclipse/lemminx-maven , @vrubezhny what do you think about that?

@mickaelistria
Copy link
Contributor

I don't think it's an error in lemminx-maven, lemminx-maven behaves OK according to document state, and here it seems like the document state is incorrect. But the document state is a shared responsibility between the client and the server. So either LSP4E sends incorrect change event, or misses to send some; or lemminx fails to properly handle some document changed events.
@garretwilson we'll try to reproduce; any hint or clue that can increase the chance of reproducing is more than welcome!

@garretwilson
Copy link
Author

garretwilson commented Jun 17, 2023

… any hint or clue that can increase the chance of reproducing is more than welcome!

I sure will! As you might imagine I don't have time to try to find exact steps, as this sort of thing is probably due to some sort of special circumstances, timing, or whatever.

I would say to try it with the globalmentor-root pom.xml, but then I just realized that this particular issue happened on a much smaller, normal-sized POM.

Although I can't readily reproduce this particular issue, I'm surprised that anyone using this editor to edit POMs daily doesn't run into similar things all the time. I know I do. There's the one where you are adding an artifact and it pops up an autocomplete for the version and just … does nothing. Then there's the one where closing a tag results in a half-close-tag and a full-close-tag. And the one where undoing ondoes not-what-was done before undoing. Etc. I just don't have time to file all of them because I know many of them are hard to reproduce. I'm just surprised you don't see them all the time if you're using this plugin day-to-day.

Anyway good luck and have a good weekend. I'll be sure to pass along any more information I discover.

@vrubezhny
Copy link
Contributor

@garretwilson Could you please gather and share the Eclipse and Language server logs while reproducing the issue? To do that:

  1. Enable logging to a file for LemMinX Language Server in Window->Preferences->Language Servers->Log Preference page then apply and close.
  2. Exit you Eclipse
  3. Follow the tips to enable the full logging for XML Language Server process of HOW-TO document
  4. Clear or remove the exiting application logs in <your-workspace>/.metadata/ folder (all *.log files) as well as all the *.log files in <your-workspace>/languageServers-log/ folder.

Then start your Eclipse again and try reproducing the issue. Once reproduced, please share all the *.log files from both folders mentioned in #4 (you may zip the files into a single archive before attaching).

Also please attach the minimal test project that allows you to reproduce the issue if possible (please do not share any restricted information here) - you can also zip it before attaching.

Thanks for your help.

@angelozerr
Copy link
Contributor

So either LSP4E sends incorrect change event, or misses to send some;

I remember that when I try to port LSP4E on IJ, I had a problem with change event. LSP4E takes care of one change event (so it can be ignore another change event. Perhaps the fix is to manage a list of change event instead of one change event.

See https://github.com/redhat-developer/intellij-quarkus/blob/ce55178378d7d74d4c359207d6053c5babd83d91/src/main/java/com/redhat/devtools/intellij/lsp4ij/DocumentContentSynchronizer.java#L126

@kohlschuetter
Copy link

I think I've hit this bug myself.

After adding the M2E snapshots Eclipse plugin repository and installing "M2E - POM Editor using LemMinX language server (includes Incubating components)" (I got version 2.0.5.20230630-2007), this appears to be fixed.

@angelozerr
Copy link
Contributor

Indeed it was fixed in eclipse/lemminx-maven#447 thank's @vrubezhny !

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

5 participants