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

Implement DOMNode.getTextContent() according to API #1704

Merged
merged 1 commit into from
Nov 16, 2024

Conversation

laeubi
Copy link
Contributor

@laeubi laeubi commented Nov 10, 2024

Fix #1695

@laeubi
Copy link
Contributor Author

laeubi commented Nov 12, 2024

Failures seem unrelated here, ready to be merged.

@angelozerr
Copy link
Contributor

angelozerr commented Nov 12, 2024

@laeubi it would be very nice if you could add more tests like:

  • XML document with just text (ex : foo)
  • XML document with several text nodes inside one parent tag (ex : <a><b>f</b>o<b>o</b></a>)
  • XML document with several text nodes with several children (ex : <a><b>foo</b><c>bar</c></a>)
  • XML document with only comments
  • XML document with only processing instructions
  • XML document with commants, processing instructions, text nodes
  • etc

@laeubi
Copy link
Contributor Author

laeubi commented Nov 12, 2024

Yes more tests would be good, but as this is rather straight forward implementation I do not plan to put too much effort into this especially given that no one complained ever about the old implementation I suspect it is not really important for lemminx users?!?

@angelozerr
Copy link
Contributor

I think it is important for lemminx extensions which can use getTextContent. Today we have some piece of code which uses getTextContent, tests seems working but my fear is that we don't have enough tests to cover your changes.

@laeubi
Copy link
Contributor Author

laeubi commented Nov 12, 2024

The main change is that Elements no don't return null anymore, if anyone relies on this (invalid) behavior that would be the most notable change but one won't catch this with a test of course. I'll try to add some more tests to improve coverage of the different branches but this then only can test what the API of that method requires, not how consumers are using the function.

@angelozerr
Copy link
Contributor

Thanks for adding new tests.

Last changes that I think it could be good:

  1. Create a static method assertTextContent in the class to avoid duplicating code (DOMParser....

  2. Your tests should look like this

assertTextContent("Hello</a", "Hello")

  1. The assertTextContent must have assertNotNull, assertEquals like today

  2. And in this assertTextContent I think it could be nice to load xml with xerces to check that lemminx parser have the same result than xerces to be sure that we follow w3c spec

@angelozerr
Copy link
Contributor

@laeubi is there any chance that you do my suggestion in order to merge your PR?

@laeubi
Copy link
Contributor Author

laeubi commented Nov 14, 2024

@laeubi is there any chance that you do my suggestion in order to merge your PR?

Yes I'll hopefully complete that soon.

@angelozerr
Copy link
Contributor

Thanks! I'm sorry to ask you to do that (writting tests are boring) but your PR could have some impacts.

@angelozerr
Copy link
Contributor

@laeubi I am waiting for your update to merge your PR and create the lemminx release

@laeubi
Copy link
Contributor Author

laeubi commented Nov 16, 2024

I tried to implement the method as suggested but at laest locally for me the xerxes parser bails out for CDATA test that it can't find a class that is only available with JDK17... lets see what the CI say.

@laeubi
Copy link
Contributor Author

laeubi commented Nov 16, 2024

Sadly same problem on CI

 Caused by: java.lang.ClassNotFoundException: org.w3c.dom.ElementTraversal
	at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
	... 39 more

https://stackoverflow.com/questions/17515333/noclassdeffounderror-org-w3c-dom-elementtraversal

says one should use xml-apis-2.10.0.jar

Fix eclipse-lemminx#1695

Signed-off-by: Christoph Läubrich <laeubi@laeubi-soft.de>
@laeubi
Copy link
Contributor Author

laeubi commented Nov 16, 2024

I now changed this to https://mvnrepository.com/artifact/xml-apis/xml-apis/1.4.01

The xml API seem to be completely wrecked:

@laeubi
Copy link
Contributor Author

laeubi commented Nov 16, 2024

@angelozerr seems only the usual build instability now...

@angelozerr angelozerr merged commit 3c30e71 into eclipse-lemminx:main Nov 16, 2024
6 checks passed
@angelozerr
Copy link
Contributor

Thanks @laeubi !

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.

org.eclipse.lemminx.dom.DOMNode.getTextContent() seem to be implemented wrong (or incomplete)
2 participants