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-model] XML Completion based on DTD/XML Schema by using xml-model #709

Merged
merged 1 commit into from
May 21, 2020

Conversation

angelozerr
Copy link
Contributor

[xml-model] XML Completion based on DTD/XML Schema by using xml-model

Fixes #698

Signed-off-by: azerr azerr@redhat.com

@angelozerr angelozerr force-pushed the xml-model-completion branch from f870f7b to febde60 Compare May 19, 2020 09:04
@angelozerr angelozerr mentioned this pull request May 19, 2020
@angelozerr angelozerr force-pushed the xml-model-completion branch 3 times, most recently from 68bf321 to 0c7ac97 Compare May 19, 2020 09:39
@angelozerr angelozerr marked this pull request as ready for review May 19, 2020 09:40
@angelozerr
Copy link
Contributor Author

angelozerr commented May 19, 2020

You can test this PR with this XML:

<?xml-model href="http://maven.apache.org/xsd/maven-4.0.0.xsd" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0" >
	
</project>

Open the completion and you should see pom completion:

image

and hover:

image

You can add several xml-model and benefit with completion for each grammar (according to the possible elements for xsd) but I don't understand how we could use it with dtd and xsd both.

Copy link
Contributor

@fbricon fbricon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to add some tests checking aggregation of documentation for tags, attributes...

@angelozerr angelozerr force-pushed the xml-model-completion branch 3 times, most recently from 3d43176 to eec1fcc Compare May 20, 2020 13:17
@angelozerr
Copy link
Contributor Author

@fbricon I managed now aggregation with proper mean but I need to write test now.

To try it you can open the grammar.xml (which defines 2 xml-model with a xsd and a dtd) that I have included in this PR and you hover the from-xsd element which is declared in the dtd and xsd both.

You should see:

image

@angelozerr
Copy link
Contributor Author

angelozerr commented May 20, 2020

@fbricon please note you have in this case duplicate of completion item:

image

I keep like this, because the apply completion could be different from the xsd or dtd (ex: xsd defines required attributes, the apply will insert from-xsd element with attributes. The from-xsd declared in the dtd doesn't declare attributes, it generate xsd-from without attributes).

After discussing with @fbricon we keep this behavior. We will see if we will have some user issues with real usecases.

@angelozerr angelozerr force-pushed the xml-model-completion branch from eec1fcc to f355294 Compare May 20, 2020 15:05
@angelozerr
Copy link
Contributor Author

Test are written for hover aggregation.

@angelozerr angelozerr force-pushed the xml-model-completion branch from f355294 to 5c89989 Compare May 20, 2020 15:17
@xorye
Copy link

xorye commented May 20, 2020

@angelozerr I have an NPE when I have this xml:

<?xml-model href="grammar.xsd"?>
<project>
</project>

with this xsd:

<element name='project' xmlns='http://www.w3.org/2001/XMLSchema'>
  <element name='element1'>
    <complexType>
      <sequence>
        <element name='element1.1' type='string' />
        <element name='element1.2' type='string' />
      </sequence>
    </complexType>
  </element>
</element>

is my xsd file missing something?

This is the error stack trace:

[Error - 2:08:58 p.m.] May 20, 2020 02:08:58 org.eclipse.lemminx.extensions.contentmodel.participants.diagnostics.XMLValidator doDiagnostics()
Message: Unexpected XMLValidator error
java.lang.NullPointerException
    at org.apache.xerces.impl.xs.traversers.XSDocumentInfo.<init>(Unknown Source)
    at org.apache.xerces.impl.xs.traversers.XSDHandler.constructTrees(Unknown Source)
    at org.apache.xerces.impl.xs.traversers.XSDHandler.parseSchema(Unknown Source)
    at org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source)
    at org.apache.xerces.impl.xs.XMLSchemaValidator.findSchemaGrammar(Unknown Source)
    at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
    at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
    at org.eclipse.lemminx.extensions.xerces.xmlmodel.XMLModelSchemaValidator.startElement(XMLModelSchemaValidator.java:97)
    at org.eclipse.lemminx.extensions.xerces.xmlmodel.XMLModelHandler.startElement(XMLModelHandler.java:191)
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.eclipse.lemminx.extensions.contentmodel.participants.diagnostics.XMLValidator.parseXML(XMLValidator.java:107)
    at org.eclipse.lemminx.extensions.contentmodel.participants.diagnostics.XMLValidator.doDiagnostics(XMLValidator.java:93)
    at org.eclipse.lemminx.extensions.contentmodel.participants.diagnostics.ContentModelDiagnosticsParticipant.doDiagnostics(ContentModelDiagnosticsParticipant.java:48)
    at org.eclipse.lemminx.services.XMLDiagnostics.doExtensionsDiagnostics(XMLDiagnostics.java:85)
    at org.eclipse.lemminx.services.XMLDiagnostics.doDiagnostics(XMLDiagnostics.java:53)
    at org.eclipse.lemminx.services.XMLLanguageService.doDiagnostics(XMLLanguageService.java:153)
    at org.eclipse.lemminx.services.XMLLanguageService.publishDiagnostics(XMLLanguageService.java:162)
    at org.eclipse.lemminx.XMLTextDocumentService.validate(XMLTextDocumentService.java:464)
    at org.eclipse.lemminx.XMLTextDocumentService.lambda$triggerValidationFor$23(XMLTextDocumentService.java:457)
    at java.util.concurrent.CompletableFuture.uniAccept(CompletableFuture.java:670)
    at java.util.concurrent.CompletableFuture$UniAccept.tryFire(CompletableFuture.java:646)
    at java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:457)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

