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

XML entities declared in a DTD are marked undeclared after XML file change #234

Closed
ph777 opened this issue Mar 25, 2020 · 8 comments · Fixed by eclipse-lemminx/lemminx#636 or enxio/lsp4xml#36
Assignees
Labels
bug Something isn't working DTD
Milestone

Comments

@ph777
Copy link

ph777 commented Mar 25, 2020

I have a DTD file base.dtd that declares an XML entity external:

<?xml version="1.0" encoding="utf-8"?>
<!ELEMENT root-element (#PCDATA)>
<!ENTITY external "EXTERNALLY DECLARED ENTITY">

I have an XML file file.xml that references the DTD file and declares an XML entity local. To make the case clear it also uses an undeclared entity undeclared.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE root-element SYSTEM "./base.dtd" [
<!ENTITY local "LOCALLY DECLARED ENTITY">
]>
<root-element>
&local;
&external;
&undeclared;
</root-element>

Now, if I open file.xml in VSCode, the DTD is recognized and the &undeclared; is correctly marked with an EntityNotDeclared error.

However, once I modify file.xml, e.g. by putting a new line or space anywhere (any safe place that does not break well-formdness of XML, e.g. after <root-element> opening tag), the &external; entity gets marked with an EntityNotDeclared error, which is NOT correct.

Is it possible to fix it? This error is really annoying in large XML files with a lot of externally declared XML entities. Once you modify your XML it gets red all over and you easily miss your real errors in XML. Or is this a lemminx problem?

Thanks

@ph777
Copy link
Author

ph777 commented Mar 25, 2020

I need to either reload VSCode or save file.xml, close it and reopen again to have externally declared XML entities evaluated correctly.

@angelozerr angelozerr added the bug Something isn't working label Mar 25, 2020
@angelozerr
Copy link
Contributor

DTD entity validation is indeed not very stable, we need to improve it. I need to investigate the problem.

@ph777
Copy link
Author

ph777 commented Mar 25, 2020

Thanks, that would be great!

@angelozerr
Copy link
Contributor

angelozerr commented Mar 26, 2020

Thanks @ph777 for your detailed explanation.

I can reproduce it and the bug is not trivial. It comes from the custom LemMinx cache of DTD which is used to avoid parsing referenced DTD grammar each time you type something in the XML editor.

The first time DTD grammar is not in the cache, the validation error for entities is correct. The second time when DTD grammar is on the cache, the Xerces validator doesn't reparse the DTD (because it is on the cache), that's nice but as it doesn't parse the DTD, it doesn't collect the declared entities and you have crazy errors about entities.

But I have some ideas to fix this problem. I will ping you as soon as I will find a fix.

@fbricon fbricon added the DTD label Mar 26, 2020
@ph777
Copy link
Author

ph777 commented Mar 26, 2020 via email

@angelozerr angelozerr self-assigned this Apr 2, 2020
@angelozerr angelozerr added this to the 0.12.0 milestone Apr 11, 2020
angelozerr added a commit to angelozerr/lemminx that referenced this issue Apr 15, 2020
angelozerr added a commit to angelozerr/lemminx that referenced this issue Apr 15, 2020
angelozerr added a commit to angelozerr/lemminx that referenced this issue Apr 16, 2020
angelozerr added a commit to angelozerr/lemminx that referenced this issue Apr 17, 2020
angelozerr added a commit to angelozerr/lemminx that referenced this issue Apr 17, 2020
angelozerr added a commit to angelozerr/lemminx that referenced this issue Apr 17, 2020
angelozerr added a commit to angelozerr/lemminx that referenced this issue Apr 17, 2020
@angelozerr
Copy link
Contributor

@ph777 I create a PR to fix this issue eclipse-lemminx/lemminx#636, here a demo:

EntityDemo

angelozerr added a commit to angelozerr/lemminx that referenced this issue Apr 20, 2020
angelozerr added a commit to angelozerr/lemminx that referenced this issue Apr 20, 2020
angelozerr added a commit to angelozerr/lemminx that referenced this issue Apr 21, 2020
angelozerr added a commit to angelozerr/lemminx that referenced this issue Apr 21, 2020
angelozerr added a commit to angelozerr/lemminx that referenced this issue Apr 21, 2020
angelozerr added a commit to eclipse-lemminx/lemminx that referenced this issue Apr 21, 2020
@ph777
Copy link
Author

ph777 commented Apr 21, 2020

Great news! Thanks!

When can we expect the 0.12.0 version to be released?

@angelozerr
Copy link
Contributor

When can we expect the 0.12.0 version to be released?

Perhaps in 3 weeks. But you can install the current version vsix at
https://download.jboss.org/jbosstools/vscode-xml/staging/?C=M;O=D

It should be good if you could do that to give us feedback before the release. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment