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

Multiple insert required attribute code actions shown when multiple attributes are missing #209

Closed
fbricon opened this issue Nov 8, 2018 · 2 comments
Assignees
Labels
bug Something isn't working code action
Milestone

Comments

@fbricon
Copy link
Contributor

fbricon commented Nov 8, 2018

Given an xml document:

<?xml version="1.0" encoding="UTF-8"?>
<invoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:noNamespaceSchemaLocation="invoice.xsd">
  <date>2017-11-30</date>
  <number>5235</number>
  <products>
    <product />
  </products>
  <payments>
    <payment amount="770.00" method="credit"/>
  </payments>
</invoice>

with an invoice.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="invoice" type="invoiceType"></xsd:element>
    
    <xsd:complexType name="invoiceType">
    	<xsd:sequence>
    		<xsd:element name="date" type="xsd:date"></xsd:element>
            <xsd:element name="number" type="xsd:int"></xsd:element>
            <xsd:element name="products" type="productsType"></xsd:element>
    		<xsd:element name="payments" type="paymentsType"></xsd:element>
    	</xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="productsType">
    	<xsd:choice minOccurs="1" maxOccurs="unbounded">
    		<xsd:element name="product" type="productType"></xsd:element>
    	</xsd:choice>
    </xsd:complexType>

    <xsd:complexType name="productType">
    	<xsd:attribute name="price" type="xsd:float" use="required"></xsd:attribute>
    	<xsd:attribute name="description" type="xsd:string" use="required"></xsd:attribute>
    </xsd:complexType>


    <xsd:complexType name="paymentsType">
    	<xsd:sequence minOccurs="1" maxOccurs="unbounded">
    		<xsd:element name="payment" type="paymentType"></xsd:element>
    	</xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="paymentType">
    	<xsd:attribute name="amount" type="xsd:float" use="required"></xsd:attribute>
    	<xsd:attribute name="method" type="paymentMethodType" use="required"></xsd:attribute>
    </xsd:complexType>

    <xsd:simpleType name="paymentMethodType">
    	<xsd:restriction base="xsd:string">
			<xsd:enumeration value="credit"></xsd:enumeration>
    		<xsd:enumeration value="debit"></xsd:enumeration>
    		<xsd:enumeration value="cash"></xsd:enumeration>
    		<xsd:enumeration value="aaaa"></xsd:enumeration>
    	</xsd:restriction>
    </xsd:simpleType>
</xsd:schema>

missing both attributes on the product tag generates duplicate code actions:

screen shot 2018-11-08 at 5 20 49 pm

There are as many code actions as there are missing attributes. The server should not send duplicates

@fbricon fbricon added bug Something isn't working code action labels Nov 8, 2018
@fbricon fbricon added this to the v0.0.3 milestone Nov 8, 2018
@fbricon fbricon added the to do label Nov 15, 2018
@angelozerr
Copy link
Contributor

@fbricon I don't know how to fix this issues, because it seems that it's a LSP issues.

Indeed in your case, you have 2 diagnostics "cvc-complex-type.4" with the same "code" (but for each missing attributes):

{
    "jsonrpc": "2.0",
    "method": "textDocument/publishDiagnostics",
    "params": {
        "uri": "product.xml",


        "diagnostics": [{
                "range": {
                    "start": {
                        "line": 6,
                        "character": 5
                    },
                    "end": {
                        "line": 6,
                        "character": 12
                    }
                },
                "severity": 1,
                "code": "cvc-complex-type.4",
                "source": "xml",
                "message": "cvc-complex-type.4: Attribute \u0027price\u0027 must appear on element \u0027product\u0027."
            },
            {
                "range": {
                    "start": {
                        "line": 6,
                        "character": 5
                    },
                    "end": {
                        "line": 6,
                        "character": 12
                    }
                },
                "severity": 1,
                "code": "cvc-complex-type.4",
                "source": "xml",
                "message": "cvc-complex-type.4: Attribute \u0027description\u0027 must appear on element \u0027product\u0027."
            }
        ]
    }
}

LSP call for each diangnostics a code action (you have 2 requesest) and the lsp4xml server returns a response per request.

An uggly fix that I have in my mind, is to generate only one "cvc-complex-type.4-ALL" diagnostic and map code action in this cvc-complex-type.4-ALL (what do you think about this idea?)

@angelozerr angelozerr self-assigned this Dec 3, 2018
@NikolasKomonen NikolasKomonen modified the milestones: v0.0.3, v0.0.4 Jan 17, 2019
@NikolasKomonen NikolasKomonen modified the milestones: v0.4.0, v0.5.0 Mar 1, 2019
@NikolasKomonen
Copy link
Contributor

Im going to implement this by having a single code action insert all missing attributes

NikolasKomonen added a commit to NikolasKomonen/lsp4xml that referenced this issue Mar 27, 2019
NikolasKomonen added a commit to NikolasKomonen/lsp4xml that referenced this issue Mar 27, 2019
fbricon pushed a commit that referenced this issue Mar 28, 2019
@fbricon fbricon removed the to do label Mar 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working code action
Projects
None yet
Development

No branches or pull requests

3 participants