@xorye
Copy link

xorye commented May 20, 2020

Also for reference, could you provide grammar.xsd and grammar.dtd from this screenshot, please?
image

@angelozerr angelozerr force-pushed the xml-model-completion branch from 5c89989 to 5fc414c Compare May 20, 2020 22:07
@angelozerr
Copy link
Contributor Author

Also for reference, could you provide grammar.xsd and grammar.dtd from this screenshot, please?

Those files belong to this PR (in the test xml-model folder).

But here their content:

  • grammar.dtd:
<!ELEMENT grammar (#PCDATA | from-dtd | from-xsd)* >
<!ELEMENT from-dtd (#PCDATA)>
<!-- DTD documentation for from-xsd -->
<!ELEMENT from-xsd (#PCDATA)>
  • grammar.xsd:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
	<xs:element name="grammar">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="from-xsd" >
				<xs:annotation>
					<xs:documentation>XSD documentation for from-xsd</xs:documentation>
				</xs:annotation>
				</xs:element>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
</xs:schema>
  • grammar.xml:
<?xml-model href="grammar.dtd" ?>
<?xml-model href="grammar.xsd" ?>
<grammar>
	<from-xsd></from-xsd>	
</grammar>

@angelozerr
Copy link
Contributor Author

angelozerr commented May 20, 2020

@angelozerr I have an NPE

The problem is that XSD must start with schema and not element.

<schema  xmlns='http://www.w3.org/2001/XMLSchema'>
  <element name='element1'>
    <complexType>
      <sequence>
        <element name='element1.1' type='string' />
        <element name='element1.2' type='string' />
      </sequence>
    </complexType>
  </element>
</schema>

This NPE is not linked to this issue but it's a bug of Xerces. If you open the XSD file, you will see the same error. Please create an issue in LemMinx with this XSD which doesn't start with schema. I'm afraid that we cannot do something since it's a bug of Xerces.

@xorye
Copy link

xorye commented May 21, 2020

Those files belong to this PR (in the test xml-model folder).

Oops sorry, I have missed that the first time around.

The PR is working great on my end, I have also tested it with attribute tag/value completion from an external XSD and DTD

@angelozerr angelozerr merged commit 5e1dfe8 into eclipse-lemminx:master May 21, 2020
@angelozerr
Copy link
Contributor Author

The PR is working great on my end, I have also tested it with attribute tag/value completion from an external XSD and DTD

Thanks for the review!

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.

[xml-model] XML Completion based on DTD/XML Schema by using xml-model
3 participants