lemminx icon indicating copy to clipboard operation
lemminx copied to clipboard

Support RelaxNG validation.

Open angelozerr opened this issue 5 years ago • 2 comments

Support RelaxNG validation.

angelozerr avatar Aug 10 '20 14:08 angelozerr

It would be an immense help to have this. Is there anything preventing it from being merged?

adunning avatar Mar 10 '22 11:03 adunning

@adunning thanks for your feedback.

At first please wote at https://github.com/redhat-developer/vscode-xml/issues/450

The main problem is that RelaxNG is not our priority and it requires a lot of work (to support validation with error range and completion,hover, definition based on relaxng). Our current goal is to support robust support for XML, XSD and DTD.But if we see that we have more and more people(liek you) who are interested we could work.

This PR is based on Jing, but I know @svanteschubert wanted to provide a relaxng support based on MSV. See https://github.com/redhat-developer/vscode-xml/issues/451#issuecomment-858080135

@svanteschubert what is the status of your work?

angelozerr avatar Mar 10 '22 12:03 angelozerr

We will need to do a bit of work in order to get the binary to work

datho7561 avatar Sep 26 '22 14:09 datho7561

For org.relaxng:jing, I couldn't find any recent entry on ClearlyDefined. https://clearlydefined.io/definitions/maven/mavencentral/org.relaxng/jing/20181222 doesn't have the necessary score.

$ mvn clean verify -DskipTests -Pverify-iplog
...
...
$ cat target/dash/summary | grep -v approved
maven/mavencentral/isorelax/isorelax/20030108, , restricted, clearlydefined
maven/mavencentral/org.relaxng/jing/20220510, , restricted, clearlydefined

So these libraries would need to be approved via. https://gitlab.eclipse.org/eclipsefdn/emo-team/iplab . You can use Create a request to vet Third-party content in order to do it manually. There's also an automated process that requires you to create at GitLab api token.

rgrunber avatar Sep 27 '22 14:09 rgrunber

See https://gitlab.eclipse.org/eclipsefdn/emo-team/iplab/-/issues/3540, https://gitlab.eclipse.org/eclipsefdn/emo-team/iplab/-/issues/3539

datho7561 avatar Oct 03 '22 14:10 datho7561

Here's what's needed to get the binary working:

diff --git a/org.eclipse.lemminx/src/main/resources/META-INF/native-image/resource-config.json b/org.eclipse.lemminx/src/main/resources/META-INF/native-image/resource-config.json
index 12a4fcdb..18d3640d 100644
--- a/org.eclipse.lemminx/src/main/resources/META-INF/native-image/resource-config.json
+++ b/org.eclipse.lemminx/src/main/resources/META-INF/native-image/resource-config.json
@@ -50,6 +50,12 @@
                {
                        "name": "org.apache.xerces.impl.msg.XMLMessages"
                },
+               {
+                       "name": "com.thaiopensource.datatype.xsd.resources.Messages"
+               },
+               {
+                       "name": "com.thaiopensource.relaxng.pattern.resources.Messages"
+               },
                {
                        "name": "org.eclipse.lemminx.extensions.xerces.xmlmodel.msg.XMLMessages"
                },

datho7561 avatar Oct 05 '22 19:10 datho7561

Here's what's needed to get the binary working:

Thanksso much for your feedback. I'm surprised that there is just this fix to do. I think completion doesn't work with binary because I'm using Java reflection (for the moment).

angelozerr avatar Oct 05 '22 20:10 angelozerr

I'll double check, but I thought it was working when I tried it.

edit: yep, it seems to be working with the binary

datho7561 avatar Oct 06 '22 11:10 datho7561

Ok this PR should work correctly now. All features are tested with some Junit tests and the integration of RelaxNG should be clean (we use system cache, commons error range are managed, etc).

The only thing that I need to implement is the documentation, but for the moment I need to do some investigation.

You can take for instance this XML:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
   
</TEI>

and play with validation and completion.

Here a demo:

RelaxNGValidationAndCompletion

It should work too with compact syntax.

angelozerr avatar Oct 11 '22 10:10 angelozerr

Type Definition to open the grammar element/attribute from XML should work now:

RelaxNGValidationTypeDefinition

angelozerr avatar Oct 11 '22 21:10 angelozerr

I clean my PR and I support documentation (but not for compact syntax)

  • for completion:

image

  • for hover:

image

angelozerr avatar Oct 12 '22 10:10 angelozerr

Given:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="asdf.rnc"?>
<addressBook>
  <card>
    <name>David</name>
    <email></email>
  </card>
</addressBook>

and an empty asdf.rnc, the "schema invalid" error is placed on the first line of the file (it's not adjusted properly), and 2 NPE appear in the console.

datho7561 avatar Oct 12 '22 17:10 datho7561

If you reference an empty .rng file, then the error message that appears is ::::-1:-1:-1:Premature end of file.xml(RelaxNGNotFound). It would be nice if we could remove the ::::-1:-1:-1: part

datho7561 avatar Oct 12 '22 17:10 datho7561

It would be nice to associate all .rng files with the relaxng.rng or relaxng.xsd schema. Do you want to do this in a future PR?

datho7561 avatar Oct 12 '22 17:10 datho7561

and an empty asdf.rnc, the "schema invalid" error is placed on the first line of the file (it's not adjusted properly), and 2 NPE appear in the console.

If you reference an empty .rng file, then the error message that appears is ::::-1:-1:-1:Premature end of file.xml(RelaxNGNotFound). It would be nice if we could remove the ::::-1:-1:-1: part

It should be fixed now and you should see the error as referenced diagnostic because the error comes from the schema and not from the XML:

image

angelozerr avatar Oct 12 '22 22:10 angelozerr

It would be nice to associate all .rng files with the relaxng.rng or relaxng.xsd schema. Do you want to do this in a future PR?

done, now you should have validation and completion for relaxng grammar:

RelaxNGGrammarSupport

angelozerr avatar Oct 12 '22 22:10 angelozerr

Don't say "This class is a copy paste of", say "This class is a copy of "

fbricon avatar Oct 13 '22 07:10 fbricon

Don't say "This class is a copy paste of", say "This class is a copy of "

fixed

angelozerr avatar Oct 13 '22 12:10 angelozerr

I add 2 snippets support for RelaxNG:

  • one to create an XML file bound with RelaxNG
  • one to create a RelaxNG *.rng grammar file

Here a demo which show how it is easy to create an XML bound with a RelaxNG grammar created by snippets:

RelaxNGSnippetSupport

angelozerr avatar Oct 13 '22 12:10 angelozerr

If you reference an empty .rng file, the SAXParseException appears in the logs.

datho7561 avatar Oct 13 '22 13:10 datho7561

If you reference an empty .rng file, the SAXParseException appears in the logs.

It should be fixed.

angelozerr avatar Oct 13 '22 16:10 angelozerr