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

Validate open .xml files when bounded .xsd files are externally saved #509

Merged
merged 1 commit into from
Jul 16, 2019
Merged

Conversation

xorye
Copy link

@xorye xorye commented Jul 11, 2019

Signed-off-by: David Kwon [email protected]

Fixes vscode-xml #132.

This PR was tested with this xml document:

<?xml version="1.0" encoding="UTF-8" ?>
<root
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="sequence.xsd">
  <tag></tag>
  <optional></optional>
  <optional></optional>
  <optional></optional>
</root>

With this xsd schema:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified">
  <xs:element name="root">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="tag"/>
        <xs:element
            name="optional"
            minOccurs="0"
            maxOccurs="2"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

In the xsd file, I simply change the maxOccurs value from 2 to 3 and back to 2 in a separate editor to test this fix.

This PR will register all xsd files as watched files, therefore when the xsd files are saved externally, the client would send the didChangeWatchedFiles notification. The server will check through every open xml document and validate if it is bound to the recently saved xsd file.

This check was needed because document is null if the document representing documentURI is not opened on the client side. In our case, document is null when an xsd that is not currently open in the client, has been modified and saved externally.

Note that this PR works whether or not the xsd file is currently open in the client. I have only written the unit test for the unopened case. I am more than willing to write one for the opened case if desired.

For the unit test, I created this new file. One thing I am not sure about are the two sleep calls here. I added them because it seems like validation for the xml file is being done in a separate thread, and I wanted to wait until the validation was over, so I could read the resulting diagnostics/errors.

Validation for the xml document takes place when I call didOpen() with the xml document here which returns void.

I did not test this on Windows yet, however a fix for Windows overlaps with #506 .

@xorye
Copy link
Author

xorye commented Jul 12, 2019

I've made the changes.

Instead of sleeping for 1000 milliseconds, it now sleeps for 600. It can go as low as around 530ms, but when it is that low, sometimes the validation takes longer so the tests fail. Or maybe it depends on the machine running the tests?

The temp folder is now being created in the target directory.

@angelozerr
Copy link
Contributor

Works like a charm on Windows OS (after applying my future work https://github.com/angelozerr/lsp4xml/tree/improve-revalidate)

Well done @xorye !

@angelozerr angelozerr merged commit 962510d into eclipse-lemminx:master Jul 16, 2019
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.

Trigger textDocument/didSave if an XSD file was changed externally from a different editor
4 participants