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

Show relevant XML completion options based on XML Schema #347

Closed
cassianstraessle opened this issue Apr 8, 2019 · 3 comments · Fixed by #505
Closed

Show relevant XML completion options based on XML Schema #347

cassianstraessle opened this issue Apr 8, 2019 · 3 comments · Fixed by #505
Assignees
Labels
completion This issue or enhancement is related to completion support enhancement New feature or request XSD
Milestone

Comments

@cassianstraessle
Copy link

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="data">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="e1"/>
                <xs:element name="e2"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

Given the schema above the code completion shows the following behavior:

  • for the very fist element in <data> the code completion suggests both elements <e1> and <e2>. But only <e1> is a valid choice.
  • for the second element in the code completion suggests both elements <e1> and <e2>. But only <e2> is a valid choice.

The schema validation correctly points out the invalid elements. But code completion should not suggest invalid elements in the first place.

I observed this behavior with redhat.vscode-xml v0.5.0

@fbricon fbricon added bug Something isn't working completion This issue or enhancement is related to completion support labels Apr 8, 2019
@NikolasKomonen NikolasKomonen self-assigned this Apr 9, 2019
@NikolasKomonen NikolasKomonen added this to the v0.6.0 milestone Apr 9, 2019
NikolasKomonen added a commit to NikolasKomonen/lsp4xml that referenced this issue Apr 10, 2019
This includes handling for (choice, all, and sequence)

Fixes eclipse-lemminx#347

Signed-off-by: Nikolas <nikolaskomonen@gmail.com>
NikolasKomonen added a commit to NikolasKomonen/lsp4xml that referenced this issue Apr 11, 2019
This includes handling for (choice, all, and sequence)

Fixes eclipse-lemminx#347

Signed-off-by: Nikolas <nikolaskomonen@gmail.com>
@kduvekot
Copy link

as an addition ... it looks like the suggestions are always in alphabetical order, and ideally you want to get the suggestions in the sequence order, and restricted to what is possible at the location where the suggestion is make. (so limited to the elements that would "fit" there based on previous and next elements in the document)

I am working with UBL XSDs where sequence is important:
http://docs.oasis-open.org/ubl/os-UBL-2.2/xsd/maindoc/

Also when you have a sequence and there are mandatory elements (<xsd:element minOccurs="1" maxOccurs="1"> it would be good to insert those when the parent element of that sequence is started. You already know that the XML wil not be valid without those mandatory elements anyway.

and while you are at it ... then also insert the possible mandatory attributes of those elements :-)

I would not go as far as inserting the mandatory elements of complexType elements in the original sequence.. because they might be recursive .. so that would dig you down into a very deep rabbit hole.

@NikolasKomonen
Copy link
Contributor

NikolasKomonen commented Apr 15, 2019

Hi, I'm working on this issue right now trying to make sure it covers all cases. I will try to have a pr soon, which I hope people can test out to see if anything is missing.

For XSD based element completion the server should eventually cover:

  • Consider the model group (all, choice, sequence)
    • Recognize already existing elements
    • Provide the next required element(s) in a sequence
  • Consider the max/min occurrences / nillable elements.
  • Consider references / 'substitutionGroup' (already did that, but considers the model group)
  • Handle elements that have the 'absolute' attribute set.
  • xs:any elements that can link to other XSD's
  • Auto insert top level required elements (may be in different pr)

Let me know if you see any possible cases that are missing.

insert those when the parent element of that sequence is started ...
then also insert the possible mandatory attributes of those elements

thanks @kduvekot for the idea, I'll make sure we implement this.

NikolasKomonen added a commit to NikolasKomonen/lsp4xml that referenced this issue Apr 18, 2019
This includes handling for (choice, all, and sequence)

Fixes eclipse-lemminx#347

Signed-off-by: Nikolas <nikolaskomonen@gmail.com>
NikolasKomonen added a commit to NikolasKomonen/lsp4xml that referenced this issue Apr 18, 2019
This includes handling for (choice, all, and sequence)

Fixes eclipse-lemminx#347

Signed-off-by: Nikolas <nikolaskomonen@gmail.com>
NikolasKomonen added a commit to NikolasKomonen/lsp4xml that referenced this issue Apr 18, 2019
This includes handling for (choice, all, and sequence)

Fixes eclipse-lemminx#347

Signed-off-by: Nikolas <nikolaskomonen@gmail.com>
NikolasKomonen added a commit to NikolasKomonen/lsp4xml that referenced this issue Apr 18, 2019
This includes handling for (choice, all, and sequence)

Fixes eclipse-lemminx#347

