Completion + mixed language

I have an issue while working with mixed language and completion. I’m using custom grammar for a tag style language and using a nested grammar for what is inside. The problem arises when I try to trigger the completion on the first position inside the a tag.

Case 1: <a> </a>
Case 2: <a></a>

For case 1 I at least I have a node for the JS parser so I could think of a way of triggering the right completion. Maybe with tokenBefore?

For case 2 I’m a bit more stranded because there is no match for any inside node.

Do I understand correctly that you parsing the content of <a> tags as JavaScript? When there is no content at all that is indeed tricky, and languageDataAt will not recognize the position as being part of a JavaScript tree. When there is actual code inside the tag, I coincidentally released a bunch of new package versions today (@lezer/common, @lezer/html, @codemirror/language) that should make this work better.

1 Like

Your assumptions are correct.

Thanks, it works as expected after a few changes for case 1 with the new versions.

I was checking the code at @lezer/html @codemirror/lang-html and I wonder how does it for case 2 since it does a simple parseMixed and it works.

A script tag always contains a ScriptText node, even when empty, and that is then parsed as an empty JavaScript program by the mixed parser, and thus found as a nested language when completing.