XML: find the next sibling with the lezer parse tree

I am working in autocompletion for XML based on a XSD. In the XSD there are many complex types with sequences. For an accurate autocompletion that doesnt violate the XSD, the previous and next sibling based on the cursor position must be known (to know where in the sequence we are and what element is possible on this position).

I use the lezer parse tree and the implementation to find the previous sibling is working. However, I have some trouble with finding the next sibling. The problem arises when the user is writing an opening tag. The XML is not well-formed at this point, so traversing the parse tree doesnt work. My idea was to maybe parse the XML without the opening tag the user is writing. Is that possible? Or do you have another suggestion?

In my experience, even when the tree contains syntax errors, you can often get some useful information from it by scanning the tokens after the error. @lezer/xml seems to generally put elements after an unfinished tags as children of that tag, which isn’t where they will actually end up, of course, but which still makes them easy to find.

Thank you, I actually got it to work now by finding the opening Element node from the new opening tag and then at its first child instead of looking for the next sibling