It seems like
@codemirror/autocomplete just displays the suggestions on top of the editor, but the text you are writing during the autocompletion is still very much inserted directly into the document.
While this works fine for autocompleting variable and function names it is less than ideal for cases where you can search for labels associated with an identifier, e.g. when typing
wd:Mount Everest should suggest
wd:Q513 you do not want
wd:Mount to be highlighted as a prefixed name and
Everest to result in a parsing error. Another point is that the labels may contain strings that look like syntax elements e.g. typing
wd:http:// should suggest
wd:Q8777 but this is very difficult when you cannot differentiate between what was written before and after the autocompletion has been triggered.
So I think I would really like a system where you can explicitly start an autocompletion at a certain point, everything the user writes while the autocompletion is active is written to a new edit buffer (but this is just an implementation detail from the user interface it still looks like you’re writing into the document), writing into this edit buffer does not trigger a reparsing / rehighlighting of the document. Only when the user confirms the autocompletion (by pressing enter or clicking on a suggestion) the new text is inserted into the document.
Sidenote: I think this would also be better for collaborative editing since it would reduce superfluous updates.