Signed-off-by: Nikolas <nikolaskomonen@gmail.com>
NikolasKomonen added a commit to NikolasKomonen/lsp4xml that referenced this issue Apr 23, 2019
This includes handling for (choice, all, and sequence)

Fixes eclipse-lemminx#347

Signed-off-by: Nikolas <nikolaskomonen@gmail.com>
NikolasKomonen added a commit to NikolasKomonen/lsp4xml that referenced this issue Apr 25, 2019
This includes handling for (choice, all, and sequence)

Fixes eclipse-lemminx#347

Signed-off-by: Nikolas <nikolaskomonen@gmail.com>
NikolasKomonen added a commit to NikolasKomonen/lsp4xml that referenced this issue Apr 26, 2019
This includes handling for (choice, all, and sequence)

Fixes eclipse-lemminx#347

Signed-off-by: Nikolas <nikolaskomonen@gmail.com>
NikolasKomonen added a commit to NikolasKomonen/lsp4xml that referenced this issue May 6, 2019
This includes handling for (choice, all, and sequence)

Fixes eclipse-lemminx#347

Signed-off-by: Nikolas <nikolaskomonen@gmail.com>
NikolasKomonen added a commit to NikolasKomonen/lsp4xml that referenced this issue May 9, 2019
This includes handling for (choice, all, and sequence)

Fixes eclipse-lemminx#347

Signed-off-by: Nikolas <nikolaskomonen@gmail.com>
@NikolasKomonen NikolasKomonen removed this from the v0.6.0 milestone May 21, 2019
angelozerr added a commit that referenced this issue Jul 5, 2019
Fix #347

Signed-off-by: azerr <azerr@redhat.com>
@angelozerr
Copy link
Contributor

@cassianstraessle @kduvekot @NikolasKomonen I'm working again on this (hard) issue. I hope it will be avaialble for 0.8.0 millestone.

@NikolasKomonen I think we should use XSCMValidator from xerces that it is used in XMLSchemaValidator. I'm working on this idea.

angelozerr added a commit that referenced this issue Jul 5, 2019
Fix #347

Signed-off-by: azerr <azerr@redhat.com>
angelozerr added a commit that referenced this issue Jul 8, 2019
Fix #347

Signed-off-by: azerr <azerr@redhat.com>
angelozerr added a commit that referenced this issue Jul 8, 2019
Fix #347

Signed-off-by: azerr <azerr@redhat.com>
angelozerr added a commit that referenced this issue Jul 8, 2019
Fix #347

Signed-off-by: azerr <azerr@redhat.com>
angelozerr added a commit that referenced this issue Jul 8, 2019
Fix #347

Signed-off-by: azerr <azerr@redhat.com>
angelozerr added a commit that referenced this issue Jul 8, 2019
Fix #347

Signed-off-by: azerr <azerr@redhat.com>
angelozerr added a commit that referenced this issue Jul 8, 2019
Fix #347

Signed-off-by: azerr <azerr@redhat.com>
angelozerr added a commit that referenced this issue Jul 9, 2019
Fix #347

Signed-off-by: azerr <azerr@redhat.com>
@angelozerr angelozerr added this to the v0.8.0 milestone Jul 9, 2019
angelozerr added a commit that referenced this issue Jul 9, 2019
Fix #347

Signed-off-by: azerr <azerr@redhat.com>
angelozerr added a commit that referenced this issue Jul 9, 2019
Fix #347

Signed-off-by: azerr <azerr@redhat.com>
angelozerr added a commit that referenced this issue Jul 9, 2019
Fix #347

Signed-off-by: azerr <azerr@redhat.com>
angelozerr added a commit that referenced this issue Jul 9, 2019
Fix #347

Signed-off-by: azerr <azerr@redhat.com>
angelozerr added a commit that referenced this issue Jul 10, 2019
Fix #347

Signed-off-by: azerr <azerr@redhat.com>
angelozerr added a commit that referenced this issue Jul 10, 2019
Fix #347

Signed-off-by: azerr <azerr@redhat.com>
fbricon pushed a commit that referenced this issue Jul 10, 2019
Fix #347

Signed-off-by: azerr <azerr@redhat.com>
@angelozerr angelozerr changed the title Completion provides invalid suggestions for xsd:sequence Show possible elements for completion based on XML Schema Jul 23, 2019
@angelozerr angelozerr added XSD enhancement New feature or request and removed bug Something isn't working labels Jul 23, 2019
@angelozerr angelozerr changed the title Show possible elements for completion based on XML Schema Show relevant XML completion options based on XML Schema Jul 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
completion This issue or enhancement is related to completion support enhancement New feature or request XSD
Projects
None yet
5 participants