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

Code Completion is not working for non-root elements #14

Open
ckpearson opened this issue Jun 22, 2022 · 1 comment
Open

Code Completion is not working for non-root elements #14

ckpearson opened this issue Jun 22, 2022 · 1 comment

Comments

@ckpearson
Copy link

I'm using the following example XSD:

<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<!-- definition of simple elements -->
<xs:element name="orderperson" type="xs:string"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
<xs:element name="title" type="xs:string"/>
<xs:element name="note" type="xs:string"/>
<xs:element name="quantity" type="xs:positiveInteger"/>
<xs:element name="price" type="xs:decimal"/>

<!-- definition of attributes -->
<xs:attribute name="orderid" type="xs:string"/>

<!-- definition of complex elements -->
<xs:element name="shipto">
  <xs:complexType>
    <xs:sequence>
      <xs:element ref="name"/>
      <xs:element ref="address"/>
      <xs:element ref="city"/>
      <xs:element ref="country"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

<xs:element name="item">
  <xs:complexType>
    <xs:sequence>
      <xs:element ref="title"/>
      <xs:element ref="note" minOccurs="0"/>
      <xs:element ref="quantity"/>
      <xs:element ref="price"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

<xs:element name="shiporder">
  <xs:complexType>
    <xs:sequence>
      <xs:element ref="orderperson"/>
      <xs:element ref="shipto"/>
      <xs:element ref="item" maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:attribute ref="orderid" use="required"/>
  </xs:complexType>
</xs:element>

</xs:schema>

My workflow for adding this into a react app differs slightly as I'm using @monaco-editor/react, but essentially in a useEffect callback that occurs once Monaco and the editor instances are mounted, I'm following the example code as such:

useEffect(() => {
    if (!editorMounted) return;
    const xsdManager = new XsdManager(editorRef.current);
    xsdManager.set({
      path: "dummy.xsd",
      value: demoXsd, // this is just a const containing the demo xsd from above
      alwaysInclude: true,
    });

    const xsdFeatures = new XsdFeatures(
      xsdManager,
      monacoRef.current,
      editorRef.current
    );

    xsdFeatures.addCompletion();
    xsdFeatures.addValidation();
    xsdFeatures.addGenerateAction();
    xsdFeatures.addReformatAction();
  }, [editorMounted]);

This works for root elements:
Screenshot 2022-06-22 at 23 30 42

But as soon as you try to get completion inside an element, it draws a blank:
Screenshot 2022-06-22 at 23 31 36

From the XSD I would expect this to offer up completions for orderperson, shipto and item in the correct sequence, instead no completions are presented, even when the keyboard shortcut is entered.

This appears to happen for even simpler schemas too, and there aren't any console errors either.

@philipsens
Copy link
Owner

philipsens commented Oct 19, 2022

Thanks for reporting the issue. I've been noticing that some XSD's don't work because there is a lot of variation in how someone can structure it.

Currently, the parser consists of multiple xpath queries, but it doesn't cover all cases.

I've been working on it a bit, but the progress is a bit slow and I still need to merge the changes. The changes would change the queries in favor of a translation of XML to JSON.

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

No branches or pull requests

2 participants